SA-MP Forums Archive
Bonus kill / player - 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 kill / player (/showthread.php?tid=444470)



Bonus kill / player - Ananisiki - 16.06.2013

^^^^^^^^


Re: Bonus kill / player - park4bmx - 17.06.2013

This is not help! Is a request !!

pawn Код:
stock RandomPlayer()
{
new count;
for(new i=0; i < MAX_PLAYERS; i++)
   {
         if(IsPlayerConnected(i)) Count++;
   }
new Result = Random(Count);
if(IsPlayerConnected(Result)) return Result;
else RandomPlayer();
}
this is a bad way to check it doe


Re: Bonus kill / player - Pottus - 17.06.2013

Quote:
Originally Posted by park4bmx
Посмотреть сообщение
This is not help! Is a request !!

pawn Код:
stock RandomPlayer()
{
new count;
for(new i=0; i < MAX_PLAYERS; i++)
   {
         if(IsPlayerConnected(i)) Count++;
   }
new Result = Random(Count);
if(IsPlayerConnected(Result)) return Result;
else RandomPlayer();
}
That is bad code dude completely senseless ass backwards logic.

1.) If no players are connected this will keep calling it's self.
2.) Why on Earth would you make this recursive?


MAX_PLAYER loop version
pawn Код:
stock RandomPlayer()
{
    new ConnectedPlayers[MAX_PLAYERS];
    new count;

    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            ConnectedPlayers[count] = i;
            count++;
        }
    }
    if(count > 0) return ConnectedPlayers[random(count)];
    return INVALID_PLAYER_ID;
}
Or foreach version if your using foreach instead
pawn Код:
stock RandomPlayer()
{
    new ConnectedPlayers[MAX_PLAYERS];
    new count;

    foreach(new i : Player)
    {
        ConnectedPlayers[count] = i;
        count++;
    }
    if(count > 0) return ConnectedPlayers[random(count)];
    return INVALID_PLAYER_ID;
}



Re: Bonus kill / player - Ananisiki - 17.06.2013

^^^^^^^^


Re: Bonus kill / player - Scenario - 17.06.2013

https://sampwiki.blast.hk/wiki/SendClientMessage

You should probably go and read these before you start scripting...

https://sampwiki.blast.hk/wiki/Scripting_Basics
https://sampwiki.blast.hk/wiki/Keywords:Initialisers
https://sampwiki.blast.hk/wiki/Keywords:Operators
https://sampwiki.blast.hk/wiki/Keywords:Statements


Re: Bonus kill / player - Ananisiki - 23.06.2013

^^^^^^^^


Re: Bonus kill / player - Goldilox - 23.06.2013

Like this maybe.

pawn Код:
stock RandomPlayer()
{
    new ConnectedPlayers[MAX_PLAYERS];
    new count;

    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            ConnectedPlayers[count] = i;
            count++;
            SendClientMessage(i,0xF80000,"You've been chosen as a bonus player.");

        }
    }
    if(count > 0) return ConnectedPlayers[random(count)];
    return INVALID_PLAYER_ID;
}



Re: Bonus kill / player - Ananisiki - 23.06.2013

^^^^^^^^