Skip to content

Commit

Permalink
Spawn mod: Also reposition players on respawn
Browse files Browse the repository at this point in the history
To avoid respawn position being possibly very distant from new player
spawn position.
  • Loading branch information
paramat committed Jun 7, 2018
1 parent bcf76ea commit abe1b9f
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions mods/spawn/init.lua
Expand Up @@ -106,19 +106,28 @@ local function search()
end


-- On new player spawn
-- On new player spawn and player respawn

-- Search for new player spawn once per server session. If successful, store
-- position and reposition new players, otherwise leave them at engine spawn
-- Search for spawn position once per server session. If successful, store
-- position and reposition players, otherwise leave them at engine spawn
-- position.

minetest.register_on_newplayer(function(player)
local function on_spawn(player)
if not searched then
success = search()
searched = true
end

if success then
player:setpos(spawn_pos)
player:set_pos(spawn_pos)
end
end

minetest.register_on_newplayer(function(player)
on_spawn(player)
end)

minetest.register_on_respawnplayer(function(player)
on_spawn(player)

return true
end)

0 comments on commit abe1b9f

Please sign in to comment.