AnxiousInfusion wrote:Thanks, even though that is sad news. I got 90% of the way through making a sword with dynamic sound effects only to get snagged on the on_use override. Maybe I can have it set_hp() if pointed_thing is an object ... object.is_player() ... ?
I really wish the engine had some sort of register-damage function.
I was about to suggest the after_use callback but this only called after a node is dug and I’m not sure if it is even called at all for players or entities.
I came up with this idea which essentially allows you to add a ‘sounds’ table to any tool definition. Unfortunately due to limitations of the api this will only work when you hit nodes or players, not entities.
- Code: Select all
minetest.register_on_punchnode(function(pos, node, puncher)
local tool = puncher:get_wielded_item()
if tool then
local def = tool:get_definition()
if def and def.sounds and def.sounds.node then
minetest.sound_play(def.sounds.node, {pos=pos})
end
end
end)
minetest.register_on_punchplayer(function(player, hitter)
local tool = hitter:get_wielded_item()
if tool then
local def = tool:get_definition()
if def and def.sounds and def.sounds.player then
minetest.sound_play(def.sounds.player, {object=player})
end
end
end)
-- example tooldef
minetest.register_tool("soundfx:pick_glass", {
description = "Glass Pickaxe",
inventory_image = "soundfx_pick_glass.png",
tool_capabilities = { ... },
sounds = {
node = "default_break_glass",
player = "default_break_glass",
},
})
It seems a bit incomplete that we should have on_punchnode and on_punchplayer but no equivalent for entities :(