Tweaked knock-back routine
This commit is contained in:
parent
0cb006ee97
commit
3fc65118da
41
api.lua
41
api.lua
@ -1,4 +1,4 @@
|
|||||||
-- Mobs Api (7th November 2015)
|
-- Mobs Api (9th November 2015)
|
||||||
mobs = {}
|
mobs = {}
|
||||||
mobs.mod = "redo"
|
mobs.mod = "redo"
|
||||||
|
|
||||||
@ -718,19 +718,25 @@ minetest.register_entity(name, {
|
|||||||
|
|
||||||
-- knockback timer
|
-- knockback timer
|
||||||
if self.pause_timer > 0 then
|
if self.pause_timer > 0 then
|
||||||
|
|
||||||
self.pause_timer = self.pause_timer - dtime
|
self.pause_timer = self.pause_timer - dtime
|
||||||
|
|
||||||
if self.pause_timer < 1 then
|
if self.pause_timer < 1 then
|
||||||
self.pause_timer = 0
|
self.pause_timer = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- attack timer
|
-- attack timer
|
||||||
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
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
self.timer = 0
|
self.timer = 0
|
||||||
end
|
end
|
||||||
-- never go over 100
|
-- never go over 100
|
||||||
@ -1394,6 +1400,11 @@ minetest.register_entity(name, {
|
|||||||
|
|
||||||
on_punch = function(self, hitter, tflp, tool_capabilities, dir)
|
on_punch = function(self, hitter, tflp, tool_capabilities, dir)
|
||||||
|
|
||||||
|
-- cannot punch spamming
|
||||||
|
if tflp < 0.45 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
-- weapon wear
|
-- weapon wear
|
||||||
local weapon = hitter:get_wielded_item()
|
local weapon = hitter:get_wielded_item()
|
||||||
local punch_interval = 1.4
|
local punch_interval = 1.4
|
||||||
@ -1402,10 +1413,9 @@ minetest.register_entity(name, {
|
|||||||
punch_interval = tool_capabilities.full_punch_interval or 1.4
|
punch_interval = tool_capabilities.full_punch_interval or 1.4
|
||||||
end
|
end
|
||||||
|
|
||||||
if weapon:get_definition()
|
if weapon:get_definition()
|
||||||
and weapon:get_definition().tool_capabilities then
|
and weapon:get_definition().tool_capabilities then
|
||||||
local wear = math.floor((punch_interval / 75) * 9000)
|
weapon:add_wear(math.floor((punch_interval / 75) * 9000))
|
||||||
weapon:add_wear(wear)
|
|
||||||
hitter:set_wielded_item(weapon)
|
hitter:set_wielded_item(weapon)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1441,26 +1451,25 @@ minetest.register_entity(name, {
|
|||||||
-- knock back effect
|
-- knock back effect
|
||||||
if self.knock_back > 0 then
|
if self.knock_back > 0 then
|
||||||
|
|
||||||
local kb = self.knock_back
|
|
||||||
local r = self.recovery_time
|
|
||||||
local v = self.object:getvelocity()
|
local v = self.object:getvelocity()
|
||||||
|
local r = 1.4 - math.min(punch_interval, 1.4)
|
||||||
if tflp < punch_interval then
|
--local r = self.recovery_time
|
||||||
|
local kb = r * 5
|
||||||
if kb > 0 then
|
--local kb = self.knock_back
|
||||||
kb = kb * (tflp / punch_interval)
|
|
||||||
end
|
|
||||||
|
|
||||||
r = r * (tflp / punch_interval)
|
|
||||||
end
|
|
||||||
|
|
||||||
self.object:setvelocity({
|
self.object:setvelocity({
|
||||||
x = dir.x * kb,
|
x = dir.x * kb,
|
||||||
y = 0,
|
y = 2,
|
||||||
z = dir.z * kb
|
z = dir.z * kb
|
||||||
})
|
})
|
||||||
|
|
||||||
self.pause_timer = r
|
self.pause_timer = r
|
||||||
|
set_animation(self, "stand")
|
||||||
|
self.state = "nada" -- temporary state
|
||||||
|
|
||||||
|
minetest.after(r, function()
|
||||||
|
self.state = "stand"
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- attack puncher and call other mobs for help
|
-- attack puncher and call other mobs for help
|
||||||
|
Loading…
x
Reference in New Issue
Block a user