diff --git a/death.lua b/death.lua new file mode 100644 index 0000000000000000000000000000000000000000..eb057e393baef974841222c1743d0d1bd5cfbc3a --- /dev/null +++ b/death.lua @@ -0,0 +1,42 @@ + +-- adopted from https://github.com/pandorabox-io/pandorabox_custom/blob/master/death.lua +local BONES_WAYPOINT_EXPIRES_SECONDS = 42 * 60 + +minetest.register_on_dieplayer(function(player) + local player_name = player:get_player_name() + local pos = player:get_pos() + + pos.x = math.floor(pos.x + 0.5) + pos.y = math.floor(pos.y + 0.5) + pos.z = math.floor(pos.z + 0.5) + + local pos_string = minetest.pos_to_string(pos) + + minetest.log("action", "[death] player '" .. player_name .. "' died at " .. pos_string) + minetest.chat_send_player(player_name, "You died at " .. pos_string) + + local bone_string = "Bones" + if player.get_attribute then + -- [xp_redo] keeps track of deathcount, let's see if it is there + local count = player:get_attribute("died") + if count then + bone_string = "Bone #" .. tostring(count) + end + end -- if not fake player + local hud_id = player:hud_add({ + hud_elem_type = "waypoint", + name = bone_string .. " " .. pos_string, + text = "m", + number = 0xFFFFFF, + world_pos = pos + }) + + minetest.after(BONES_WAYPOINT_EXPIRES_SECONDS, function() + -- retrieve player by name, the "player" object should not be carried across server-steps + player = minetest.get_player_by_name(player_name) + if player then + player:hud_remove(hud_id) + end + end) + +end) diff --git a/init.lua b/init.lua index bc605651008a4364c5fc06a1ef0333d41385653b..63b5ca7a530377492197284406e75095ccdfaaa7 100644 --- a/init.lua +++ b/init.lua @@ -19,5 +19,8 @@ end -- /spawn command dofile(MP.."/chat/spawn.lua") +-- death message +dofile(MP.."/death.lua") + -- by popular demand dofile(MP.."/additional_stuff/salad_pickaxe.lua")