SA-MP Forums Archive
Lotto - Random Player ID - Help! - 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: Lotto - Random Player ID - Help! (/showthread.php?tid=85545)



Lotto - Random Player ID - Help! - bpeterson - 08.07.2009

Hello Everyone!

I have this code:
pawn Код:
public lotto()
{
new rand;
rand = random(GetMaxPlayers());
if(IsPlayerConnected(rand)) goto nyertes;
if(!IsPlayerConnected(rand)) goto nincsnyertes;
for (new i = 0; i < MAX_PLAYERS; i++)
{
//===
nyertes:
new string[256];
new WinnerID;
new WinnerName[MAX_PLAYER_NAME];
WinnerID = i;
GetPlayerName(i, WinnerName, sizeof(WinnerName));
format(string,sizeof(string),"%s (%i) Has Won The Lottery! Jackpot: $%i . Congratulations!",WinnerName,WinnerID,jackpot);
SendClientMessageToAll(COLOR_GREEN,string);
new string3[256];
format(string3,sizeof(string3),"~w~won the ~g~lottery~w~!~n~~g~$%i",jackpot);
GameTextForPlayer(i,string3,4000,3);
GivePlayerMoney(i, jackpot);
oscore = GetPlayerScore(i);
SetPlayerScore(i, oscore +5);
ResetJackpot();
//===
nincsnyertes:
new string2[256];
format(string2,sizeof(string2),"Nobody Has Won The Lottery Today! Jackpot: $%i .",jackpot);
SendClientMessageToAll(COLOR_GREEN,string2);
//===
}
return 1;
}
Something wrong with it, because it isn't selects only 1 player. Whats wrong with it? Please Help me!


Re: Lotto - Random Player ID - Help! - bpeterson - 08.07.2009

Please i really need help...


Re: Lotto - Random Player ID - Help! - Nero_3D - 08.07.2009

You put the code in a loop and what happans if you put something is a loop, yes it gets called x times while a variable is changing
You just need to remove the loop and replace each "i" with "rand" and maybe get a better way to get the random player because this way doesnt include all players


Re: Lotto - Random Player ID - Help! - bpeterson - 08.07.2009

Quote:
Originally Posted by ♣ ⓐⓢⓢ
You put the code in a loop and what happans if you put something is a loop, yes it gets called x times while a variable is changing
You just need to remove the loop and replace each "i" with "rand" and maybe get a better way to get the random player because this way doesnt include all players
I love you! Thanks! :P