1
0
mirror of https://github.com/Oarcinae/FactorioScenarioMultiplayerSpawn.git synced 2024-12-14 10:23:17 +02:00

Trying to fix some issues with player being nil for certain GUI events.

This commit is contained in:
Oarcinae 2018-02-22 18:05:22 -05:00
parent 10814e30fa
commit 5ddb5b2dee

View File

@ -121,6 +121,11 @@ end
-- Display the spawn options and explanation -- Display the spawn options and explanation
function DisplaySpawnOptions(player) function DisplaySpawnOptions(player)
if (player == nil) then
DebugPrint("DisplaySpawnOptions with no valid player...")
return
end
if (player.gui.center.spawn_opts ~= nil) then if (player.gui.center.spawn_opts ~= nil) then
DebugPrint("Tried to display spawn options when it was already displayed!") DebugPrint("Tried to display spawn options when it was already displayed!")
return return
@ -791,9 +796,11 @@ function SpawnCtrlGuiClick(event)
player.print("You rejected " .. joinQueuePlayerChoice .. "'s request to join your base.") player.print("You rejected " .. joinQueuePlayerChoice .. "'s request to join your base.")
SendMsg(joinQueuePlayerChoice, "Your request to join was rejected.") SendMsg(joinQueuePlayerChoice, "Your request to join was rejected.")
-- Close the waiting players menu
game.players[joinQueuePlayerChoice].gui.center.join_shared_spawn_wait_menu.destroy() if (game.players[joinQueuePlayerChoice].gui.center.join_shared_spawn_wait_menu) then
DisplaySpawnOptions(game.players[joinQueuePlayerChoice]) game.players[joinQueuePlayerChoice].gui.center.join_shared_spawn_wait_menu.destroy()
DisplaySpawnOptions(game.players[joinQueuePlayerChoice])
end
-- Find and remove the player from the joinQueue they were in. -- Find and remove the player from the joinQueue they were in.
for index,requestingPlayer in pairs(global.sharedSpawns[player.name].joinQueue) do for index,requestingPlayer in pairs(global.sharedSpawns[player.name].joinQueue) do
@ -805,12 +812,6 @@ function SpawnCtrlGuiClick(event)
elseif (elemName == "accept_player_request") then elseif (elemName == "accept_player_request") then
-- Send an announcement
SendBroadcastMsg(joinQueuePlayerChoice .. " is joining " .. player.name .. "'s base!")
-- Close the waiting players menu
game.players[joinQueuePlayerChoice].gui.center.join_shared_spawn_wait_menu.destroy()
-- Find and remove the player from the joinQueue they were in. -- Find and remove the player from the joinQueue they were in.
for index,requestingPlayer in pairs(global.sharedSpawns[player.name].joinQueue) do for index,requestingPlayer in pairs(global.sharedSpawns[player.name].joinQueue) do
if (requestingPlayer == joinQueuePlayerChoice) then if (requestingPlayer == joinQueuePlayerChoice) then
@ -818,17 +819,30 @@ function SpawnCtrlGuiClick(event)
end end
end end
-- Spawn the player -- If player exists, then do stuff.
joiningPlayer = game.players[joinQueuePlayerChoice] if (game.players[joinQueuePlayerChoice]) then
ChangePlayerSpawn(joiningPlayer, global.sharedSpawns[player.name].position) -- Send an announcement
SendPlayerToSpawn(joiningPlayer) SendBroadcastMsg(joinQueuePlayerChoice .. " is joining " .. player.name .. "'s base!")
GivePlayerStarterItems(joiningPlayer)
table.insert(global.sharedSpawns[player.name].players, joiningPlayer.name) -- Close the waiting players menu
joiningPlayer.force = game.players[player.name].force if (game.players[joinQueuePlayerChoice].gui.center.join_shared_spawn_wait_menu) then
game.players[joinQueuePlayerChoice].gui.center.join_shared_spawn_wait_menu.destroy()
end
-- Spawn the player
joiningPlayer = game.players[joinQueuePlayerChoice]
ChangePlayerSpawn(joiningPlayer, global.sharedSpawns[player.name].position)
SendPlayerToSpawn(joiningPlayer)
GivePlayerStarterItems(joiningPlayer)
table.insert(global.sharedSpawns[player.name].players, joiningPlayer.name)
joiningPlayer.force = game.players[player.name].force
-- Create the button at the top left for setting respawn point and sharing base. -- Create the button at the top left for setting respawn point and sharing base.
CreateSpawnCtrlGui(joiningPlayer) CreateSpawnCtrlGui(joiningPlayer)
ExpandSpawnCtrlGui(player, event.tick) ExpandSpawnCtrlGui(player, event.tick)
else
SendBroadcastMsg(joinQueuePlayerChoice .. " left the game. What an ass.")
end
end end
end end
end end
@ -1029,7 +1043,9 @@ function BuddySpawnOptsGuiClick(event)
buddyIsStillWaiting = false buddyIsStillWaiting = false
for _,buddyName in pairs(global.waitingBuddies) do for _,buddyName in pairs(global.waitingBuddies) do
if (buddyChoice == buddyName) then if (buddyChoice == buddyName) then
buddyIsStillWaiting = true if (game.players[buddyChoice]) then
buddyIsStillWaiting = true
end
break break
end end
end end
@ -1143,7 +1159,12 @@ function BuddySpawnWaitMenuClick(event)
end end
function DisplayBuddySpawnRequestMenu(player, requestingBuddyName) function DisplayBuddySpawnRequestMenu(player, requestingBuddyName)
if not player then
DebugPrint("Another gui click happened with no valid player...")
return
end
player.gui.center.add{name = "buddy_request_menu", player.gui.center.add{name = "buddy_request_menu",
type = "frame", type = "frame",
direction = "vertical", direction = "vertical",