MAX_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: MAX_PLAYERS (
/showthread.php?tid=405907)
MAX_PLAYERS -
micol - 08.01.2013
Hi, it's me again. ;p
I have another question(like usually).
When I have in my GM something like this:
Код:
#undef MAX_PLAYERS
#define MAX_PLAYERS NUMBER_OF_MY_SLOTS
and my question is simple.
How I must use this?
like:
Код:
arena[playerid] == true
or
Код:
arena[MAX_PLAYERS] == true
or
Код:
arena[NUMBER_OF_MY_SLOTS] == true
Greetings, micol.
Re: MAX_PLAYERS -
Babul - 08.01.2013
playerid is a default variable in most callbacks which need one players' id to proceed.
if you ever try to access a variable with [MAX_PLAYERS], you will get no warning/error at compile time, but the script will crash, due to an "out of bounds error".
hence each array starts at an index of 0 - assuming 80 MAX_PLAYERS, the 80'th element gets assigned [79].
when declaring an array with 80 slots, is IS required to use the size of 80.
here is a little example:
Код:
new Test[MAX_PLAYERS]; //array ranging from 0 upto MAX_PLAYERS-1 (79), is 80 cells together.
later, in a function/callback USING playerid, like:
Код:
public OnPlayerUpdate(playerid)
{
new Test[playerid]=GetTickCount();//writes the actual timestamp into the playerid's cell.
return 1;
}
here a loop in a function, NOT using playerid, so it needs to be created first:
Код:
stock Timestamps()
{
for(new playerid=0;playerid<MAX_PLAYERS)
{
Test[playerid]=0;//delete timestamp for each player
}
return 1;
}
Re: MAX_PLAYERS -
micol - 08.01.2013
Thanks for quick answer.

I'm finally know this. : D
Greetings, micol.
@EDIT
And another edit from my side. : c
Can you tell me whether I can write code like this:
Код:
new arena[2][MAX_PLAYERS]
or how ?
This means something like this
Код:
arena[0][playerid] == 1
arena[1][playerid] == 1
Re: MAX_PLAYERS -
u3ber - 09.01.2013
Quote:
Originally Posted by micol
How I must use this?
like:
Код:
arena[playerid] == true
or
Код:
arena[MAX_PLAYERS] == true
or
Код:
arena[NUMBER_OF_MY_SLOTS] == true
|
not sure what Babul hasn't mentioned, but MAX_PLAYERS is just a number. So it doesn't really matter in the above ^. But be weary! #defines are used (and should be used) when wanting to make multiple references towards some value. it becomes a compile-time constant meaning before actual compilation (preprocessing) all occurrences of the identifier are replaced with a constant value.
hi, click me.
Quote:
Originally Posted by miloc
Can you tell me whether I can write code like this:
Код:
new arena[2][MAX_PLAYERS]
or how ?
This means something like this
Код:
arena[0][playerid] == 1
arena[1][playerid] == 1
|
yes...