SA-MP Forums Archive
Select 2 Players - 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: Select 2 Players (/showthread.php?tid=574922)



Select 2 Players - Blackazur - 22.05.2015

Hello, how can i make that this chooses instead of one Player 2 Players?

Код:
stock OnePlayer()
{
    new count = 0;
    new Random = Iter_Random(Player);
    foreach(Player, i)
    {
        if(team[i] == TEAM_RED) count++;
        if(count == Iter_Count(Player))
        {
			SendClientMessage(playerid,COLOR_RED"You got chosen.");
        }
    }
    return 1;
}



Re: Select 2 Players - jamesbond007 - 22.05.2015

i dont think this even chooses one random player

im not familiar with ******'s libraries tho


AW: Select 2 Players - Blackazur - 22.05.2015

this select one player but i want that it chooses 2 players..


Re: AW: Select 2 Players - SickAttack - 22.05.2015

Quote:
Originally Posted by Blackazur
Посмотреть сообщение
this select one player but i want that it chooses 2 players..
No it doesn't. It just gives them a message. Well, not even that because it sends the message to the player with the id in the variable "playerid", which is unknown, not even defined.


Re: Select 2 Players - Gammix - 22.05.2015

pawn Код:
new Random = Iter_Random(Player);
Doesn't this gives you warnings? You aren't using it then why declare it?

pawn Код:
if(count == Iter_Count(Player))
This isn't required if all the players are TEAM_RED. You must use a specific integer value to check that limit. For example:
pawn Код:
if(count > Iter_Count(Player))
This will run only when there are more than 2 red team players.

I assume you want to pickup random players for choosing them, so this code will pick 2 random players from TEAM_RED:
pawn Код:
new players = Itter_Count(Player);
    if(players > 1)//if there is more than 1 player
    {
        #define count 2//number of players we want to select

        for(new x = 0; x < count; x++)//looping as many people we want to select
        {
            new bool:choosen = false;
            foreach(new i : Player)//not an efficient method though! (but can work OK!)
            {
                new randomplayer = Iter_Random(Player);
                if(team[randomplayer] == TEAM_RED)
                {
                    //your code
                    SendClientMessage(randomplayer,COLOR_RED"You got chosen.");
                    choosen = true;
                    break;
                }
            }
            if(! choosen)//in case no one was choosen, we will go loop sequently!
            {
                foreach(new i : Player)
                {
                    if(team[i] == TEAM_RED)
                    {
                        //your code
                        SendClientMessage(i,COLOR_RED"You got chosen.");
                        break;
                    }
                }
            }
        }
    }