Make the on_hit field optional

This commit is contained in:
upsilon 2017-06-20 16:42:35 +02:00
parent 552b958dba
commit d33a8b69ca
No known key found for this signature in database
GPG Key ID: A80DAE1F266E1C3C
2 changed files with 12 additions and 10 deletions

View File

@ -61,7 +61,7 @@ Definition: definition table, containing:
* target (optional, defaulting to throwing.target_both): what the arrow is able to hit (throwing.target_node, throwing.target_object, throwing.target_both).
* allow_protected (optional, defaulting to false): whether the arrow can be throw in a protected area
* on_hit_sound (optional): sound played when the arrow hits a node or an object.
* on_hit(pos, last_pos, node, object, hitter, data, self) (must exist, will crash if nil): callback function:
* on_hit(pos, last_pos, node, object, hitter, data, self) (optional but very useful): callback function:
- pos: the position of the hit node or object.
- last_pos: the last air node where the arrow was
- node and object: hit node or object. Either node or object is nil, depending

View File

@ -111,16 +111,18 @@ local function arrow_step(self, dtime)
return
end
local ret, reason = self.on_hit(pos, self.last_pos, node, obj, player, self.data, self)
if ret == false then
if reason then
logging(": on_hit function failed for reason: "..reason)
else
logging(": on_hit function failed")
end
if self.on_hit then
local ret, reason = self.on_hit(pos, self.last_pos, node, obj, player, self.data, self)
if ret == false then
if reason then
logging(": on_hit function failed for reason: "..reason)
else
logging(": on_hit function failed")
end
hit_failed()
return
hit_failed()
return
end
end
if self.on_hit_sound then