Mob definition switched to a setmetatable way of doing it. Gives modders so much customization that they can shoot themselves in the foot with it.

This commit is contained in:
ElectricSolstice 2013-10-15 19:16:22 -07:00
parent 5865c59969
commit eacb49ac70

831
api.lua
View File

@ -1,481 +1,460 @@
mobs = {} mobs = {}
function mobs:jump()
local v = self.object:getvelocity()
v.y = 5
self.object:setvelocity(v)
end
function mobs:register_mob(name, def) mobs.default_definition = {
minetest.register_entity(name, { physical = true,
hp_max = def.hp_max, jump = function (self)
physical = true, local v = self.object:getvelocity()
collisionbox = def.collisionbox, v.y = 5
visual = def.visual, self.object:setvelocity(v)
visual_size = def.visual_size, end,
mesh = def.mesh,
textures = def.textures,
makes_footstep_sound = def.makes_footstep_sound, timer = 0,
view_range = def.view_range, env_damage_timer = 0, -- only if state = "attack"
walk_velocity = def.walk_velocity, attack = {player=nil, dist=nil},
run_velocity = def.run_velocity, state = "stand",
damage = def.damage, v_start = false,
light_damage = def.light_damage, old_y = nil,
water_damage = def.water_damage, lifetimer = 600,
lava_damage = def.lava_damage, tamed = false,
disable_fall_damage = def.disable_fall_damage,
drops = def.drops, set_velocity = function(self, v)
armor = def.armor, local yaw = self.object:getyaw()
drawtype = def.drawtype, if self.drawtype == "side" then
on_rightclick = def.on_rightclick, yaw = yaw+(math.pi/2)
type = def.type, end
attack_type = def.attack_type, local x = math.sin(yaw) * -v
arrow = def.arrow, local z = math.cos(yaw) * v
shoot_interval = def.shoot_interval, self.object:setvelocity({x=x, y=self.object:getvelocity().y, z=z})
sounds = def.sounds, end,
animation = def.animation,
follow = def.follow, get_velocity = function(self)
jump = def.jump or mobs.jump, local v = self.object:getvelocity()
return (v.x^2 + v.z^2)^(0.5)
end,
set_animation = function(self, type)
if not self.animation then
return
end
if not self.animation.current then
self.animation.current = ""
end
if type == "stand" and self.animation.current ~= "stand" then
if
self.animation.stand_start
and self.animation.stand_end
and self.animation.speed_normal
then
self.object:set_animation(
{x=self.animation.stand_start,y=self.animation.stand_end},
self.animation.speed_normal, 0
)
self.animation.current = "stand"
end
elseif type == "walk" and self.animation.current ~= "walk" then
if
self.animation.walk_start
and self.animation.walk_end
and self.animation.speed_normal
then
self.object:set_animation(
{x=self.animation.walk_start,y=self.animation.walk_end},
self.animation.speed_normal, 0
)
self.animation.current = "walk"
end
elseif type == "run" and self.animation.current ~= "run" then
if
self.animation.run_start
and self.animation.run_end
and self.animation.speed_run
then
self.object:set_animation(
{x=self.animation.run_start,y=self.animation.run_end},
self.animation.speed_run, 0
)
self.animation.current = "run"
end
elseif type == "punch" and self.animation.current ~= "punch" then
if
self.animation.punch_start
and self.animation.punch_end
and self.animation.speed_normal
then
self.object:set_animation(
{x=self.animation.punch_start,y=self.animation.punch_end},
self.animation.speed_normal, 0
)
self.animation.current = "punch"
end
end
end,
on_step = function(self, dtime)
if self.type == "monster" and minetest.setting_getbool("only_peaceful_mobs") then
self.object:remove()
end
timer = 0, self.lifetimer = self.lifetimer - dtime
env_damage_timer = 0, -- only if state = "attack" if self.lifetimer <= 0 and not self.tamed then
attack = {player=nil, dist=nil}, local player_count = 0
state = "stand", for _,obj in ipairs(minetest.env:get_objects_inside_radius(self.object:getpos(), 20)) do
v_start = false, if obj:is_player() then
old_y = nil, player_count = player_count+1
lifetimer = 600, end
tamed = false, end
if player_count == 0 and self.state ~= "attack" then
self.object:remove()
return
end
end
set_velocity = function(self, v) if self.object:getvelocity().y > 0.1 then
local yaw = self.object:getyaw() local yaw = self.object:getyaw()
if self.drawtype == "side" then if self.drawtype == "side" then
yaw = yaw+(math.pi/2) yaw = yaw+(math.pi/2)
end end
local x = math.sin(yaw) * -v local x = math.sin(yaw) * -2
local z = math.cos(yaw) * v local z = math.cos(yaw) * 2
self.object:setvelocity({x=x, y=self.object:getvelocity().y, z=z}) self.object:setacceleration({x=x, y=-10, z=z})
end, else
self.object:setacceleration({x=0, y=-10, z=0})
end
get_velocity = function(self) if self.disable_fall_damage and self.object:getvelocity().y == 0 then
local v = self.object:getvelocity() if not self.old_y then
return (v.x^2 + v.z^2)^(0.5) self.old_y = self.object:getpos().y
end, else
local d = self.old_y - self.object:getpos().y
if d > 5 then
local damage = d-5
self.object:set_hp(self.object:get_hp()-damage)
if self.object:get_hp() == 0 then
self.object:remove()
end
end
self.old_y = self.object:getpos().y
end
end
set_animation = function(self, type) self.timer = self.timer+dtime
if not self.animation then if self.state ~= "attack" then
if self.timer < 1 then
return return
end end
if not self.animation.current then self.timer = 0
self.animation.current = "" end
end
if type == "stand" and self.animation.current ~= "stand" then
if
self.animation.stand_start
and self.animation.stand_end
and self.animation.speed_normal
then
self.object:set_animation(
{x=self.animation.stand_start,y=self.animation.stand_end},
self.animation.speed_normal, 0
)
self.animation.current = "stand"
end
elseif type == "walk" and self.animation.current ~= "walk" then
if
self.animation.walk_start
and self.animation.walk_end
and self.animation.speed_normal
then
self.object:set_animation(
{x=self.animation.walk_start,y=self.animation.walk_end},
self.animation.speed_normal, 0
)
self.animation.current = "walk"
end
elseif type == "run" and self.animation.current ~= "run" then
if
self.animation.run_start
and self.animation.run_end
and self.animation.speed_run
then
self.object:set_animation(
{x=self.animation.run_start,y=self.animation.run_end},
self.animation.speed_run, 0
)
self.animation.current = "run"
end
elseif type == "punch" and self.animation.current ~= "punch" then
if
self.animation.punch_start
and self.animation.punch_end
and self.animation.speed_normal
then
self.object:set_animation(
{x=self.animation.punch_start,y=self.animation.punch_end},
self.animation.speed_normal, 0
)
self.animation.current = "punch"
end
end
end,
on_step = function(self, dtime) if self.sounds and self.sounds.random and math.random(1, 100) <= 1 then
if self.type == "monster" and minetest.setting_getbool("only_peaceful_mobs") then minetest.sound_play(self.sounds.random, {object = self.object})
self.object:remove() end
end
local do_env_damage = function(self)
local pos = self.object:getpos()
local n = minetest.env:get_node(pos)
self.lifetimer = self.lifetimer - dtime if self.light_damage and self.light_damage ~= 0
if self.lifetimer <= 0 and not self.tamed then and pos.y>0
local player_count = 0 and minetest.env:get_node_light(pos)
for _,obj in ipairs(minetest.env:get_objects_inside_radius(self.object:getpos(), 20)) do and minetest.env:get_node_light(pos) > 4
if obj:is_player() then and minetest.env:get_timeofday() > 0.2
player_count = player_count+1 and minetest.env:get_timeofday() < 0.8
end then
end self.object:set_hp(self.object:get_hp()-self.light_damage)
if player_count == 0 and self.state ~= "attack" then if self.object:get_hp() == 0 then
self.object:remove() self.object:remove()
return
end end
end end
if self.object:getvelocity().y > 0.1 then if self.water_damage and self.water_damage ~= 0 and
local yaw = self.object:getyaw() minetest.get_item_group(n.name, "water") ~= 0
if self.drawtype == "side" then then
yaw = yaw+(math.pi/2) self.object:set_hp(self.object:get_hp()-self.water_damage)
end if self.object:get_hp() == 0 then
local x = math.sin(yaw) * -2 self.object:remove()
local z = math.cos(yaw) * 2
self.object:setacceleration({x=x, y=-10, z=z})
else
self.object:setacceleration({x=0, y=-10, z=0})
end
if self.disable_fall_damage and self.object:getvelocity().y == 0 then
if not self.old_y then
self.old_y = self.object:getpos().y
else
local d = self.old_y - self.object:getpos().y
if d > 5 then
local damage = d-5
self.object:set_hp(self.object:get_hp()-damage)
if self.object:get_hp() == 0 then
self.object:remove()
end
end
self.old_y = self.object:getpos().y
end end
end end
self.timer = self.timer+dtime if self.lava_damage and self.lava_damage ~= 0 and
if self.state ~= "attack" then minetest.get_item_group(n.name, "lava") ~= 0
if self.timer < 1 then then
return self.object:set_hp(self.object:get_hp()-self.lava_damage)
end if self.object:get_hp() == 0 then
self.timer = 0 self.object:remove()
end
if self.sounds and self.sounds.random and math.random(1, 100) <= 1 then
minetest.sound_play(self.sounds.random, {object = self.object})
end
local do_env_damage = function(self)
local pos = self.object:getpos()
local n = minetest.env:get_node(pos)
if self.light_damage and self.light_damage ~= 0
and pos.y>0
and minetest.env:get_node_light(pos)
and minetest.env:get_node_light(pos) > 4
and minetest.env:get_timeofday() > 0.2
and minetest.env:get_timeofday() < 0.8
then
self.object:set_hp(self.object:get_hp()-self.light_damage)
if self.object:get_hp() == 0 then
self.object:remove()
end
end
if self.water_damage and self.water_damage ~= 0 and
minetest.get_item_group(n.name, "water") ~= 0
then
self.object:set_hp(self.object:get_hp()-self.water_damage)
if self.object:get_hp() == 0 then
self.object:remove()
end
end
if self.lava_damage and self.lava_damage ~= 0 and
minetest.get_item_group(n.name, "lava") ~= 0
then
self.object:set_hp(self.object:get_hp()-self.lava_damage)
if self.object:get_hp() == 0 then
self.object:remove()
end
end end
end end
end
self.env_damage_timer = self.env_damage_timer + dtime
if self.state == "attack" and self.env_damage_timer > 1 then self.env_damage_timer = self.env_damage_timer + dtime
self.env_damage_timer = 0 if self.state == "attack" and self.env_damage_timer > 1 then
do_env_damage(self) self.env_damage_timer = 0
elseif self.state ~= "attack" then do_env_damage(self)
do_env_damage(self) elseif self.state ~= "attack" then
end do_env_damage(self)
end
if self.type == "monster" and minetest.setting_getbool("enable_damage") then
for _,player in pairs(minetest.get_connected_players()) do if self.type == "monster" and minetest.setting_getbool("enable_damage") then
local s = self.object:getpos() for _,player in pairs(minetest.get_connected_players()) do
local p = player:getpos() local s = self.object:getpos()
local dist = ((p.x-s.x)^2 + (p.y-s.y)^2 + (p.z-s.z)^2)^0.5 local p = player:getpos()
if dist < self.view_range then local dist = ((p.x-s.x)^2 + (p.y-s.y)^2 + (p.z-s.z)^2)^0.5
if self.attack.dist then if dist < self.view_range then
if dist < self.attack.dist then if self.attack.dist then
self.attack.player = player if dist < self.attack.dist then
self.attack.dist = dist
end
else
self.state = "attack"
self.attack.player = player self.attack.player = player
self.attack.dist = dist self.attack.dist = dist
end end
else
self.state = "attack"
self.attack.player = player
self.attack.dist = dist
end end
end end
end end
end
if self.follow and self.follow ~= "" and not self.following then
for _,player in pairs(minetest.get_connected_players()) do if self.follow and self.follow ~= "" and not self.following then
local s = self.object:getpos() for _,player in pairs(minetest.get_connected_players()) do
local p = player:getpos() local s = self.object:getpos()
local dist = ((p.x-s.x)^2 + (p.y-s.y)^2 + (p.z-s.z)^2)^0.5 local p = player:getpos()
if self.view_range and dist < self.view_range then local dist = ((p.x-s.x)^2 + (p.y-s.y)^2 + (p.z-s.z)^2)^0.5
self.following = player if self.view_range and dist < self.view_range then
end self.following = player
end end
end end
end
if self.following and self.following:is_player() then
if self.following:get_wielded_item():get_name() ~= self.follow then if self.following and self.following:is_player() then
if self.following:get_wielded_item():get_name() ~= self.follow then
self.following = nil
self.v_start = false
else
local s = self.object:getpos()
local p = self.following:getpos()
local dist = ((p.x-s.x)^2 + (p.y-s.y)^2 + (p.z-s.z)^2)^0.5
if dist > self.view_range then
self.following = nil self.following = nil
self.v_start = false self.v_start = false
else else
local s = self.object:getpos() local vec = {x=p.x-s.x, y=p.y-s.y, z=p.z-s.z}
local p = self.following:getpos() local yaw = math.atan(vec.z/vec.x)+math.pi/2
local dist = ((p.x-s.x)^2 + (p.y-s.y)^2 + (p.z-s.z)^2)^0.5 if self.drawtype == "side" then
if dist > self.view_range then yaw = yaw+(math.pi/2)
self.following = nil
self.v_start = false
else
local vec = {x=p.x-s.x, y=p.y-s.y, z=p.z-s.z}
local yaw = math.atan(vec.z/vec.x)+math.pi/2
if self.drawtype == "side" then
yaw = yaw+(math.pi/2)
end
if p.x > s.x then
yaw = yaw+math.pi
end
self.object:setyaw(yaw)
if dist > 2 then
if not self.v_start then
self.v_start = true
self.set_velocity(self, self.walk_velocity)
else
if self.jump and self.get_velocity(self) <= 0.5 and self.object:getvelocity().y == 0 then
self:jump()
end
self.set_velocity(self, self.walk_velocity)
end
self:set_animation("walk")
else
self.v_start = false
self.set_velocity(self, 0)
self:set_animation("stand")
end
return
end end
if p.x > s.x then
yaw = yaw+math.pi
end
self.object:setyaw(yaw)
if dist > 2 then
if not self.v_start then
self.v_start = true
self.set_velocity(self, self.walk_velocity)
else
if self.jump and self.get_velocity(self) <= 0.5 and self.object:getvelocity().y == 0 then
self:jump()
end
self.set_velocity(self, self.walk_velocity)
end
self:set_animation("walk")
else
self.v_start = false
self.set_velocity(self, 0)
self:set_animation("stand")
end
return
end end
end end
end
if self.state == "stand" then
if math.random(1, 4) == 1 then if self.state == "stand" then
self.object:setyaw(self.object:getyaw()+((math.random(0,360)-180)/180*math.pi)) if math.random(1, 4) == 1 then
end self.object:setyaw(self.object:getyaw()+((math.random(0,360)-180)/180*math.pi))
self.set_velocity(self, 0) end
self.set_animation(self, "stand") self.set_velocity(self, 0)
if math.random(1, 100) <= 50 then self.set_animation(self, "stand")
self.set_velocity(self, self.walk_velocity) if math.random(1, 100) <= 50 then
self.state = "walk"
self.set_animation(self, "walk")
end
elseif self.state == "walk" then
if math.random(1, 100) <= 30 then
self.object:setyaw(self.object:getyaw()+((math.random(0,360)-180)/180*math.pi))
end
if self.jump and self.get_velocity(self) <= 0.5 and self.object:getvelocity().y == 0 then
self:jump()
end
self:set_animation("walk")
self.set_velocity(self, self.walk_velocity) self.set_velocity(self, self.walk_velocity)
if math.random(1, 100) <= 10 then self.state = "walk"
self.set_velocity(self, 0) self.set_animation(self, "walk")
self.state = "stand" end
self:set_animation("stand") elseif self.state == "walk" then
end if math.random(1, 100) <= 30 then
elseif self.state == "attack" and self.attack_type == "dogfight" then self.object:setyaw(self.object:getyaw()+((math.random(0,360)-180)/180*math.pi))
if not self.attack.player or not self.attack.player:is_player() then end
self.state = "stand" if self.jump and self.get_velocity(self) <= 0.5 and self.object:getvelocity().y == 0 then
self:set_animation("stand") self:jump()
self.attack = {player=nil, dist=nil} end
return self:set_animation("walk")
end self.set_velocity(self, self.walk_velocity)
local s = self.object:getpos() if math.random(1, 100) <= 10 then
local p = self.attack.player:getpos()
local dist = ((p.x-s.x)^2 + (p.y-s.y)^2 + (p.z-s.z)^2)^0.5
if dist > self.view_range or self.attack.player:get_hp() <= 0 then
self.state = "stand"
self.v_start = false
self.set_velocity(self, 0)
self.attack = {player=nil, dist=nil}
self:set_animation("stand")
return
else
self.attack.dist = dist
end
local vec = {x=p.x-s.x, y=p.y-s.y, z=p.z-s.z}
local yaw = math.atan(vec.z/vec.x)+math.pi/2
if self.drawtype == "side" then
yaw = yaw+(math.pi/2)
end
if p.x > s.x then
yaw = yaw+math.pi
end
self.object:setyaw(yaw)
if self.attack.dist > 2 then
if not self.v_start then
self.v_start = true
self.set_velocity(self, self.run_velocity)
else
if self.jump and self.get_velocity(self) <= 0.5 and self.object:getvelocity().y == 0 then
self:jump()
end
self.set_velocity(self, self.run_velocity)
end
self:set_animation("run")
else
self.set_velocity(self, 0)
self:set_animation("punch")
self.v_start = false
if self.timer > 1 then
self.timer = 0
if self.sounds and self.sounds.attack then
minetest.sound_play(self.sounds.attack, {object = self.object})
end
self.attack.player:punch(self.object, 1.0, {
full_punch_interval=1.0,
damage_groups = {fleshy=self.damage}
}, vec)
end
end
elseif self.state == "attack" and self.attack_type == "shoot" then
if not self.attack.player or not self.attack.player:is_player() then
self.state = "stand"
self:set_animation("stand")
self.attack = {player=nil, dist=nil}
return
end
local s = self.object:getpos()
local p = self.attack.player:getpos()
local dist = ((p.x-s.x)^2 + (p.y-s.y)^2 + (p.z-s.z)^2)^0.5
if dist > self.view_range or self.attack.player:get_hp() <= 0 then
self.state = "stand"
self.v_start = false
self.set_velocity(self, 0)
self.attack = {player=nil, dist=nil}
self:set_animation("stand")
return
else
self.attack.dist = dist
end
local vec = {x=p.x-s.x, y=p.y-s.y, z=p.z-s.z}
local yaw = math.atan(vec.z/vec.x)+math.pi/2
if self.drawtype == "side" then
yaw = yaw+(math.pi/2)
end
if p.x > s.x then
yaw = yaw+math.pi
end
self.object:setyaw(yaw)
self.set_velocity(self, 0) self.set_velocity(self, 0)
self.state = "stand"
if self.timer > self.shoot_interval and math.random(1, 100) <= 60 then self:set_animation("stand")
end
elseif self.state == "attack" and self.attack_type == "dogfight" then
if not self.attack.player or not self.attack.player:is_player() then
self.state = "stand"
self:set_animation("stand")
self.attack = {player=nil, dist=nil}
return
end
local s = self.object:getpos()
local p = self.attack.player:getpos()
local dist = ((p.x-s.x)^2 + (p.y-s.y)^2 + (p.z-s.z)^2)^0.5
if dist > self.view_range or self.attack.player:get_hp() <= 0 then
self.state = "stand"
self.v_start = false
self.set_velocity(self, 0)
self.attack = {player=nil, dist=nil}
self:set_animation("stand")
return
else
self.attack.dist = dist
end
local vec = {x=p.x-s.x, y=p.y-s.y, z=p.z-s.z}
local yaw = math.atan(vec.z/vec.x)+math.pi/2
if self.drawtype == "side" then
yaw = yaw+(math.pi/2)
end
if p.x > s.x then
yaw = yaw+math.pi
end
self.object:setyaw(yaw)
if self.attack.dist > 2 then
if not self.v_start then
self.v_start = true
self.set_velocity(self, self.run_velocity)
else
if self.jump and self.get_velocity(self) <= 0.5 and self.object:getvelocity().y == 0 then
self:jump()
end
self.set_velocity(self, self.run_velocity)
end
self:set_animation("run")
else
self.set_velocity(self, 0)
self:set_animation("punch")
self.v_start = false
if self.timer > 1 then
self.timer = 0 self.timer = 0
self:set_animation("punch")
if self.sounds and self.sounds.attack then if self.sounds and self.sounds.attack then
minetest.sound_play(self.sounds.attack, {object = self.object}) minetest.sound_play(self.sounds.attack, {object = self.object})
end end
self.attack.player:punch(self.object, 1.0, {
local p = self.object:getpos() full_punch_interval=1.0,
p.y = p.y + (self.collisionbox[2]+self.collisionbox[5])/2 damage_groups = {fleshy=self.damage}
local obj = minetest.env:add_entity(p, self.arrow) }, vec)
local amount = (vec.x^2+vec.y^2+vec.z^2)^0.5
local v = obj:get_luaentity().velocity
vec.y = vec.y+1
vec.x = vec.x*v/amount
vec.y = vec.y*v/amount
vec.z = vec.z*v/amount
obj:setvelocity(vec)
end end
end end
end, elseif self.state == "attack" and self.attack_type == "shoot" then
if not self.attack.player or not self.attack.player:is_player() then
on_activate = function(self, staticdata, dtime_s) self.state = "stand"
self.object:set_armor_groups({fleshy=self.armor}) self:set_animation("stand")
self.object:setacceleration({x=0, y=-10, z=0}) self.attack = {player=nil, dist=nil}
self.state = "stand" return
self.attack = {player = nil, dist = nil}
self.object:setvelocity({x=0, y=self.object:getvelocity().y, z=0})
self.object:setyaw(math.random(1, 360)/180*math.pi)
if self.type == "monster" and minetest.setting_getbool("only_peaceful_mobs") then
self.object:remove()
end end
self.lifetimer = 600 - dtime_s local s = self.object:getpos()
if staticdata then local p = self.attack.player:getpos()
local tmp = minetest.deserialize(staticdata) local dist = ((p.x-s.x)^2 + (p.y-s.y)^2 + (p.z-s.z)^2)^0.5
if tmp and tmp.lifetimer then if dist > self.view_range or self.attack.player:get_hp() <= 0 then
self.lifetimer = tmp.lifetimer - dtime_s self.state = "stand"
end self.v_start = false
if tmp and tmp.tamed then self.set_velocity(self, 0)
self.tamed = tmp.tamed self.attack = {player=nil, dist=nil}
self:set_animation("stand")
return
else
self.attack.dist = dist
end
local vec = {x=p.x-s.x, y=p.y-s.y, z=p.z-s.z}
local yaw = math.atan(vec.z/vec.x)+math.pi/2
if self.drawtype == "side" then
yaw = yaw+(math.pi/2)
end
if p.x > s.x then
yaw = yaw+math.pi
end
self.object:setyaw(yaw)
self.set_velocity(self, 0)
if self.timer > self.shoot_interval and math.random(1, 100) <= 60 then
self.timer = 0
self:set_animation("punch")
if self.sounds and self.sounds.attack then
minetest.sound_play(self.sounds.attack, {object = self.object})
end end
local p = self.object:getpos()
p.y = p.y + (self.collisionbox[2]+self.collisionbox[5])/2
local obj = minetest.env:add_entity(p, self.arrow)
local amount = (vec.x^2+vec.y^2+vec.z^2)^0.5
local v = obj:get_luaentity().velocity
vec.y = vec.y+1
vec.x = vec.x*v/amount
vec.y = vec.y*v/amount
vec.z = vec.z*v/amount
obj:setvelocity(vec)
end end
if self.lifetimer <= 0 and not self.tamed then end
self.object:remove() end,
on_activate = function(self, staticdata, dtime_s)
self.object:set_armor_groups({fleshy=self.armor})
self.object:setacceleration({x=0, y=-10, z=0})
self.state = "stand"
self.attack = {player = nil, dist = nil}
self.object:setvelocity({x=0, y=self.object:getvelocity().y, z=0})
self.object:setyaw(math.random(1, 360)/180*math.pi)
if self.type == "monster" and minetest.setting_getbool("only_peaceful_mobs") then
self.object:remove()
end
self.lifetimer = 600 - dtime_s
if staticdata then
local tmp = minetest.deserialize(staticdata)
if tmp and tmp.lifetimer then
self.lifetimer = tmp.lifetimer - dtime_s
end end
end, if tmp and tmp.tamed then
self.tamed = tmp.tamed
get_staticdata = function(self) end
local tmp = { end
lifetimer = self.lifetimer, if self.lifetimer <= 0 and not self.tamed then
tamed = self.tamed, self.object:remove()
} end
return minetest.serialize(tmp) end,
end,
get_staticdata = function(self)
on_punch = function(self, hitter) local tmp = {
if self.object:get_hp() <= 0 then lifetimer = self.lifetimer,
if hitter and hitter:is_player() and hitter:get_inventory() then tamed = self.tamed,
for _,drop in ipairs(self.drops) do }
if math.random(1, drop.chance) == 1 then return minetest.serialize(tmp)
hitter:get_inventory():add_item("main", ItemStack(drop.name.." "..math.random(drop.min, drop.max))) end,
end
on_punch = function(self, hitter)
if self.object:get_hp() <= 0 then
if hitter and hitter:is_player() and hitter:get_inventory() then
for _,drop in ipairs(self.drops) do
if math.random(1, drop.chance) == 1 then
hitter:get_inventory():add_item("main", ItemStack(drop.name.." "..math.random(drop.min, drop.max)))
end end
end end
end end
end, end
end,
})
__index = function(table,key)
return mobs.default_definition[key]
end,}
function mobs:register_mob(name, def)
setmetatable (def,mobs.default_definition)
minetest.register_entity(name, def)
end end
mobs.spawning_mobs = {} mobs.spawning_mobs = {}