[HELP] Random ID
#1

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
Reply
#2

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

Can't you just use that?
Reply
#3

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

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

I don't really understand what you need help with
Reply
#5

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

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;

Reply
#7

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.
Reply
#8

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.
Reply
#9

Get foreach. Use Iter_Random().
Reply
#10

EDIT: sry, deleted.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)