From 5af7b5e450c12abedc9f78e622c744a351ee418d Mon Sep 17 00:00:00 2001 From: BrownHedgehog78 Date: Wed, 1 Dec 2021 13:13:24 +0200 Subject: [PATCH] Improve the mod a bit --- LICENSE | 21 +++++++++++++++++++++ README.md | 10 ++++++++++ init.lua | 46 ++++++++++++++++++++++++++++++++++++++++++++++ mod.conf | 5 +++++ 4 files changed, 82 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100644 init.lua create mode 100644 mod.conf diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..7693f04 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 BlueR23 (BrownHedgehog78) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..78f89b2 --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +# Death Position + +Minetest mod that adds a command to teleport to player's last death position + +### Usage + +Use ``/death_pos`` command to return back to the last death position. + +#### Settings +To disable message that sends a tip when player dies, add setting ``death_pos.send_tip_on_die`` in ``minetest.conf`` and set it to ``false``, it should be like this: ``death_pos.send_tip_on_die = false``. When player uses the ``/death_pos`` command it clears the death pos and the player can't teleport to the last death position again, but you can disable it, add this setting in ``minetest.conf``: ``death_pos.clear_pos = false``. diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..a702412 --- /dev/null +++ b/init.lua @@ -0,0 +1,46 @@ +local death_pos = {} +local was_killed = {} +local tip_sent = {} + +minetest.register_on_dieplayer(function(player, reason) + local name = player:get_player_name() + local send_tip = minetest.settings:get("death_pos.send_tip_on_die") or true -- Sends tip to use 'death_pos' command when player dies (if true) + death_pos[name] = player:get_pos() + if reason.type == "punch" and reason.object:is_player() then + if reason.object:get_player_name() ~= name then + was_killed[name] = true + minetest.after(30, function() + was_killed[name] = nil + end) + end + end + if player and send_tip == true and not tip_sent[name] then + minetest.chat_send_player(name, minetest.colorize("#60e645", "You died. You can return back to your last death position by using /death_pos command")) + tip_sent[name] = true + minetest.after(10, function() + tip_sent[name] = nil + end) + end +end) + +minetest.register_chatcommand("death_pos", { + description = "Go to your last death position", + privs = {interact = true}, + func = function(name) + local player = minetest.get_player_by_name(name) + local pos = death_pos[name] + local clear_pos = minetest.settings:get("death_pos.clear_pos") or true -- Clears the death position when 'death_pos' command is used (if true) + if was_killed[name] then + return false, "You were killed by a player, you cannot teleport to your death position right now" + end + if pos then + player:set_pos(pos) + if clear_pos == true then + death_pos[name] = nil + end + return false, minetest.colorize("#60e645", "Teleported you back to your death position!") + else + return false, "You don't have a death position right now" + end + end +}) \ No newline at end of file diff --git a/mod.conf b/mod.conf new file mode 100644 index 0000000..b2bec48 --- /dev/null +++ b/mod.conf @@ -0,0 +1,5 @@ +name = death_pos +description = Adds a command to return back to position where you died +release = 9430 +title = Death Position +author = BlueR23