SA-MP Forums Archive
Count 1/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: Count 1/2 players (/showthread.php?tid=284089)



Count 1/2 players - knackworst - 17.09.2011

Hi, for my server I wanna make some kind of police radio.
in a textdraw every 25 seconds a player from gTeam[playerid] = TEAM_COPS
will see 2 people having a wanted level higher than 1.
after 25 seconds there should come 2 new people displayed
if theres none having a wantedlevel higher than 1 it should say no suspects...

Well so basically what I need to create is something that can count 2 players
Is that possible
if yes, how?


Re: Count 1/2 players - StuffBoy - 17.09.2011

you can loop all players with your timer and check if there are others with wanted level


Re: Count 1/2 players - JiHost - 17.09.2011

It is.
Search forum, find GetRandomID() function and add wanted level star check to it.


Respuesta: Count 1/2 players - Xyrex - 17.09.2011

I think It's simple:

1 timer.
2 global vars (for saving the last people who are "wanted")

A loop for all players. Check if they are wanted. If(true), display their names and save theirs ID.
Again the loop. Check for wanted people and check if their ID are saved in the vars.


Re: Count 1/2 players - knackworst - 17.09.2011

Ok, so I decided to do jihost's thing
so I foudn this stock:
pawn Код:
{
    new bool:connected[MAX_PLAYERS] = false, amount = 0;
    for(new i = 0; i < MAX_PLAYERS; i++)
      if(IsPlayerConnected(i))
      {
        connected[i] = true;
        amount++;
      }
    if(amount = 0) return -1;
    new rand = random(amount), done = 0;
    for(new i = 0; i < MAX_PLAYERS; i++)
      if(connected[i])
      {
        if(done == rand) return i;
        done++;
        }
    return -1;
}
and added it in my GM (on the end)
then I made a test command:
pawn Код:
if (strcmp("/test", cmdtext, true) == 0)
    {
        format(string,sizeof(string),"Test id:%d",GetRandomID());
        SendClientMessage(playerid,COLOR_RED,string);
        return 1;
    }
but I get this warning:
Код:
C:\Users\William\Documents\Famous' World\Famous' World\gamemodes\Famous.pwn(8436) : warning 211: possibly unintended assignment
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Warning.
error line:
pawn Код:
if(amount = 0) return -1;
its in the stock thing


Re: Count 1/2 players - Xyrex - 17.09.2011

Simple:

pawn Код:
if(amount == 0) return -1;



Re: Count 1/2 players - Ricop522 - 17.09.2011

pawn Код:
if (!strcmp("/test", cmdtext, true))
    {
        format(string,sizeof(string),"Test id:%d",getRandomID());
        SendClientMessage(playerid,COLOR_RED,string);
        return 1;
    }
    stock getRandomID()
    {
        new i, c;
        for ( ; i < MAX_PLAYERS; ++i )
        {
            if ( IsPlayerConnected( i ) )
            {
                ++c;
            }
        }
        return random(c);
    }



Re: Count 1/2 players - knackworst - 18.09.2011

ah, thanks both worked!
and how do I do that when a random ID gets picked and it hasn't got a wantedlevel higher than 5 there will be another ID picked with a wantedlevel higher than 3?