How to count players with a particular tag

Place to get help with not working mods / modding interface.
User avatar
WIZ4
Fast Inserter
Fast Inserter
Posts: 209
Joined: Thu Apr 07, 2016 1:36 pm
Contact:

How to count players with a particular tag

Post by WIZ4 »

This command print that tag = nil

Code: Select all

/c game.print(#game.players.tag['[Tag]'])
Screenshot_7.png
Screenshot_7.png (114.92 KiB) Viewed 1673 times
My native language is russian. Sorry if my messages are difficult to read.
posila
Former Staff
Former Staff
Posts: 5448
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: How to count players with a particular tag

Post by posila »

game.players is array of players, it doesn't contain "tag" unless there is a player named "tag".
User avatar
WIZ4
Fast Inserter
Fast Inserter
Posts: 209
Joined: Thu Apr 07, 2016 1:36 pm
Contact:

Re: How to count players with a particular tag

Post by WIZ4 »

Oh, okay
My native language is russian. Sorry if my messages are difficult to read.
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: How to count players with a particular tag

Post by eradicator »

Code: Select all

local count = 0
for _,player in pair(game.players) do
  if player.tag == 'whatever' then
    count = count +1
    end
  end
game.print(count)
(untested)
User avatar
WIZ4
Fast Inserter
Fast Inserter
Posts: 209
Joined: Thu Apr 07, 2016 1:36 pm
Contact:

Re: How to count players with a particular tag

Post by WIZ4 »

eradicator wrote:

Code: Select all

local count = 0
for _,player in pair(game.players) do
  if player.tag == 'whatever' then
    count = count +1
    end
  end
game.print(count)
(untested)
Yes it works fine, thanks!
My native language is russian. Sorry if my messages are difficult to read.
Post Reply

Return to “Modding help”