random select player? -
3417512908 - 19.10.2018
somebody know how to do it?
if we just use random(sizeof(MAX_PLAYERS)) and player is not connect,it will loop don't get stop,and server will "freeze" lol
Re: random select player? -
GangstaSunny. - 19.10.2018
Quote:
Originally Posted by ******
Iter_Random(Player);
|
No need for include.
PHP код:
random(GetPlayerPoolSize());
Re: random select player? -
Threshold - 19.10.2018
Quote:
Originally Posted by GangstaSunny.
No need for include.
PHP код:
random(GetPlayerPoolSize());
|
You didn't read the original post... did you...?
Obviously ******' suggestion is the most ethical solution.
The only way to make something equal in operation but not in efficiency is to create an array that stores current player IDs and loop through that instead.
Re: random select player? -
GangstaSunny. - 19.10.2018
Quote:
Originally Posted by Threshold
You didn't read the original post... did you...?
Obviously ******' suggestion is the most ethical solution.
The only way to make something equal in operation but not in efficiency is to create an array that stores current player IDs and loop through that instead.
|
I misunderstood, need to sorry for this.
PHP код:
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(!IsPlayerConnected(i))continue;
//if connected "return 1;" or "break;" here
}
Would still be a non-include solution.
Re: random select player? -
jasperschellekens - 19.10.2018
Quote:
Originally Posted by 3417512908
somebody know how to do it?
if we just use random(sizeof(MAX_PLAYERS)) and player is not connect,it will loop don't get stop,and server will "freeze" lol
|
Did u even use IsPlayerConnected?
Re: random select player? -
g1venchy - 19.10.2018
PHP код:
RandomPlayerID(){
new ValidPlayers[MAX_PLAYERS],cnt;
for(new i,i2=GetPlayerPoolSize(); i < i2; i++)if(IsPlayerConnected(i))ValidPlayers[cnt++]=i;
return cnt==0?-1:ValidPlayers[random(cnt)];
}
Re: random select player? -
GangstaSunny. - 19.10.2018
Quote:
Originally Posted by g1venchy
PHP код:
RandomPlayerID(){
new ValidPlayers[MAX_PLAYERS],cnt;
for(new i,i2=GetPlayerPoolSize(); i < i2; i++)if(IsPlayerConnected(i))ValidPlayers[cnt++]=i;
return cnt==0?-1:ValidPlayers[random(cnt)];
}
|
Made the same mistake.
GetPlayerPoolSize returns the amount of connected players. For example: 10.
If someone got the ID 11 cause he logged in after ID 10, but ID 10 has been disconnected, he won't be a part of the loop.
Re: random select player? -
g1venchy - 19.10.2018
but this codes performance isn't even so bad
and i wrote this code on my own
and GetPlayerPoolSize returns higest player id
Re: random select player? -
GangstaSunny. - 19.10.2018
Quote:
Originally Posted by g1venchy
but this codes performance isn't even so bad
and i wrote this code on my own
and GetPlayerPoolSize returns higest player id
|
This code is more unperformed as a Renault twingo.
Re: random select player? -
GTLS - 21.10.2018
Quote:
Originally Posted by g1venchy
GetPlayerPoolSize returns higest player id
|
What if there are ID 0-10 connected and then ID 30. ID between 11 and 30 are empty. Loop will run 30 times when it should only run 12 times.