Check the number of player in a team

Hi,i have a problem,how to check if in a team there are 3 player?
Example:This code when 3 people are police,print in console “UAH” else it does nothing

Familiarize yourself with the Garry’s Mod Wiki, searching for something you want is really easy.

team.NumPlayers

see above lol

How i make a if player on team_police = 3 then print uaa?

I think you might need some help dude

I mean;I’m in a gmod darkrp server,for one job i need 3 players on team police,and i want that when tre player be police i get notified in console

In a Think hook, loop through all players (there may be a more suitable hook for this) and check if number of police is enough, then print the message to whoever

GM:OnPlayerChangedTeam

how i put it on a code?

https://wiki.garrysmod.com/page/Hook_Library_Usage

and if i want that when 3 players become police i get notified?

Do yourself a favor and get the understanding of basic lua first.

Everytime someone joins police add it to a variable, or when they leave subtract 1.
If after adding one you can do a check if the variable is equal to 3.

Only use below code if you’re stuck, learning is the key to progress!

pretty sure this will work? Not too sure I’ve been stuck in with PHP and a lot of regret for doing so.

A couple of issues with what you send,
#v is for measuring the length of a string
Also, we don’t need to be calling a pairs because we can use a hook to check whenever someone joins a team

The link below may help with what you are working on.



local a = "what do you mean"
print( type( a ), #a )
local b = string.Explode( " ", a )
print( type( b ), #b )


hook.Add to the GM:OnPlayerChangedTeam event.

Now inside this hook:
We want to check if team.GetName(newTeam) returns “team_police” and team.NumPlayers(newTeam) returns 3 (or 2 i don’t know if it increases before or after this hook, never bothered testing).
If so, we print(“I’M TOO LAZY TO ACTUALLY LEARN LUA”)