Added emergency suicide command.
Kills the player over a short span of time. Any movement aborts the kill.
This commit is contained in:
parent
510e642a53
commit
c5e6641d39
@ -8,3 +8,4 @@ local path = minetest.get_modpath(modname)
|
||||
|
||||
dofile(path .. "/player.lua")
|
||||
dofile(path .. "/hotpotato.lua")
|
||||
dofile(path .. "/suicide.lua")
|
||||
|
42
mods/nc_player/suicide.lua
Normal file
42
mods/nc_player/suicide.lua
Normal file
@ -0,0 +1,42 @@
|
||||
-- LUALOCALS < ---------------------------------------------------------
|
||||
local minetest, nodecore, pairs, table
|
||||
= minetest, nodecore, pairs, table
|
||||
local table_concat
|
||||
= table.concat
|
||||
-- LUALOCALS > ---------------------------------------------------------
|
||||
|
||||
local suiciding = {}
|
||||
|
||||
local function pstate(player)
|
||||
local pos = player:getpos()
|
||||
local dir = player:get_look_dir()
|
||||
return table_concat({
|
||||
pos.x, pos.y, pos.z,
|
||||
dir.x, dir.y, dir.z
|
||||
}, "|")
|
||||
end
|
||||
|
||||
local function suicidecheck()
|
||||
minetest.after(0.5, suicidecheck)
|
||||
for pname, st in pairs(suiciding) do
|
||||
local player = minetest.get_player_by_name(pname)
|
||||
if player then
|
||||
local hp = player:get_hp()
|
||||
if (hp > 0) and (player:get_player_control_bits() == 0)
|
||||
and pstate(player) == st then
|
||||
nodecore.addphealth(player, -1)
|
||||
else
|
||||
suiciding[pname] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
suicidecheck()
|
||||
|
||||
minetest.register_chatcommand("suicide", {
|
||||
description = "Commit suicide (e.g. to respawn when stuck)",
|
||||
func = function(pname)
|
||||
local player = minetest.get_player_by_name(pname)
|
||||
if player then suiciding[pname] = pstate(player) end
|
||||
end,
|
||||
})
|
Loading…
x
Reference in New Issue
Block a user