Bonus player script.. it this correct?
#1

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
Reply
#2

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)