SA-MP Forums Archive
MAX_PLAYERS what is this? - 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: MAX_PLAYERS what is this? (/showthread.php?tid=65980)



MAX_PLAYERS what is this? - icey--t - 18.02.2009

what is [MAX_PLAYERS] and what is it used for. i dont get it. ive seen it numerous times but i personally dont use it lol, only because i have no idea whats it for


Re: MAX_PLAYERS what is this? - Finn - 18.02.2009

MAX_PLAYERS is the maximum amount of players that SA-MP server can hold at once, which means that MAX_PLAYERS is 200.

Usually MAX_PLAYERS is used in variables that check if player does something or for example counts kills:

pawn Код:
new kills[MAX_PLAYERS];

public OnPlayerDeath(playerid, killerid, reason)
{
    kills[killerid]++; // Adds one kill for killedid.
    return 1;
}



Re: MAX_PLAYERS what is this? - icey--t - 18.02.2009

i still dont get it. why even use it then. so max_players puts a playerid unique to a declaration?


Re: MAX_PLAYERS what is this? - robanswe - 20.02.2009


new kills[MAX_PLAYERS];

public OnPlayerDeath(playerid, killerid, reason)
{
kills[killerid]++; // Adds one kill for killedid.
return 1;
}

if(strcmp(cmd, "/kills", true) == 0)
{
new str[256];

format(str, sizeof(str), "You have killed %d players )!",kills);//this is a example to haw to use this
SendClientMessage(playerid, 0xAA3333AA, str);
return 1;
}

This code besikly stores information of a playerid...





Re: MAX_PLAYERS what is this? - Mikep - 20.02.2009

Roban[swe]: Learn to indent, script and use [ pawn ] tags.


Re: MAX_PLAYERS what is this? - kc - 20.02.2009

Quote:
Originally Posted by icey--t
i still dont get it. why even use it then. so max_players puts a playerid unique to a declaration?
it would usually be used in an array, to create a variable slot for each player.

e.g.

pawn Код:
new money;
Is just one cell. You can only store one number in it.
pawn Код:
new money[MAX_PLAYERS];
Creates 200 cells (MAX_PLAYERS is just a define for 200). You can store a number in each of them.

_________________________________________________

With that, you can store players information easily.

pawn Код:
money[playerid] = GetPlayerMoney(playerid);
printf("playerid %d has $%d",playerid, money[playerid]);