Number of active players in game

Place to get help with not working mods / modding interface.
Post Reply
jeroon
Filter Inserter
Filter Inserter
Posts: 351
Joined: Sun Jan 26, 2014 10:18 am
Contact:

Number of active players in game

Post by jeroon »

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?

JamesOFarrell
Filter Inserter
Filter Inserter
Posts: 402
Joined: Fri May 23, 2014 8:54 am
Contact:

Re: Number of active players in game

Post by JamesOFarrell »

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

jeroon
Filter Inserter
Filter Inserter
Posts: 351
Joined: Sun Jan 26, 2014 10:18 am
Contact:

Re: Number of active players in game

Post by jeroon »

So i set up a MP game, player 2 joins, player 2 quits, and i run this in player 1's console:

Code: Select all

/c if game.players[2].character == nil then 
    game.players[1].print("i'm not here")
end
And it prints nothing, so the table game.players still holds the character of players that have quit.

drs9999
Filter Inserter
Filter Inserter
Posts: 831
Joined: Wed Mar 06, 2013 11:16 pm
Contact:

Re: Number of active players in game

Post by drs9999 »

Maybe you can use somethingelse from here:
https://forums.factorio.com/wiki/inde ... Lua/Player

Post Reply

Return to “Modding help”