Record original spawns

* Record players original spawns so they can be restored after they accept an invite
* Allow admins to reset players' original spawns
master
Tai Kedzierski 2019-01-02 18:46:51 +00:00
parent f64c2a5481
commit ee2de274b7
3 changed files with 45 additions and 6 deletions

View File

@ -134,13 +134,24 @@ function rspawn:set_player_spawn(name, newpos)
end)
end
local function register_original_spawn(playername, pos)
-- We say players cannot find their original spawn after invite
-- That is the intended behaviour ; however we should still record this. Just in case.
if not rspawn.playerspawns["original spawns"] then
rspawn.playerspawns["original spawns"] = {}
end
rspawn.playerspawns["original spawns"][playername] = pos
end
function rspawn:set_newplayer_spawn(player)
-- only use for new players / players who have never had a randomized spawn
local playername = player:get_player_name()
if not rspawn.playerspawns[playername] then
local newpos = rspawn:get_next_spawn()
if newpos then
register_original_spawn(playername, newpos)
rspawn:set_player_spawn(playername, newpos)
else
@ -152,7 +163,7 @@ function rspawn:set_newplayer_spawn(player)
else
minetest.chat_send_player(playername, "Could not get custom spawn! Retrying in "..rspawn.gen_frequency.." seconds")
minetest.after(rspawn.gen_frequency+2, function()
minetest.after(rspawn.gen_frequency, function()
rspawn:set_newplayer_spawn(player)
end)
end

View File

@ -110,11 +110,39 @@ minetest.register_chatcommand("newspawn", {
})
minetest.register_chatcommand("playerspawn", {
description = "Randomly select a new spawn position for a player.",
params = "playername",
description = "Randomly select a new spawn position for a player, or use specified position, 'original' for their original spawn.",
params = "<playername> [<pos> | original]",
privs = "spawnadmin",
func = function(adminname, playername)
request_new_spawn(adminname, playername)
func = function(name, args)
if args ~= "" then
args = splitstring(args, " ")
if #args == 2 then
local tname = args[1]
local tpos
if args[2] == "original" then
tpos = rspawn.playerspawns["original spawns"][tname]
if not tpos then
minetest.chat_send_player( name, "Could not find original spawn for "..tname)
minetest.chat_send_player(tname, "Could not find original spawn for "..tname)
return
end
else
tpos = minetest.string_to_pos(args[2])
end
if tpos then
rspawn:set_player_spawn(tname, tpos)
return
end
elseif #args == 1 then
request_new_spawn(name, args[1])
return
end
end
minetest.chat_send_player(name, "Error. See '/help playerspawn'")
end
})

View File

@ -60,7 +60,7 @@ function rspawn.invites:invite_player_fromto(hostname, guestname)
local hostspawn_s = minetest.pos_to_string(rspawn.playerspawns[hostname])
minetest.chat_send_player(guestname, hostname.." invited you to join their spawn point.\nIf you accept, your spawn point will be set to "..hostspawn_s.." and you will be taken there immediately.\n This cannot be undone.\n\nRun '/spawn accept' to accept, '/spawn decline' to decline and clear the invite.")
minetest.chat_send_player(guestname, hostname.." invited you to join their spawn point.\nIf you accept, your spawn point will be set to "..hostspawn_s.." and you will be taken there immediately.\n WARNING: This CANNOT BE UNDONE.\n\nRun '/spawn accept' to accept, '/spawn decline' to decline and clear the invite.")
minetest.chat_send_player(hostname,
"You have invited "..guestname.." to join your spawn.\nIf they accept, you will be charged \n\n "..levvy_qtty.." "..levvy_nicename.." \n\nwhich will be taken from your inventory."