From eb35d7ffea128ea42f15ee843fc7145b7c7768d5 Mon Sep 17 00:00:00 2001 From: PilzAdam Date: Wed, 19 Sep 2012 20:38:03 +0200 Subject: [PATCH] Add falling damage --- api.lua | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/api.lua b/api.lua index 1d6a9b8..e2f1d37 100644 --- a/api.lua +++ b/api.lua @@ -24,6 +24,7 @@ function mobs:register_monster(name, def) attack = {player=nil, dist=nil}, state = "stand", v_start = false, + old_y = nil, set_velocity = function(self, v) @@ -54,6 +55,24 @@ function mobs:register_monster(name, def) self.object:setacceleration({x=0, y=-10, z=0}) 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 if self.state ~= "attack" then if self.timer < 1 then @@ -67,7 +86,7 @@ function mobs:register_monster(name, def) self.object:punch(self.object, 1.0, { full_punch_interval=1.0, groupcaps={ - fleshy={times={[3]=1/10}}, + fleshy={times={[self.armor]=1/1}}, } }, nil) end @@ -257,6 +276,7 @@ function mobs:register_animal(name, def) timer = 0, state = "stand", + old_y = nil, set_velocity = function(self, v) @@ -287,6 +307,24 @@ function mobs:register_animal(name, def) self.object:setacceleration({x=0, y=-10, z=0}) 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 if self.timer < 1 then return