Bonus kill / player
#1

^^^^^^^^
Reply
#2

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

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;
}
Reply
#4

^^^^^^^^
Reply
#5

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

^^^^^^^^
Reply
#7

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;
}
Reply
#8

^^^^^^^^
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)