From 0f5046bea10866f8fce4cece64fcd4015f245461 Mon Sep 17 00:00:00 2001 From: tenplus1 Date: Sun, 28 Jun 2015 11:31:19 +0100 Subject: [PATCH] Added capture routine (thanks blert2112) --- README.txt | 1 + api.lua | 53 ++++++++++++++++++++++++++-- bee.lua | 8 +---- bunny.lua | 21 ++---------- chicken.lua | 20 ++--------- cow.lua | 25 ++------------ crafts.lua | 53 ++++++++++++++++++++++++++++ init.lua | 78 +++++++++++++----------------------------- kitten.lua | 20 ++--------- rat.lua | 8 +---- sheep.lua | 24 ++----------- textures/mobs_net.png | Bin 0 -> 195 bytes warthog.lua | 23 ++----------- 13 files changed, 144 insertions(+), 190 deletions(-) create mode 100644 crafts.lua create mode 100644 textures/mobs_net.png diff --git a/README.txt b/README.txt index 1f22287..1fea446 100644 --- a/README.txt +++ b/README.txt @@ -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. diff --git a/api.lua b/api.lua index bb28cae..ac432c5 100644 --- a/api.lua +++ b/api.lua @@ -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 diff --git a/bee.lua b/bee.lua index 6aa474d..d5afbfa 100644 --- a/bee.lua +++ b/bee.lua @@ -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, }) diff --git a/bunny.lua b/bunny.lua index 91dee3a..c272bba 100644 --- a/bunny.lua +++ b/bunny.lua @@ -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, diff --git a/chicken.lua b/chicken.lua index 264e8ee..17891db 100644 --- a/chicken.lua +++ b/chicken.lua @@ -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, }) diff --git a/cow.lua b/cow.lua index 357ca88..b5d315e 100644 --- a/cow.lua +++ b/cow.lua @@ -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, }) diff --git a/crafts.lua b/crafts.lua new file mode 100644 index 0000000..1dc1a00 --- /dev/null +++ b/crafts.lua @@ -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"}, + } +}) diff --git a/init.lua b/init.lua index 198e31a..4090daf 100644 --- a/init.lua +++ b/init.lua @@ -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") diff --git a/kitten.lua b/kitten.lua index 7580dc7..25b5baf 100755 --- a/kitten.lua +++ b/kitten.lua @@ -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 }) diff --git a/rat.lua b/rat.lua index 39161f2..5eded78 100644 --- a/rat.lua +++ b/rat.lua @@ -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) diff --git a/sheep.lua b/sheep.lua index 8d059d9..1d8773e 100644 --- a/sheep.lua +++ b/sheep.lua @@ -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, }) diff --git a/textures/mobs_net.png b/textures/mobs_net.png new file mode 100644 index 0000000000000000000000000000000000000000..df7c3a61f531d9fb3b5a2a8bfd72c2f7a3e3c69f GIT binary patch literal 195 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!73?$#)eFPE^4e$wZWnj=u6yxxy(FqQ=Q1v5B2yO9Ru#CW{FIq2sZu;qT;#_8q@+w>6|b p{>-jn*&9=KMziu6f5Dzg<{~zJ50m?<|AF=}c)I$ztaD0e0sw}5K|cTh literal 0 HcmV?d00001 diff --git a/warthog.lua b/warthog.lua index f009d57..81e0e2f 100644 --- a/warthog.lua +++ b/warthog.lua @@ -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, })