Aaron Suen 40c239a798 Defer social damage sounds until after all modifiers.
This allows external mods that alter damage to prevent damage
sounds from playing for other nearby players if they modify the
damage amount.
2019-04-08 08:26:44 -04:00

24 lines
647 B
Lua

-- LUALOCALS < ---------------------------------------------------------
local minetest, nodecore
= minetest, nodecore
-- LUALOCALS > ---------------------------------------------------------
minetest.register_on_player_hpchange(function(player, hp)
local orig = player:get_hp()
if hp < 0 then
minetest.after(0, function()
local now = player:get_hp()
if now >= orig then return end
nodecore.sound_play_except("player_damage", {
pos = player:get_pos(),
gain = 0.5
}, player)
end)
end
if hp + orig <= 0 then
hp = 1 - orig
player:get_meta():set_float("dhp", -1)
end
return hp
end, true)