summaryrefslogtreecommitdiff
path: root/api.lua
diff options
context:
space:
mode:
Diffstat (limited to 'api.lua')
-rw-r--r--api.lua145
1 files changed, 76 insertions, 69 deletions
diff --git a/api.lua b/api.lua
index 87b1f56..bf81e93 100644
--- a/api.lua
+++ b/api.lua
@@ -1,5 +1,5 @@
--- Mobs Api (10th February 2017)
+-- Mobs Api (22nd February 2017)
mobs = {}
mobs.mod = "redo"
@@ -3110,109 +3110,111 @@ end
-- capture critter (thanks to blert2112 for idea)
function mobs:capture_mob(self, clicker, chance_hand, chance_net, chance_lasso, force_take, replacewith)
- if not self.child
- and clicker:is_player()
- and clicker:get_inventory() then
+ if self.child
+ or not clicker:is_player()
+ or not clicker:get_inventory() then
+ return false
+ end
- -- get name of clicked mob
- local mobname = self.name
+ -- 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
-
- local name = clicker:get_player_name()
+ -- if not nil change what will be added to inventory
+ if replacewith then
+ mobname = replacewith
+ end
- -- is mob tamed?
- if self.tamed == false
- and force_take == false then
+ local name = clicker:get_player_name()
- minetest.chat_send_player(name, S("Not tamed!"))
+ -- is mob tamed?
+ if self.tamed == false
+ and force_take == false then
- return
- end
+ minetest.chat_send_player(name, S("Not tamed!"))
- -- cannot pick up if not owner
- if self.owner ~= name
- and force_take == false then
+ return false
+ end
- minetest.chat_send_player(name, S("@1 is owner!", self.owner))
+ -- cannot pick up if not owner
+ if self.owner ~= name
+ and force_take == false then
- return
- end
+ minetest.chat_send_player(name, S("@1 is owner!", self.owner))
- if clicker:get_inventory():room_for_item("main", mobname) then
+ return false
+ end
- -- was mob clicked with hand, net, or lasso?
- local tool = clicker:get_wielded_item()
- local chance = 0
+ if clicker:get_inventory():room_for_item("main", mobname) then
- if tool:is_empty() then
- chance = chance_hand
+ -- was mob clicked with hand, net, or lasso?
+ local tool = clicker:get_wielded_item()
+ local chance = 0
- elseif tool:get_name() == "mobs:net" then
+ if tool:is_empty() then
+ chance = chance_hand
- chance = chance_net
+ elseif tool:get_name() == "mobs:net" then
- tool:add_wear(4000) -- 17 uses
+ chance = chance_net
- clicker:set_wielded_item(tool)
+ tool:add_wear(4000) -- 17 uses
- elseif tool:get_name() == "mobs:magic_lasso" then
+ clicker:set_wielded_item(tool)
- chance = chance_lasso
+ elseif tool:get_name() == "mobs:magic_lasso" then
- tool:add_wear(650) -- 100 uses
+ chance = chance_lasso
- clicker:set_wielded_item(tool)
- end
+ tool:add_wear(650) -- 100 uses
- -- return if no chance
- if chance == 0 then return end
+ clicker:set_wielded_item(tool)
+ end
- -- calculate chance.. add to inventory if successful?
- if random(1, 100) <= chance then
+ -- calculate chance.. add to inventory if successful?
+ if chance > 0 and random(1, 100) <= chance then
- -- default mob egg
- local new_stack = ItemStack(mobname)
+ -- default mob egg
+ local new_stack = ItemStack(mobname)
- -- add special mob egg with all mob information
- -- unless 'replacewith' contains new item to use
- if not replacewith then
+ -- add special mob egg with all mob information
+ -- unless 'replacewith' contains new item to use
+ if not replacewith then
- new_stack = ItemStack(mobname .. "_set")
+ new_stack = ItemStack(mobname .. "_set")
- local tmp = {}
+ local tmp = {}
- for _,stat in pairs(self) do
- local t = type(stat)
- if t ~= 'function'
- and t ~= 'nil'
- and t ~= 'userdata' then
- tmp[_] = self[_]
- end
+ for _,stat in pairs(self) do
+ local t = type(stat)
+ if t ~= 'function'
+ and t ~= 'nil'
+ and t ~= 'userdata' then
+ tmp[_] = self[_]
end
-
- local data_str = minetest.serialize(tmp)
-
- new_stack:set_metadata(data_str)
end
- local inv = clicker:get_inventory()
+ local data_str = minetest.serialize(tmp)
- if inv:room_for_item("main", new_stack) then
- inv:add_item("main", new_stack)
- else
- minetest.add_item(clicker:getpos(), new_stack)
- end
+ new_stack:set_metadata(data_str)
+ end
+
+ local inv = clicker:get_inventory()
- self.object:remove()
+ if inv:room_for_item("main", new_stack) then
+ inv:add_item("main", new_stack)
else
- minetest.chat_send_player(name, S("Missed!"))
+ minetest.add_item(clicker:getpos(), new_stack)
end
+
+ self.object:remove()
+
+ return true
+ else
+ minetest.chat_send_player(name, S("Missed!"))
end
end
+
+ return false
end
@@ -3226,6 +3228,11 @@ function mobs:protect(self, clicker)
return false
end
+ if self.protected == true then
+ minetest.chat_send_player(name, S("Already protected!"))
+ return false
+ end
+
local tool = clicker:get_wielded_item()
if tool:get_name() == "mobs:protector" then