SA-MP Forums Archive
[HELP] Random ID - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: [HELP] Random ID (/showthread.php?tid=603501)



[HELP] Random ID - MRM - 24.03.2016

Hi guys.
I want convert the following code to random ID.
And is not the ID of 0 to 10.
Код:
stock GetPlayersInTeam(TEAM)
{
    new players;
    for (new i; i < MAX_PLAYERS; i++)
    {
        if (IsPlayerConnected(i))
        {
            if (gTeam[i] == TEAM) players++;
        }
    }
    return players;
}
Thanks


Re: [HELP] Random ID - Golden96 - 24.03.2016

https://sampwiki.blast.hk/wiki/Random

Can't you just use that?


Re: [HELP] Random ID - MRM - 24.03.2016

Quote:
Originally Posted by Golden96
Посмотреть сообщение
https://sampwiki.blast.hk/wiki/Random

Can't you just use that?
no. You can?
So help me master!


Re: [HELP] Random ID - Golden96 - 24.03.2016

I don't really understand what you need help with


Re: [HELP] Random ID - MRM - 24.03.2016

I just need make a script that will get a random playerid from connected players.


Re: [HELP] Random ID - Nero_3D - 24.03.2016

PHP код:
GetRandomPlayerInTeam(teamid) {
    new
        
count,
        
player[MAX_PLAYERS],
        
GetPlayerPoolSize()
    ;
    while(
>= 0) { // set gTeam to an invalid value in OnPlayerDisconnect to
        
if(gTeam[i] == teamid) { // avoid the additional call to IsPlayerConnected
            
player[count++] = i;
        }
        
i--;
    }
    return 
count player[random(count)] : INVALID_PLAYER_ID;




Re: [HELP] Random ID - SickAttack - 24.03.2016

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
PHP код:
GetRandomPlayerInTeam(teamid) {
    new
        
count,
        
player[MAX_PLAYERS],
        
GetPlayerPoolSize()
    ;
    while(
>= 0) { // set gTeam to an invalid value in OnPlayerDisconnect to
        
if(gTeam[i] == teamid) { // avoid the additional call to IsPlayerConnected
            
player[count++] = i;
        }
        
i--;
    }
    return 
count player[random(count)] : INVALID_PLAYER_ID;

If he doesn't set "gTeam[playerid]" to an unused/invalid value when a player disconnects, then he's going to have problems with that code. He's probably better off with the "IsPlayerConnected" condition placed in the function.


Re: [HELP] Random ID - MRM - 24.03.2016

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
PHP код:
GetRandomPlayerInTeam(teamid) {
    new
        
count,
        
player[MAX_PLAYERS],
        
GetPlayerPoolSize()
    ;
    while(
>= 0) { // set gTeam to an invalid value in OnPlayerDisconnect to
        
if(gTeam[i] == teamid) { // avoid the additional call to IsPlayerConnected
            
player[count++] = i;
        }
        
i--;
    }
    return 
count player[random(count)] : INVALID_PLAYER_ID;

I just want to Player ID.
Not for the team.


Re: [HELP] Random ID - Vince - 24.03.2016

Get foreach. Use Iter_Random().


Re: [HELP] Random ID - MRM - 24.03.2016

EDIT: sry, deleted.