Make it so you cannot spam hit mobs

This commit is contained in:
oilboi 2020-03-31 03:55:54 -04:00
parent 37ff89a400
commit a0dc2547b5
2 changed files with 25 additions and 14 deletions

View File

@ -45,6 +45,7 @@ mob.hunger = 200
mob.view_distance = 20
mob.punch_timer = 0
mob.punched_timer = 0
----------------------------------

View File

@ -5,12 +5,18 @@ mob.manage_punch_timer = function(self,dtime)
if self.punch_timer > 0 then
self.punch_timer = self.punch_timer - dtime
end
--this controls how fast you can punch the mob (punched timer reset)
if self.punched_timer > 0 then
print(self.punched_timer)
self.punched_timer = self.punched_timer - dtime
end
end
--this controls what happens when the mob gets punched
mob.on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir)
print(time_from_last_punch)
if self.punched_timer <= 0 then
self.punched_timer = 0.8
local hurt = tool_capabilities.damage_groups.fleshy
if not hurt then
hurt = 1
@ -22,7 +28,11 @@ mob.on_punch = function(self, puncher, time_from_last_punch, tool_capabilities,
end
self.hp = hp-hurt
self.direction = vector.multiply(dir,-1)
self.speed = 5
dir = vector.multiply(dir,10)
dir.y = 4
self.object:add_velocity(dir)
end
end