Add /killme chat command
authorrubenwardy <rubenwardy@gmail.com>
Mon, 2 Jan 2017 15:44:15 +0000 (15:44 +0000)
committerparamat <mat.gregory@virginmedia.com>
Sat, 7 Jan 2017 22:01:19 +0000 (22:01 +0000)
Added as a new mod as it doesn't fit anywhere else.

This is a game play change, so it better suited to
Minetest Game rather than builtin

Fixes #857

mods/killme/init.lua [new file with mode: 0644]

diff --git a/mods/killme/init.lua b/mods/killme/init.lua
new file mode 100644 (file)
index 0000000..06aa39d
--- /dev/null
@@ -0,0 +1,24 @@
+minetest.register_chatcommand("killme", {
+       description = "Kill yourself to respawn",
+       func = function(name)
+               local player = minetest.get_player_by_name(name)
+               if player then
+                       if minetest.setting_getbool("enable_damage") then
+                               player:set_hp(0)
+                               return true
+                       else
+                               for _, callback in pairs(core.registered_on_respawnplayers) do
+                                       if callback(player) then
+                                               return true
+                                       end
+                               end
+
+                               -- There doesn't seem to be a way to get a default spawn pos from the lua API
+                               return false, "No static_spawnpoint defined"
+                       end
+               else
+                       -- Show error message if used when not logged in, eg: from IRC mod
+                       return false, "You need to be online to be killed!"
+               end
+       end
+})