Added capture routine (thanks blert2112)

This commit is contained in:
tenplus1 2015-06-28 11:31:19 +01:00
parent 698c7f36c8
commit 0f5046bea1
13 changed files with 144 additions and 190 deletions

View File

@ -28,6 +28,7 @@ This mod contains the following additions:
Changelog:
1.13- Added capture function (thanks blert2112) chance of picking up mob with hand, net and magic lasso
1.12- Added animal ownership so that players cannot steal your tamed animals
1.11- Added flying mobs (and swimming), fly=true and fly_in="air" or "deafult:water_source" for fishy
1,10- Footstep removed (use replace), explosion routine added for exploding mobs.

53
api.lua
View File

@ -1,4 +1,4 @@
-- Mobs Api (27th June 2015)
-- Mobs Api (28th June 2015)
mobs = {}
mobs.mod = "redo"
@ -14,7 +14,7 @@ function mobs:register_mob(name, def)
name = name,
fly = def.fly,
fly_in = def.fly_in or "air",
owner = def.owner,
owner = def.owner or "",
order = def.order or "",
on_die = def.on_die,
do_custom = def.do_custom,
@ -75,7 +75,6 @@ function mobs:register_mob(name, def)
hornytimer = 0,
child = false,
gotten = false,
owner = "",
health = 0,
do_attack = function(self, player, dist)
@ -1282,3 +1281,51 @@ function mobs:register_egg(mob, desc, background, addegg)
end,
})
end
-- capture critter (thanks to blert2112 for idea)
function mobs:capture_mob(self, clicker, chance_hand, chance_net, chance_lasso, force_take, replacewith)
if clicker:is_player() and clicker:get_inventory() and not self.child then
-- get name of clicked mob
local mobname = self.name
-- if not nil change what will be added to inventory
if replacewith then
mobname = replacewith
end
--print ("taking by force is", force_take)
local name = clicker:get_player_name()
if self.owner == "" and force_take == false then
minetest.chat_send_player(name, "Not tamed!")
-- cannot pick up if not owner
elseif self.owner ~= name and force_take == false then
minetest.chat_send_player(name, "Not owner!")
end
if clicker:get_inventory():room_for_item("main", name) then
-- was mob clicked with hand, net, or lasso?
local tool = clicker:get_wielded_item()
local chance = 0
if tool:is_empty() then
chance = chance_hand
elseif tool:get_name() == "mobs:net" then
chance = chance_net
tool:add_wear(4000) -- 17 uses
clicker:set_wielded_item(tool)
elseif tool:get_name() == "mobs:magic_lasso" then
-- pick up if owner
chance = chance_lasso
tool:add_wear(650) -- 100 uses
clicker:set_wielded_item(tool)
end
-- return if no chance
if chance == 0 then return end
-- calculate chance.. was capture successful?
if math.random(100) <= chance then
-- successful capture.. add to inventory
clicker:get_inventory():add_item("main", mobname)
self.object:remove()
else
minetest.chat_send_player(name, "Missed!")
end
end
end
end

View File

@ -36,13 +36,7 @@ mobs:register_mob("mobs:bee", {
walk_end = 65,
},
on_rightclick = function(self, clicker)
if clicker:is_player()
and clicker:get_inventory()
and self.child == false
and clicker:get_inventory():room_for_item("main", "mobs:bee") then
clicker:get_inventory():add_item("main", "mobs:bee")
self.object:remove()
end
mobs:capture_mob(self, clicker, 25, 80, 0, true, nil)
end,
})

View File

