Hear other players get hurt, reorg player health mod.

This commit is contained in:
Aaron Suen 2019-04-06 21:23:14 -04:00
parent 5a115bdaa8
commit 31fbfd8d33
4 changed files with 26 additions and 14 deletions

View File

@ -0,0 +1,25 @@
-- LUALOCALS < ---------------------------------------------------------
local ipairs, minetest, vector
= ipairs, minetest, vector
-- LUALOCALS > ---------------------------------------------------------
minetest.register_on_player_hpchange(function(player, hp)
if hp < 0 then
local pos = player:get_pos()
for _, p in ipairs(minetest.get_connected_players()) do
if p ~= player and vector.distance(p:get_pos(), pos) <= 32 then
minetest.sound_play("player_damage", {
to_player = p:get_player_name(),
pos = pos,
gain = 0.5
})
end
end
end
local t = player:get_hp()
if hp + t <= 0 then
hp = 1 - t
player:get_meta():set_float("dhp", -1)
end
return hp
end, true)

View File

@ -1,13 +0,0 @@
-- LUALOCALS < ---------------------------------------------------------
local minetest
= minetest
-- LUALOCALS > ---------------------------------------------------------
minetest.register_on_player_hpchange(function(player, hp)
local t = player:get_hp()
if hp + t <= 0 then
hp = 1 - t
player:get_meta():set_float("dhp", -1)
end
return hp
end, true)

View File

@ -5,4 +5,4 @@ local include
include("healing")
include("ejectinv")
include("death")
include("damage")