add respawn on death

This commit is contained in:
Tai @ Flex 2017-01-13 23:16:29 +00:00
parent 316b8a8253
commit a8b6568cbb
2 changed files with 14 additions and 4 deletions

View File

@ -2,7 +2,7 @@
A spawn command for Minetest without needing a fixed point A spawn command for Minetest without needing a fixed point
If no static spawning point is defined, each player is given a spawn location somewhere near 0,0,0. If no `static_spawnpoint` is defined in `minetest.conf`, each player is given a spawn location somewhere near 0,0,0.
If static spawn point is defined, that point is used as origin instead. If static spawn point is defined, that point is used as origin instead.
@ -10,6 +10,10 @@ Players will not spawn in spaces that are protected by any other player than the
Players can request a new spawn point by typing `/newspawn` if they have the `newspawn` privilege. Players can request a new spawn point by typing `/newspawn` if they have the `newspawn` privilege.
Player will respawn at ths spawnpoint if they die.
TODO - integrate with beds API to allow bed to override the spawn.
## License ## License
(C) 2017 Tai "DuCake" Kedzierski (C) 2017 Tai "DuCake" Kedzierski

View File

@ -26,11 +26,10 @@ local function newspawn(radius)
if not radius then if not radius then
radius = 32 radius = 32
end end
if radius > 200 then if radius > 256 then
minetest.debug("No valid spawnable location") minetest.log("error", "No valid spawnable location")
return return
end end
minetest.debug("Re-spawn: Trying radius "..tostring(radius))
local pos1 = {x=origin.x-radius, y=origin.y, z=origin.z-radius} local pos1 = {x=origin.x-radius, y=origin.y, z=origin.z-radius}
local pos2 = {x=origin.x+radius, y=origin.y+(radius/2), z=origin.z+radius} local pos2 = {x=origin.x+radius, y=origin.y+(radius/2), z=origin.z+radius}
@ -51,6 +50,7 @@ local function newspawn(radius)
end end
if #validnodes > 0 then if #validnodes > 0 then
minetest.log("info", "New spawn point found with radius "..tostring(radius))
return validnodes[math.random(1,#validnodes)] return validnodes[math.random(1,#validnodes)]
end end
@ -119,3 +119,9 @@ minetest.register_on_joinplayer(function(player)
end end
end) end)
end) end)
minetest.register_on_respawnplayer(function(player)
local name = player:get_player_name()
player:setpos(playerspawns[name])
return true
end)