[HELP] How to check server empty?
#1

How to check empty servers by loop?

https://pastebin.com/T7gqBfUJ
Reply
#2

If you are using y_iterate you can use Iter_Count(Player) to get number of online players and check if it is zero
Reply
#3

or if you dontwant to use iterators you can just create a global variable like below.

Код:
new myonlineplayers=0;
Then under OnPlayerConnect:

Код:
myonlineplayers++;
Then ofcourse OnPlayerDisconnect:

Код:
myonlineplayers--;
After that you just need a command that will tell you the number that your variable holds.

If you really want to use a loop you can create an array* variable for max players and when they disconnect you can turn it to 0 and ofcourse on login you can do switching it to 1. so your loop would be like:

Код:
new mycount=0;
for(new i=0; i<MAX_PLAYERS; i++)
{
    if(myonlineplayers[i]==1)
    {
        mycount++;
    }  
}
Then you can print that mycount variable to your screen if you want or do whatever you need with it. But it would be the same thing as using iterators because thats basically an iterator.

Edit: fixed wrong spelled word.
Reply
#4

Quote:
Код:
new mycount=0;
for(new i=0; i<MAX_PLAYERS; i++)
{
    if(myonlineplayers[i]==1)
    {
        mycount++;
    }  
}
Wut? In your example myonlineplayers keep the connected players already, why did you make this loop? Its useless and it have an error already, myonlineplayers its not an array and definetly its not a per player array.
Reply
#5

Quote:
Originally Posted by Banditul18
Посмотреть сообщение
Wut? In your example myonlineplayers keep the connected players already, why did you make this loop? Its useless and it have an error already, myonlineplayers its not an array and definetly its not a per player array.
i told him to change it to an array there. i didnt specify with my coding. i turned it in to a loop because check what he asked. HE WANTED A LOOP. So i gave him a loop if he changes it in to an array. the first one i do keeps the online count. the loop with array keeps which ids are online, which is what he asks and what he gave example of in pastebin. Is it really that hard to see it there?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)