mirror of
https://github.com/minetest-mods/throwing.git
synced 2025-01-09 09:40:26 +01:00
Make the on_hit field optional
This commit is contained in:
parent
552b958dba
commit
d33a8b69ca
@ -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
|
||||
|
20
init.lua
20
init.lua
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user