tweak custom attack function
This commit is contained in:
parent
3b8c4bc070
commit
245128f9e6
15
api.lua
15
api.lua
@ -1224,7 +1224,6 @@ local entity_physics = function(pos, radius)
|
|||||||
|
|
||||||
-- punches work on entities AND players
|
-- punches work on entities AND players
|
||||||
objs[n]:punch(objs[n], 1.0, {
|
objs[n]:punch(objs[n], 1.0, {
|
||||||
-- objs[n]:punch(nil, 1.0, {
|
|
||||||
full_punch_interval = 1.0,
|
full_punch_interval = 1.0,
|
||||||
damage_groups = {fleshy = damage},
|
damage_groups = {fleshy = damage},
|
||||||
}, pos)
|
}, pos)
|
||||||
@ -2524,9 +2523,11 @@ function mob_class:do_states(dtime)
|
|||||||
|
|
||||||
self:set_velocity(0)
|
self:set_velocity(0)
|
||||||
|
|
||||||
if not self.custom_attack then
|
if self.timer > 1 then
|
||||||
|
|
||||||
if self.timer > 1 then
|
-- no custom attack or custom attack returns true to continue
|
||||||
|
if not self.custom_attack
|
||||||
|
or self:custom_attack(self, p) == true then
|
||||||
|
|
||||||
self.timer = 0
|
self.timer = 0
|
||||||
self:set_animation("punch")
|
self:set_animation("punch")
|
||||||
@ -2555,14 +2556,6 @@ function mob_class:do_states(dtime)
|
|||||||
}, nil)
|
}, nil)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else -- call custom attack every second
|
|
||||||
if self.custom_attack
|
|
||||||
and self.timer > 1 then
|
|
||||||
|
|
||||||
self.timer = 0
|
|
||||||
|
|
||||||
self:custom_attack(p)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
3
api.txt
3
api.txt
@ -291,7 +291,8 @@ enhance mob functionality and have them do many interesting things:
|
|||||||
time_from_last_punch, tool_capabilities, direction), return
|
time_from_last_punch, tool_capabilities, direction), return
|
||||||
false to stop punch damage and knockback from taking place.
|
false to stop punch damage and knockback from taking place.
|
||||||
'custom_attack' when set this function is called instead of the normal mob
|
'custom_attack' when set this function is called instead of the normal mob
|
||||||
melee attack, parameters are (self, to_attack).
|
melee attack, parameters are (self, to_attack) and if true
|
||||||
|
is returned normal attack function continued.
|
||||||
'on_die' a function that is called when mob is killed (self, pos)
|
'on_die' a function that is called when mob is killed (self, pos)
|
||||||
'do_custom' a custom function that is called every tick while mob is
|
'do_custom' a custom function that is called every tick while mob is
|
||||||
active and which has access to all of the self.* variables
|
active and which has access to all of the self.* variables
|
||||||
|
Loading…
x
Reference in New Issue
Block a user