fix reconcile
This commit is contained in:
parent
9ea24ce8ce
commit
9143edb1aa
@ -38,16 +38,16 @@ minetest.register_chatcommand("spawn", {
|
||||
params = "[ add <player> | visit <player> | kick <player> | guests | hosts ]",
|
||||
privs = "spawn",
|
||||
func = function(playername, args)
|
||||
local target = rspawn.playerspawns[name]
|
||||
local target = rspawn.playerspawns[playername]
|
||||
local args = args:split(" ")
|
||||
|
||||
if #args == 0 then
|
||||
if target then
|
||||
minetest.get_player_by_name(name):setpos(target)
|
||||
minetest.get_player_by_name(playername):setpos(target)
|
||||
return
|
||||
|
||||
else
|
||||
minetest.chat_send_player(name, "You have no spawn position!")
|
||||
minetest.chat_send_player(playername, "You have no spawn position!")
|
||||
return
|
||||
end
|
||||
elseif #args < 3 then
|
||||
@ -70,7 +70,7 @@ minetest.register_chatcommand("spawn", {
|
||||
end
|
||||
end
|
||||
|
||||
minetest.chat_send_player(name, "Please check '/help spawn'")
|
||||
minetest.chat_send_player(playername, "Please check '/help spawn'")
|
||||
end
|
||||
})
|
||||
|
||||
|
17
lua/data.lua
17
lua/data.lua
@ -27,23 +27,26 @@ end
|
||||
|
||||
local function reconcile_guest(guestname, guestspawn)
|
||||
for hostname,hostspawn in pairs(rspawn.playerspawns) do
|
||||
if hostspawn == guestspawn then
|
||||
if hostname ~= "guest lists" and hostname ~= guestname and hostspawn == guestspawn then
|
||||
local hostlist = rspawn.playerspawns["guest lists"][hostname] or {}
|
||||
hostlist[guestname] = 1
|
||||
rspawn.playerspawns["guest lists"][hostname] = hostlist
|
||||
|
||||
rspawn.playerspawns["original spawns"][guestname] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function reconcile_guestlist_spawns()
|
||||
local original_spawns = rspawn.playerspawns["original spawns"]
|
||||
if not original_spawns then return
|
||||
if not rspawn.playerspawns["guest lists"] then rspawn.playerspawns["guest lists"] = {} end
|
||||
|
||||
for guestname,spawnpos in pairs(original_spawns) do
|
||||
for guestname,spawnpos in pairs(rspawn.playerspawns) do
|
||||
reconcile_guest(guestname, spawnpos)
|
||||
rspawn.playerspawns[guestname] = spawnpos
|
||||
|
||||
if rspawn.playerspawns["original spawns"][guestname] then
|
||||
rspawn.playerspawns[guestname] = rspawn.playerspawns["original spawns"][guestname]
|
||||
rspawn.playerspawns["original spawns"][guestname] = nil
|
||||
else
|
||||
minetest.debug("Could not return "..guestname)
|
||||
end
|
||||
end
|
||||
|
||||
if #rspawn.playerspawns["original spawns"] == 0 then
|
||||
|
@ -20,6 +20,8 @@ minetest.after(0,function()
|
||||
end)
|
||||
|
||||
local function canvisit(hostname, guestname)
|
||||
minetest.debug(dump(rspawn.playerspawns["guest lists"]))
|
||||
|
||||
local glist = rspawn.playerspawns["guest lists"][hostname] or {}
|
||||
return glist[guestname] == 1
|
||||
end
|
||||
@ -139,7 +141,7 @@ function rspawn.invites:kick(hostname, guestname)
|
||||
local hostspawnpos = rspawn.playerspawns[hostname]
|
||||
local guestspawnpos = rspawn.playerspawns[guestname]
|
||||
|
||||
if vector.distance(guestpos, hostspawnpos) then
|
||||
if vector.distance(guestpos, hostspawnpos) < 32 then
|
||||
guest:setpos(guestspawnpos)
|
||||
end
|
||||
end
|
||||
@ -149,7 +151,7 @@ function rspawn.invites:listguests(hostname)
|
||||
local guestlist = rspawn.playerspawns["guest lists"][hostname] or {}
|
||||
|
||||
for guestname,status in pairs(guestlist) do
|
||||
if status == 1 then status = "" else status = " (exiled)"
|
||||
if status == 1 then status = "" else status = " (exiled)" end
|
||||
|
||||
guests = ", "..guestname..status
|
||||
end
|
||||
@ -163,7 +165,7 @@ function rspawn.invites:listhosts(guestname)
|
||||
for _,hostname in ipairs(rspawn.playerspawns["guest lists"]) do
|
||||
for gname,status in pairs(rspawn.playerspawns["guest lists"][hostname]) do
|
||||
if guestname == gname then
|
||||
if status == 1 then status = "" else status = " (exiled)"
|
||||
if status == 1 then status = "" else status = " (exiled)" end
|
||||
|
||||
hosts = ", "..hostname..status
|
||||
end
|
||||
@ -177,10 +179,14 @@ function rspawn.invites:visitplayer(hostname, guestname)
|
||||
local guest = minetest.get_player_by_name(guestname)
|
||||
local hostpos = rspawn.playerspawns[hostname]
|
||||
|
||||
if guest and hostpos and canvisit(hostname, guestname) then
|
||||
guest:setpos(hostpos)
|
||||
else
|
||||
if not hostpos then
|
||||
minetest.log("error", "[rspawn] Missing spawn position data for "..hostname)
|
||||
minetest.chat_send_player(guestname, "Could not find spawn position for "..hostname)
|
||||
end
|
||||
|
||||
if guest and canvisit(hostname, guestname) then
|
||||
guest:setpos(hostpos)
|
||||
else
|
||||
minetest.chat_send_player(guestname, "Could not visit"..hostname)
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user