Making this into
#1

Solved
Reply
#2

Quote:
Originally Posted by Kitten
Посмотреть сообщение
I made this code it should of picked 1 player only but it picks 3 or 6 random players which is complety wrong look at the code i can't seem to figure it out

pawn Код:
public StartInfection(playerid) {
    start:
    new Random = Iter_Random(Player), count = 0;
    if(Random == playerid && Iter_Count(Player) > 1) {
        count++;
        if(count > 1) return 1;
        goto start;
    }
    OnceOnly = 0;
    return 1;
}
First of all you shouldn't use goto.
Even you want to use it, the start label is put wrongly.
Also, if(count > 1) should be if(count >= 1) so that it can be returned if a player is chosen.
So if count must be 1 in this case, count is not needed.

pawn Код:
public StartInfection(playerid)
{
    if(Iter_Random(Player) == playerid && Iter_Count(Player) > 1) return 1;
    OnceOnly = 0;
    return 1;
}
Reply
#3

your not seeing entirely where that code is going.
and the goto is right. but i must say, count is positioned wrong.

pawn Код:
public StartInfection(playerid) {
    new count = 0;
    start:
    new Random = Iter_Random(Player);
    if(Random == playerid && Iter_Count(Player) > 1) {
        count++;
        if(count > 3)
        {
             //failed
             return 1;
        }
        goto start;
    }
    OnceOnly = 0;
    return 1;
}
your code won't give it a chance to select another player if random equals to you and there are more players online

this code selects a random player, if the player is you and more than 1 players are online, it skips it and checks again to try to get the other player. well basically count should be around what i put it, unless iter_random keeps selecting the same player 4 times? s:
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)