@ -65,12 +65,13 @@ mobs:register_mob("mobs:bunny", {
self.food = 0
self.tamed = true
-- make owner
if not self.owner or self.owner == "" then
if self.owner == "" then
self.owner = name
end
end
return
end
-- Monty Python tribute
if item:get_name() == "mobs:lava_orb" then
-- take item
@ -87,23 +88,7 @@ mobs:register_mob("mobs:bunny", {
return
end
if clicker:is_player()
and clicker:get_inventory()
and self.child == false
and clicker:get_inventory():room_for_item("main", "mobs:bunny") then
-- pick up if owner
if self.owner == name then
clicker:get_inventory():add_item("main", "mobs:bunny")
self.object:remove()
-- cannot pick up if not tamed
elseif not self.owner or self.owner == "" then
minetest.chat_send_player(name, "Not tamed!")
-- cannot pick up if not owner
elseif self.owner ~= name then
minetest.chat_send_player(name, "Not owner!")
end
end
mobs:capture_mob(self, clicker, 30, 50, 80, false, nil)
end,
attack_type = "dogfight",
damage = 5,

View File

@ -71,7 +71,7 @@ mobs:register_mob("mobs:chicken", {
end
self.tamed = true
-- make owner
if not self.owner or self.owner == "" then
if self.owner == "" then
self.owner = name
end
minetest.sound_play("mobs_chicken", {
@ -83,23 +83,7 @@ mobs:register_mob("mobs:chicken", {
return
end
if clicker:is_player()
and clicker:get_inventory()
and self.child == false
and clicker:get_inventory():room_for_item("main", "mobs:chicken") then
-- pick up if owner
if self.owner == name then
clicker:get_inventory():add_item("main", "mobs:chicken")
self.object:remove()
-- cannot pick up if not tamed
elseif not self.owner or self.owner == "" then
minetest.chat_send_player(name, "Not tamed!")
-- cannot pick up if not owner
elseif self.owner ~= name then
minetest.chat_send_player(name, "Not owner!")
end
end
mobs:capture_mob(self, clicker, 30, 50, 80, false, nil)
end,
})

25
cow.lua
View File

@ -63,6 +63,7 @@ mobs:register_mob("mobs:cow", {
minetest.add_item(pos, {name = "mobs:bucket_milk"})
end
self.gotten = true -- milked
return
end
if tool:get_name() == "farming:wheat" then
@ -86,7 +87,7 @@ mobs:register_mob("mobs:cow", {
self.gotten = false -- ready to be milked again
self.tamed = true
-- make owner
if not self.owner or self.owner == "" then
if self.owner == "" then
self.owner = name
end
minetest.sound_play("mobs_cow", {
@ -99,27 +100,7 @@ mobs:register_mob("mobs:cow", {
return
end
if tool:get_name() == "mobs:magic_lasso"
and clicker:is_player()
and clicker:get_inventory()
and self.child == false
and clicker:get_inventory():room_for_item("main", "mobs:cow") then
-- pick up if owner
if self.owner == name then
clicker:get_inventory():add_item("main", "mobs:cow")
self.object:remove()
tool:add_wear(3000) -- 22 uses
clicker:set_wielded_item(tool)
-- cannot pick up if not tamed
elseif not self.owner or self.owner == "" then
minetest.chat_send_player(name, "Not tamed!")
-- cannot pick up if not owner
elseif self.owner ~= name then
minetest.chat_send_player(name, "Not owner!")
end
end
mobs:capture_mob(self, clicker, 0, 5, 60, false, nil)
end,
})

53
crafts.lua Normal file
View File

@ -0,0 +1,53 @@
-- Meat & Cooked Meat
minetest.register_craftitem("mobs:meat_raw", {
description = "Raw Meat",
inventory_image = "mobs_meat_raw.png",
on_use = minetest.item_eat(3),
})
minetest.register_craftitem("mobs:meat", {
description = "Meat",
inventory_image = "mobs_meat.png",
on_use = minetest.item_eat(8),
})
minetest.register_craft({
type = "cooking",
output = "mobs:meat",
recipe = "mobs:meat_raw",
cooktime = 5,
})
-- Golden Lasso
minetest.register_tool("mobs:magic_lasso", {
description = "Magic Lasso (right-click animal to put in inventory)",
inventory_image = "mobs_magic_lasso.png",
})
minetest.register_craft({
output = "mobs:magic_lasso",
recipe = {
{"farming:string", "default:gold_lump", "farming:string"},
{"default:gold_lump", "default:diamondblock", "default:gold_lump"},
{"farming:string", "default:gold_lump", "farming:string"},
}
})
-- Net
minetest.register_tool("mobs:net", {
description = "Net (right-click animal to put in inventory)",
inventory_image = "mobs_net.png",
})
minetest.register_craft({
output = "mobs:net",
recipe = {
{"default:stick", "", "default:stick"},
{"default:stick", "", "default:stick"},
{"farming:string", "default:stick", "farming:string"},
}
})

View File

@ -1,69 +1,37 @@
local path = minetest.get_modpath("mobs")
-- Mob Api
dofile(minetest.get_modpath("mobs").."/api.lua")
dofile(path.."/api.lua")
-- Animals
dofile(minetest.get_modpath("mobs").."/chicken.lua") -- JKmurray
dofile(minetest.get_modpath("mobs").."/cow.lua") -- KrupnoPavel
dofile(minetest.get_modpath("mobs").."/rat.lua") -- PilzAdam
dofile(minetest.get_modpath("mobs").."/sheep.lua") -- PilzAdam
dofile(minetest.get_modpath("mobs").."/warthog.lua") -- KrupnoPavel
dofile(minetest.get_modpath("mobs").."/bee.lua") -- KrupnoPavel
dofile(minetest.get_modpath("mobs").."/bunny.lua") -- ExeterDad
dofile(minetest.get_modpath("mobs").."/kitten.lua") -- Jordach/BFD
dofile(path.."/chicken.lua") -- JKmurray
dofile(path.."/cow.lua") -- KrupnoPavel
dofile(path.."/rat.lua") -- PilzAdam
dofile(path.."/sheep.lua") -- PilzAdam
dofile(path.."/warthog.lua") -- KrupnoPavel
dofile(path.."/bee.lua") -- KrupnoPavel
dofile(path.."/bunny.lua") -- ExeterDad
dofile(path.."/kitten.lua") -- Jordach/BFD
-- Monsters
dofile(minetest.get_modpath("mobs").."/dirtmonster.lua") -- PilzAdam
dofile(minetest.get_modpath("mobs").."/dungeonmaster.lua")
dofile(minetest.get_modpath("mobs").."/oerkki.lua")
dofile(minetest.get_modpath("mobs").."/sandmonster.lua")
dofile(minetest.get_modpath("mobs").."/stonemonster.lua")
dofile(minetest.get_modpath("mobs").."/treemonster.lua")
dofile(minetest.get_modpath("mobs").."/lava_flan.lua") -- Zeg9
dofile(minetest.get_modpath("mobs").."/mese_monster.lua")
dofile(minetest.get_modpath("mobs").."/spider.lua") -- AspireMint
dofile(path.."/dirtmonster.lua") -- PilzAdam
dofile(path.."/dungeonmaster.lua")
dofile(path.."/oerkki.lua")
dofile(path.."/sandmonster.lua")
dofile(path.."/stonemonster.lua")
dofile(path.."/treemonster.lua")
dofile(path.."/lava_flan.lua") -- Zeg9
dofile(path.."/mese_monster.lua")
dofile(path.."/spider.lua") -- AspireMint
-- NPC
dofile(minetest.get_modpath("mobs").."/npc.lua") -- TenPlus1
dofile(path.."/npc.lua") -- TenPlus1
-- Meat & Cooked Meat
minetest.register_craftitem("mobs:meat_raw", {
description = "Raw Meat",
inventory_image = "mobs_meat_raw.png",
on_use = minetest.item_eat(3),
})
minetest.register_craftitem("mobs:meat", {
description = "Meat",
inventory_image = "mobs_meat.png",
on_use = minetest.item_eat(8),
})
minetest.register_craft({
type = "cooking",
output = "mobs:meat",
recipe = "mobs:meat_raw",
cooktime = 5,
})
-- Golden Lasso
minetest.register_tool("mobs:magic_lasso", {
description = "Magic Lasso (right-click animal to put in inventory)",
inventory_image = "mobs_magic_lasso.png",
})
minetest.register_craft({
output = "mobs:magic_lasso",
recipe = {
{"farming:string", "default:gold_lump", "farming:string"},
{"default:gold_lump", "default:diamondblock", "default:gold_lump"},
{"farming:string", "default:gold_lump", "farming:string"},
}
})
-- Mob Items
dofile(path.."/crafts.lua")
if minetest.setting_get("log_mods") then
minetest.log("action", "mobs loaded")

View File

@ -63,7 +63,7 @@ mobs:register_mob("mobs:kitten", {
self.food = 0
self.tamed = true
-- make owner
if not self.owner or self.owner == "" then
if self.owner == "" then
self.owner = name
end
minetest.sound_play("mobs_kitten", {
@ -76,23 +76,7 @@ mobs:register_mob("mobs:kitten", {
return
end
if clicker:is_player()
and clicker:get_inventory()
and self.child == false
and clicker:get_inventory():room_for_item("main", "mobs:kitten") then
-- pick up if owner
if self.owner == name then
clicker:get_inventory():add_item("main", "mobs:kitten")
self.object:remove()
-- cannot pick up if not tamed
elseif not self.owner or self.owner == "" then
minetest.chat_send_player(name, "Not tamed!")
-- cannot pick up if not owner
elseif self.owner ~= name then
minetest.chat_send_player(name, "Not owner!")
end
end
mobs:capture_mob(self, clicker, 50, 50, 90, false, nil)
end
})

View File

@ -24,13 +24,7 @@ mobs:register_mob("mobs:rat", {
lava_damage = 4,
light_damage = 0,
on_rightclick = function(self, clicker)
if clicker:is_player()
and clicker:get_inventory()
and self.child == false
and clicker:get_inventory():room_for_item("main", "mobs:rat") then
clicker:get_inventory():add_item("main", "mobs:rat")
self.object:remove()
end
mobs:capture_mob(self, clicker, 25, 80, 0, true, nil)
end,
--[[
do_custom = function(self)

View File

@ -66,7 +66,7 @@ mobs:register_mob("mobs:sheep", {
self.gotten = false -- can be shaved again
self.tamed = true
-- make owner
if not self.owner or self.owner == "" then
if self.owner == "" then
self.owner = name
end
self.object:set_properties({
@ -101,28 +101,10 @@ mobs:register_mob("mobs:sheep", {
textures = {"mobs_sheep_shaved.png"},
mesh = "mobs_sheep_shaved.x",
})
return
end
if item:get_name() == "mobs:magic_lasso"
and clicker:is_player()
and clicker:get_inventory()
and self.child == false
and clicker:get_inventory():room_for_item("main", "mobs:sheep") then
-- pick up if owner
if self.owner == name then
clicker:get_inventory():add_item("main", "mobs:sheep")
self.object:remove()
item:add_wear(3000) -- 22 uses
clicker:set_wielded_item(item)
-- cannot pick up if not tamed
elseif not self.owner or self.owner == "" then
minetest.chat_send_player(name, "Not tamed!")
-- cannot pick up if not tamed
elseif self.owner ~= name then
minetest.chat_send_player(name, "Not owner!")
end
end
mobs:capture_mob(self, clicker, 0, 5, 60, false, nil)
end,
})

BIN
textures/mobs_net.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 195 B

View File

@ -63,7 +63,7 @@ mobs:register_mob("mobs:pumba", {
end
self.tamed = true
-- make owner
if not self.owner or self.owner == "" then
if self.owner == "" then
self.owner = name
end
minetest.sound_play("mobs_pig", {
@ -76,26 +76,7 @@ mobs:register_mob("mobs:pumba", {
return
end
if item:get_name() == "mobs:magic_lasso"
and clicker:is_player()
and clicker:get_inventory()
and self.child == false
and clicker:get_inventory():room_for_item("main", "mobs:pumba") then
-- pick up if owner
if self.owner == name then
clicker:get_inventory():add_item("main", "mobs:pumba")
self.object:remove()
item:add_wear(3000) -- 22 uses
clicker:set_wielded_item(item)
-- cannot pick up if not tamed
elseif not self.owner or self.owner == "" then
minetest.chat_send_player(name, "Not tamed!")
-- cannot pick up if not tamed
elseif self.owner ~= name then
minetest.chat_send_player(name, "Not owner!")
end
end
mobs:capture_mob(self, clicker, 0, 5, 50, false, nil)
end,
})