From d45602c3fa8ac6c32366d98e1ac37ecde41be08c Mon Sep 17 00:00:00 2001 From: MoNTE48 Date: Wed, 26 May 2021 19:27:05 +0200 Subject: [PATCH] Player_api: add waypoint of death --- files/player/player_api/init.lua | 44 ++++++++++++++++--- .../player/player_api/locale/player_api.ru.tr | 2 + 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/files/player/player_api/init.lua b/files/player/player_api/init.lua index a088098..9245f11 100644 --- a/files/player/player_api/init.lua +++ b/files/player/player_api/init.lua @@ -112,9 +112,13 @@ if not creative_mode_cache and minetest.is_singleplayer() then end) end --- Drop items at death +-- Drop items at death and add waypoint +local dead_waypoint = {} +local waypoint_live = tonumber(minetest.settings:get("item_entity_ttl")) or 600 + minetest.register_on_dieplayer(function(player) - local pos = player:get_pos() + local name = player:get_player_name() + local pos = vector.round(player:get_pos()) local inv = player:get_inventory() -- Drop inventory items @@ -133,9 +137,39 @@ minetest.register_on_dieplayer(function(player) end -- Display death coordinates - local name = player:get_player_name() - local pos_string = minetest.pos_to_string(pos, 1) + local pos_string = minetest.pos_to_string(pos) - minetest.chat_send_player(name, S("Your last coordinates: @1", pos_string)) + minetest.chat_send_player(name, + S("Your last coordinates: @1", pos_string)) minetest.log("action", "Player \"" .. name .. "\" died at " .. pos_string) + + -- Add Waypoint + if dead_waypoint[name] then + player:hud_remove(dead_waypoint[name]) + end + + local hud = player:hud_add({ + hud_elem_type = "waypoint", + name = S("Your point of death:"), + text = S("m left"), + number = "0xd80a1b", + world_pos = pos + }) + dead_waypoint[name] = hud + + minetest.after(waypoint_live, function() + if dead_waypoint[name] then + player:hud_remove(dead_waypoint[name]) + dead_waypoint[name] = nil + end + end) +end) + +minetest.register_on_leaveplayer(function(player) + local name = player:get_player_name() + + if dead_waypoint[name] then + player:hud_remove(dead_waypoint[name]) + dead_waypoint[name] = nil + end end) diff --git a/files/player/player_api/locale/player_api.ru.tr b/files/player/player_api/locale/player_api.ru.tr index e4f017e..ea8d8cb 100644 --- a/files/player/player_api/locale/player_api.ru.tr +++ b/files/player/player_api/locale/player_api.ru.tr @@ -1,2 +1,4 @@ # textdomain: player_api Your last coordinates: @1=Ваши последние координаты: @1 +Your point of death:=Ваша точка смерти: +m left=м осталось