summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTenPlus1 <kinsellaja@yahoo.com>2017-02-22 12:57:02 +0000
committerTenPlus1 <kinsellaja@yahoo.com>2017-02-22 12:57:02 +0000
commit59e8ba64f28b293b716854eeee9550cd9f97cfb9 (patch)
treebdc5754bfb259af1eabd6ccc492746a1285b51db
parentbf5d976d8e074788bfb98c9a87837bed95c5a8fc (diff)
Tidied code, added fly arrow check
-rw-r--r--api.lua145
-rw-r--r--mount.lua18
2 files changed, 86 insertions, 77 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
diff --git a/mount.lua b/mount.lua
index b3b527f..0b08613 100644
--- a/mount.lua
+++ b/mount.lua
@@ -340,9 +340,6 @@ function mobs.drive(entity, moving_anim, stand_anim, can_fly, dtime)
else
v = v * 0.25
end
--- elseif ni == "walkable" then
--- v = 0
--- new_acce.y = 1
end
new_velo = get_velocity(v, entity.object:getyaw() - rot_view, velo.y)
@@ -415,11 +412,16 @@ function mobs.fly(entity, dtime, speed, shoots, arrow, moving_anim, stand_anim)
y = pos.y + 1.5 + dir.y,
z = pos.z + 0 + dir.z * 2.5}, arrow)
- local vec = {x = dir.x * 6, y = dir.y * 6, z = dir.z * 6}
- local yaw = entity.driver:get_look_yaw()
-
- obj:setyaw(yaw + math.pi / 2)
- obj:setvelocity(vec)
+ local ent = obj:get_luaentity()
+ if ent then
+ ent.switch = 1 -- for mob specific arrows
+ local vec = {x = dir.x * 6, y = dir.y * 6, z = dir.z * 6}
+ local yaw = entity.driver:get_look_yaw()
+ obj:setyaw(yaw + math.pi / 2)
+ obj:setvelocity(vec)
+ else
+ obj:remove()
+ end
end
-- change animation if stopped