Tidied code, added fly arrow check

This commit is contained in:
TenPlus1 2017-02-22 12:57:02 +00:00
parent bf5d976d8e
commit 59e8ba64f2
2 changed files with 105 additions and 96 deletions

29
api.lua
View File

@ -1,5 +1,5 @@
-- Mobs Api (10th February 2017) -- Mobs Api (22nd February 2017)
mobs = {} mobs = {}
mobs.mod = "redo" mobs.mod = "redo"
@ -3110,9 +3110,11 @@ end
-- capture critter (thanks to blert2112 for idea) -- capture critter (thanks to blert2112 for idea)
function mobs:capture_mob(self, clicker, chance_hand, chance_net, chance_lasso, force_take, replacewith) function mobs:capture_mob(self, clicker, chance_hand, chance_net, chance_lasso, force_take, replacewith)
if not self.child if self.child
and clicker:is_player() or not clicker:is_player()
and clicker:get_inventory() then or not clicker:get_inventory() then
return false
end
-- get name of clicked mob -- get name of clicked mob
local mobname = self.name local mobname = self.name
@ -3130,7 +3132,7 @@ function mobs:capture_mob(self, clicker, chance_hand, chance_net, chance_lasso,
minetest.chat_send_player(name, S("Not tamed!")) minetest.chat_send_player(name, S("Not tamed!"))
return return false
end end
-- cannot pick up if not owner -- cannot pick up if not owner
@ -3139,7 +3141,7 @@ function mobs:capture_mob(self, clicker, chance_hand, chance_net, chance_lasso,
minetest.chat_send_player(name, S("@1 is owner!", self.owner)) minetest.chat_send_player(name, S("@1 is owner!", self.owner))
return return false
end end
if clicker:get_inventory():room_for_item("main", mobname) then if clicker:get_inventory():room_for_item("main", mobname) then
@ -3168,11 +3170,8 @@ function mobs:capture_mob(self, clicker, chance_hand, chance_net, chance_lasso,
clicker:set_wielded_item(tool) clicker:set_wielded_item(tool)
end end
-- return if no chance
if chance == 0 then return end
-- calculate chance.. add to inventory if successful? -- calculate chance.. add to inventory if successful?
if random(1, 100) <= chance then if chance > 0 and random(1, 100) <= chance then
-- default mob egg -- default mob egg
local new_stack = ItemStack(mobname) local new_stack = ItemStack(mobname)
@ -3208,11 +3207,14 @@ function mobs:capture_mob(self, clicker, chance_hand, chance_net, chance_lasso,
end end
self.object:remove() self.object:remove()
return true
else else
minetest.chat_send_player(name, S("Missed!")) minetest.chat_send_player(name, S("Missed!"))
end end
end end
end
return false
end end
@ -3226,6 +3228,11 @@ function mobs:protect(self, clicker)
return false return false
end end
if self.protected == true then
minetest.chat_send_player(name, S("Already protected!"))
return false
end
local tool = clicker:get_wielded_item() local tool = clicker:get_wielded_item()
if tool:get_name() == "mobs:protector" then if tool:get_name() == "mobs:protector" then

View File

@ -340,9 +340,6 @@ function mobs.drive(entity, moving_anim, stand_anim, can_fly, dtime)
else else
v = v * 0.25 v = v * 0.25
end end
-- elseif ni == "walkable" then
-- v = 0
-- new_acce.y = 1
end end
new_velo = get_velocity(v, entity.object:getyaw() - rot_view, velo.y) 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, y = pos.y + 1.5 + dir.y,
z = pos.z + 0 + dir.z * 2.5}, arrow) z = pos.z + 0 + dir.z * 2.5}, arrow)
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 vec = {x = dir.x * 6, y = dir.y * 6, z = dir.z * 6}
local yaw = entity.driver:get_look_yaw() local yaw = entity.driver:get_look_yaw()
obj:setyaw(yaw + math.pi / 2) obj:setyaw(yaw + math.pi / 2)
obj:setvelocity(vec) obj:setvelocity(vec)
else
obj:remove()
end
end end
-- change animation if stopped -- change animation if stopped