From baa44b920bdfc4eb5cc679c345d94a51f210640a Mon Sep 17 00:00:00 2001 From: Peter Nerlich <peter.nerlich+dev@googlemail.com> Date: Tue, 1 Dec 2020 11:34:50 +0100 Subject: [PATCH] death marker adopted from https://github.com/pandorabox-io/pandorabox_custom/blob/master/death.lua --- death.lua | 42 ++++++++++++++++++++++++++++++++++++++++++ init.lua | 3 +++ 2 files changed, 45 insertions(+) create mode 100644 death.lua diff --git a/death.lua b/death.lua new file mode 100644 index 0000000..eb057e3 --- /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 bc60565..63b5ca7 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") -- GitLab