Bonus player script.. it this correct? - 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)
+--- Thread: Bonus player script.. it this correct? (
/showthread.php?tid=451978)
Bonus player script.. it this correct? -
Anak - 19.07.2013
Hello basically i want to create a system i which random bonus player is selected, when some one kills that bonus player then killer get reward.. here i have created so far it this correct?
pawn Код:
//
stock SelectRandomPlayer()
{
   new random = Random(MAX_PLAYERS);
   if(IsPlayerConnected(random))
   {
      return random;
   }
   else
   {
      SelectRandomPlayer();
   }
}
//
// under OnFilterScriptInit
SetTimer("BonusPlayer", 60*1000);
//
forward BonusPlayer();
public BonusPlayer()
{
new randomplayer = SelectRandomPlayer();
new str[100];
new pname;
GetPlayerName(randomplayer, pname, sizeof(pname));
format(str, sizeof(str),"* %s (%d) Has Been Selected As Bonus Player.", pname, randomplayer);
SendClientMessageToAll(COLOR_WHITE, str);
}
//
// under OnPlayerDeath
    if(randomplayer == playerid)
  {
  new str1[100];
  new pname, kname;
  GetPlayerName(playerid, pname, sizeof(pname));
  GetPlayerName(killerid, kname, sizeof(pname));
  format(str1, sizeof(str1),"* %s (%d) Has Killed Bonus Player %s (%d)."kname, killerid, pname, playerid);
    SendClientMessageToAll(COLOR_SKYBLUE, str1);
  }
Thanks, if this is wrong please correct it
Re: Bonus player script.. it this correct? -
Misiur - 19.07.2013
pawn Код:
stock SelectRandomPlayer()
{
   new random = Random(MAX_PLAYERS);
   if(IsPlayerConnected(random))
   {
      return random;
   }
   else
   {
      return SelectRandomPlayer();
   }
}
You have to return the function value (in recursive manner). If you use foreach there is Iter_Random function