SA-MP Forums Archive
INVALID_PLAYER_ID - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: INVALID_PLAYER_ID (/showthread.php?tid=78927)



INVALID_PLAYER_ID - russiany - 24.05.2009

Hey there. I have a question. If i'm using a loop ( for ) and i use IsPlayerConnected(i) i need to use
pawn Code:
i != INVALID_PLAYER_ID
?

e.g.:

pawn Code:
for(new i = 0; i < GetMaxPlayers(); i++)
                {
                    if (PlayerInfo[i][Key] == PlayerInfo[playerid][Key])
                    {
                        if(IsPlayerConnected(i))
                        {
                          if(i != INVALID_PLAYER_ID)
                          {



Re: INVALID_PLAYER_ID - Castle - 24.05.2009

All fine except this one:
pawn Code:
for(new i = 0; i < GetMaxPlayers(); i++)
change to:
pawn Code:
for(new i = 0; i < MAX_PLAYERS; i++)



Re: INVALID_PLAYER_ID - russiany - 24.05.2009

oh really ? Who learned you this ? Both are corectly , but GetMaxPlayers(); takes the value of my players sets from server.cfg ( if in server.cfg at maxplayers i have 100 , at GetMaxPlayers(); it allow space just for 100 players).

But I repeat my question , if i use IsPlayerConnected(i) , i must use i != INVALID_PLAYER_ID ?


Re: INVALID_PLAYER_ID - Lewwy - 24.05.2009

GetMaxPlayers() is more inefficient than MAX_PLAYERS despite the fact it should theoretically, loop less, and it can't be saved to a variable.


Re: INVALID_PLAYER_ID - Castle - 24.05.2009

So Basically MAX_PLAYERS works better that GetMaxPlayers();


Re: INVALID_PLAYER_ID - Lewwy - 24.05.2009

My point exactly. It's more efficient.


Re: INVALID_PLAYER_ID - russiany - 24.05.2009

Quote:
Originally Posted by russiany
But I repeat my question , if i use IsPlayerConnected(i) , i must use i != INVALID_PLAYER_ID ?



Re: INVALID_PLAYER_ID - Lewwy - 24.05.2009

Not necessarily.


Re: INVALID_PLAYER_ID - MenaceX^ - 24.05.2009

Quote:
Originally Posted by russiany
Quote:
Originally Posted by russiany
But I repeat my question , if i use IsPlayerConnected(i) , i must use i != INVALID_PLAYER_ID ?
You can do
pawn Code:
if(!IsPlayerConnected(i)) return 0;
Quote:
Originally Posted by Castle
All fine except this one:
pawn Code:
for(new i = 0; i < GetMaxPlayers(); i++)
change to:
pawn Code:
for(new i = 0; i < MAX_PLAYERS; i++)
Why would he do it?
You can do GetMaxPlayer or either do MAX_PLAYERS and check if the player is connected.


Re: INVALID_PLAYER_ID - russiany - 24.05.2009

Quote:
Originally Posted by [XG
Lj ]
Not necessarily.
Thanks.