Overkillz Posted March 8, 2018 Share Posted March 8, 2018 Hey dear community, today Im having a little issue when the player leave the server. Well, Im currently updating the players in a table when they join the arena, leave and quit. Well, the issue is when the arena is empty, I want to set a status but it doesn't work setRaceState function only changes the value of a variable, but it doesn't work. When I join and check the variable value with a different custom function it drops me the old one and not "none" as it should be due to the arenaPlayers table is 0. I don't know if you have gotten me at all, but I hope you can bring me a tip to fix it. function updatePlayersInArena() arenaPlayers = {} local players = getElementsByType("player") for i,player in ipairs(players) do if getElementData(player,"arenaTag") then table.insert(arenaPlayers,player) end end if #arenaPlayers <= 0 then outputChatBox("Arena is empty, setting default state") setRaceState("none") end end addEventHandler( "onPlayerQuit", getRootElement(), updatePlayersInArena) Best regards. Link to comment
DNL291 Posted March 9, 2018 Share Posted March 9, 2018 From what I understood, if a player is on the arena and he quits the server, his element-data "arenaTag" will still be active until the whole function is executed, and in this case, arenaPlayers wouldn't return 0 players. Although, I'm not sure if getElementsByType function inside "onPlayerQuit" event includes the player who left the server. Link to comment
ZL|LuCaS Posted March 9, 2018 Share Posted March 9, 2018 (edited) You're doing everything wrong, my friend. if #arenaPlayers <= 0 then outputChatBox("Arena is empty, setting default state") setRaceState("none") end will never be zero if #arenaPlayers <= 0 then table.insert(arenaPlayers,player) You are adding the player to the table so it will not return zero. Edited March 9, 2018 by ZL|LuCaS Link to comment
Overkillz Posted March 9, 2018 Author Share Posted March 9, 2018 2 hours ago, DNL291 said: From what I understood, if a player is on the arena and he quits the server, his element-data "arenaTag" will still be active until the whole function is executed, and in this case, arenaPlayers wouldn't return 0 players. Although, I'm not sure if getElementsByType function inside "onPlayerQuit" event includes the player who left the server. Thats exactly what I mean. However, i think that Im going to change the way of adding players to if not arenaPlayer [thePlayer] then arenaPlayer [thePlayer] = true end And when the player stay in the arena and leaves the server arenaPlayer [thePlayer] = nil If you know another way which is similar to the first one commented, just leave an answer. 2 hours ago, ZL|LuCaS said: You're doing everything wrong, my friend. if #arenaPlayers <= 0 then outputChatBox("Arena is empty, setting default state") setRaceState("none") end will never be zero if #arenaPlayers <= 0 then table.insert(arenaPlayers,player) You are adding the player to the table so it will not return zero. Im not adding any player because the function shouldnt add any player if there is not anyone on the server. And the table.insert is before the check players in table condition. Thanls and regards. Link to comment
MisterQuestions Posted March 9, 2018 Share Posted March 9, 2018 "arenaTag" is always the same? Is it a bool? Link to comment
ZL|LuCaS Posted March 9, 2018 Share Posted March 9, 2018 Your English does not help but I guess you do not know what you're doing. local arenaPlayers = {} function updatePlayersInArena() --local players = getElementsByType("player") for id,player in ipairs(arenaPlayers) do if player == source then --if getElementData(player,"arenaTag") then table.remove(arenaPlayers,id) --end end end if #arenaPlayers <= 0 then outputChatBox("Arena is empty, setting default state") setRaceState("none") end end addEventHandler( "onPlayerQuit", getRootElement(), updatePlayersInArena) 1 Link to comment
Overkillz Posted March 10, 2018 Author Share Posted March 10, 2018 I won't do undo my old function due to It is managed by other scripts too so I tried to implement your's one with mine one. Sadly I didn't get the solution Look, it is still not working function updatePlayersInArena() arenaPlayers = {} local players = getElementsByType("player") for i,player in ipairs(players) do if getElementData(player,"arenaTag") then table.insert(arenaPlayers,player) end end if #arenaPlayers < 1 or not arenaPlayers then outputChatBox("Arena is empty, setting default state") setRaceState("none") end end function playerLeavingServer() for id,player in ipairs(arenaPlayers) do if player == source then table.remove(arenaPlayers,id) end end updatePlayersInArena() end addEventHandler( "onPlayerQuit", getRootElement(), playerLeavingServer) Link to comment
DNL291 Posted March 10, 2018 Share Posted March 10, 2018 (edited) Try setting 'false' to the player's element-data: function updatePlayersInArena() arenaPlayers = {} setElementData( source, "arenaTag", false ) local players = getElementsByType("player") for i,player in ipairs(players) do if getElementData(player,"arenaTag") then table.insert(arenaPlayers,player) end end if #arenaPlayers <= 0 then outputChatBox("Arena is empty, setting default state") setRaceState("none") end end addEventHandler( "onPlayerQuit", getRootElement(), updatePlayersInArena) Edited March 10, 2018 by DNL291 1 Link to comment
Overkillz Posted March 11, 2018 Author Share Posted March 11, 2018 22 hours ago, DNL291 said: Try setting 'false' to the player's element-data: Genious ! Link to comment
MisterQuestions Posted March 12, 2018 Share Posted March 12, 2018 Just wondering how will you check if its an specific arena that way Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now