Number of active players in game
Number of active players in game
Is there a way to show the number of active players in game? I'm using #game.players atm, but I've noticed that when a player leaves, he stays in the game.players table, so I can't see if the players in there are really ingame (not sure if this is a bug). Anyone got a workaround?
-
- Filter Inserter
- Posts: 402
- Joined: Fri May 23, 2014 8:54 am
- Contact:
Re: Number of active players in game
jeroon wrote:Is there a way to show the number of active players in game? I'm using #game.players atm, but I've noticed that when a player leaves, he stays in the game.players table, so I can't see if the players in there are really ingame (not sure if this is a bug). Anyone got a workaround?
Code: Select all
function getPlayerCount(players)
local playerCount = 0
for i,player in ipairs(players) do
if player.character ~= nil then
playerCount = playerCount + 1
end
end
return playerCount
end
Re: Number of active players in game
So i set up a MP game, player 2 joins, player 2 quits, and i run this in player 1's console:
And it prints nothing, so the table game.players still holds the character of players that have quit.
Code: Select all
/c if game.players[2].character == nil then
game.players[1].print("i'm not here")
end
Re: Number of active players in game
Maybe you can use somethingelse from here:
https://forums.factorio.com/wiki/inde ... Lua/Player
https://forums.factorio.com/wiki/inde ... Lua/Player