Jump to content
Chris_37

counting players with variable

Recommended Posts

Hello wondering if anyone can help me?  i am trying to come up a way of counting all the players with a variable and if their is 5 players already with the variable the player will be prevented from joining?

Share this post


Link to post
Share on other sites

You could setVariable forEach  allPlayers, and cycle through getVariable forEach allPlayers each time your variable changes somewhere and do a count for when the variable is equal to whatever. A more efficient approach, depending on what you are accomplishing, could be to keep a script running on the server that manages a global array that adds/removes players from it as a means of "assigning variables". You may have to make it a publicVariable. Again, it just depends on what you are needing the data for. 

Share this post


Link to post
Share on other sites
1 hour ago, KC Grimes said:

You could setVariable forEach  allPlayers, and cycle through getVariable forEach allPlayers each time your variable changes somewhere and do a count for when the variable is equal to whatever. A more efficient approach, depending on what you are accomplishing, could be to keep a script running on the server that manages a global array that adds/removes players from it as a means of "assigning variables". You may have to make it a publicVariable. Again, it just depends on what you are needing the data for. 

How would i go about doing a gobal array that manages players depending of which variable they had? like in terms of adding/removing?

Share this post


Link to post
Share on other sites

Again it just depends on the circumstances surrounding the variable. Is the variable set locally based on a local action, or is it set on the server based on the server's detection of a condition? Does anybody but the server need to set or get the variables? To avoid public variables it would be ideal to have all of the tracking done on the server, but I get a feeling the clients will need to have access to the variable. Just do setVariable, have the public broadcast param set to true, loop through allPlayers counting the number, and do/don't do what you are wanting given that condition. 

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×