Making this into - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Making this into (
/showthread.php?tid=267338)
Making this into -
Kitten - 08.07.2011
Solved
Re: Making this into -
leong124 - 08.07.2011
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;
}
Re: Making this into -
Donya - 08.07.2011
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: