Add falling damage
This commit is contained in:
parent
7672041b15
commit
eb35d7ffea
40
api.lua
40
api.lua
@ -24,6 +24,7 @@ function mobs:register_monster(name, def)
|
|||||||
attack = {player=nil, dist=nil},
|
attack = {player=nil, dist=nil},
|
||||||
state = "stand",
|
state = "stand",
|
||||||
v_start = false,
|
v_start = false,
|
||||||
|
old_y = nil,
|
||||||
|
|
||||||
|
|
||||||
set_velocity = function(self, v)
|
set_velocity = function(self, v)
|
||||||
@ -54,6 +55,24 @@ function mobs:register_monster(name, def)
|
|||||||
self.object:setacceleration({x=0, y=-10, z=0})
|
self.object:setacceleration({x=0, y=-10, z=0})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if 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:punch(self.object, 1.0, {
|
||||||
|
full_punch_interval=1.0,
|
||||||
|
groupcaps={
|
||||||
|
fleshy={times={[self.armor]=1/damage}},
|
||||||
|
}
|
||||||
|
}, nil)
|
||||||
|
end
|
||||||
|
self.old_y = self.object:getpos().y
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
self.timer = self.timer+dtime
|
self.timer = self.timer+dtime
|
||||||
if self.state ~= "attack" then
|
if self.state ~= "attack" then
|
||||||
if self.timer < 1 then
|
if self.timer < 1 then
|
||||||
@ -67,7 +86,7 @@ function mobs:register_monster(name, def)
|
|||||||
self.object:punch(self.object, 1.0, {
|
self.object:punch(self.object, 1.0, {
|
||||||
full_punch_interval=1.0,
|
full_punch_interval=1.0,
|
||||||
groupcaps={
|
groupcaps={
|
||||||
fleshy={times={[3]=1/10}},
|
fleshy={times={[self.armor]=1/1}},
|
||||||
}
|
}
|
||||||
}, nil)
|
}, nil)
|
||||||
end
|
end
|
||||||
@ -257,6 +276,7 @@ function mobs:register_animal(name, def)
|
|||||||
|
|
||||||
timer = 0,
|
timer = 0,
|
||||||
state = "stand",
|
state = "stand",
|
||||||
|
old_y = nil,
|
||||||
|
|
||||||
|
|
||||||
set_velocity = function(self, v)
|
set_velocity = function(self, v)
|
||||||
@ -287,6 +307,24 @@ function mobs:register_animal(name, def)
|
|||||||
self.object:setacceleration({x=0, y=-10, z=0})
|
self.object:setacceleration({x=0, y=-10, z=0})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if 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:punch(self.object, 1.0, {
|
||||||
|
full_punch_interval=1.0,
|
||||||
|
groupcaps={
|
||||||
|
fleshy={times={[3]=1/damage}},
|
||||||
|
}
|
||||||
|
}, nil)
|
||||||
|
end
|
||||||
|
self.old_y = self.object:getpos().y
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
self.timer = self.timer+dtime
|
self.timer = self.timer+dtime
|
||||||
if self.timer < 1 then
|
if self.timer < 1 then
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user