Answered Getting a random player from my team

Cxwh

Veteran
Messages
64
Reaction score
45
Points
793
Would this return a random player from my team who is not me?
Code:
function getRandPlayer()
{
    players = GetPlayers();
    rand = RandomIntRange(0, players.size)

    if(players[rand].team != self.team && players[rand].name != self.name && players[rand].info["type"] != "bot") //don't worry i defined "bot" so when it's a bot that players.info["type"] is bot
        continue;

    return players[rand];
}

or could I also just do it like this?

Code:
function getRandPlayer()
{
    foreach(player in self.team)
    {
        if(player.name != self.name && player.info["type"] != "bot")
            return player; //does this return end the function? if not i'll use endon and a notify
    }
}
 
S

SeriousHD-

Guest
Would this return a random player from my team who is not me?
Code:
function getRandPlayer()
{
    players = GetPlayers();
    rand = RandomIntRange(0, players.size)

    if(players[rand].team != self.team && players[rand].name != self.name && players[rand].info["type"] != "bot") //don't worry i defined "bot" so when it's a bot that players.info["type"] is bot
        continue;

    return players[rand];
}

or could I also just do it like this?

Code:
function getRandPlayer()
{
    foreach(player in self.team)
    {
        if(player.name != self.name && player.info["type"] != "bot")
            return player; //does this return end the function? if not i'll use endon and a notify
    }
}
Nope.
Here:

function GetRandomTeammate()
{
team = self.team
i = randomintrange(0,level.players.size);
while(level.players == self || level.players.team != team)
{
wait .01;
i = randomintrange(0,level.players.size);
}
return level.players;
}
 

iplaynothing

Veteran
Messages
83
Reaction score
39
Points
803
Nope.
Here:

function GetRandomTeammate()
{
team = self.team
i = randomintrange(0,level.players.size);
while(level.players == self || level.players.team != team)
{
wait .01;
i = randomintrange(0,level.players.size);
}
return level.players;
}
holy **** SeriousHD doing GSC HOLY HOLY HOLY HOLY HOLY crap
 

Cxwh

Veteran
Messages
64
Reaction score
45
Points
793
I'm a bit confused as to why this works, like shouldn't it be like this or am I wrong?
Code:
function GetRandomTeammate()
{
    team = self.team
    i = randomintrange(0, level.players.size);

    while(level.players[i] == self || level.players[i].team != team)
    {
        wait .01;
        i = randomintrange(0, level.players.size);
    }
    return level.players[i];
}
 
S

SeriousHD-

Guest
I'm a bit confused as to why this works, like shouldn't it be like this or am I wrong?
Code:
function GetRandomTeammate()
{
    team = self.team
    i = randomintrange(0, level.players.size);

    while(level.players[i] == self || level.players[i].team != team)
    {
        wait .01;
        i = randomintrange(0, level.players.size);
    }
    return level.players[i];
}
I missed a ';' after self.team on the first line but yeah that works man.
Use like RandomPlayer = self GetRandomTeammate();
 
Top