mirror of
https://github.com/minetest-mods/throwing.git
synced 2025-01-09 17:50:25 +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).
|
* 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
|
* 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_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.
|
- pos: the position of the hit node or object.
|
||||||
- last_pos: the last air node where the arrow was
|
- last_pos: the last air node where the arrow was
|
||||||
- node and object: hit node or object. Either node or object is nil, depending
|
- 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
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local ret, reason = self.on_hit(pos, self.last_pos, node, obj, player, self.data, self)
|
if self.on_hit then
|
||||||
if ret == false then
|
local ret, reason = self.on_hit(pos, self.last_pos, node, obj, player, self.data, self)
|
||||||
if reason then
|
if ret == false then
|
||||||
logging(": on_hit function failed for reason: "..reason)
|
if reason then
|
||||||
else
|
logging(": on_hit function failed for reason: "..reason)
|
||||||
logging(": on_hit function failed")
|
else
|
||||||
end
|
logging(": on_hit function failed")
|
||||||
|
end
|
||||||
|
|
||||||
hit_failed()
|
hit_failed()
|
||||||
return
|
return
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.on_hit_sound then
|
if self.on_hit_sound then
|
||||||
|
Loading…
Reference in New Issue
Block a user