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