[Solved] GetServerVarAsInt + 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: [Solved] GetServerVarAsInt + MAX_PLAYERS (
/showthread.php?tid=120918)
[Solved] GetServerVarAsInt + MAX_PLAYERS -
Miguel - 14.01.2010
My server has less than 500 slots, and using MAX_PLAYERS is just a waste of memory. My question is if I can do this:
pawn Код:
#define SLOTS GetServerVarAsInt("maxplayers")
If not, i will have to re define slots everytime i change that value

.
Re: GetServerVarAsInt + MAX_PLAYERS -
ev0lution - 14.01.2010
You can, but that means every time you make a reference to SLOTS in your gamemode, GetServerVarAsInt will be called.
That's slower than just using a variable/define, and useless because maxplayers can't change while the server is running, so you're constantly calling GetServerVarAsInt for the same value.
It'd be easier and faster to do this:
pawn Код:
new SLOTS;
public OnGameModeInit() {
SLOTS = GetServerVarAsInt("maxplayers");
}
Re: GetServerVarAsInt + MAX_PLAYERS -
Joe Staff - 14.01.2010
Quote:
Originally Posted by ev0lutionnn
You can, but that means every time you make a reference to SLOTS in your gamemode, GetServerVarAsInt will be called.
That's slower than just using a variable/define, and useless because maxplayers can't change while the server is running, so you're constantly calling GetServerVarAsInt for the same value.
It'd be easier and faster to do this:
pawn Код:
new SLOTS;
public OnGameModeInit() { SLOTS = GetServerVarAsInt("maxplayers"); }
|
That won't work when creating variables. If accessing your script isn't a big deal then just add
pawn Код:
#undef MAX_PLAYERS
#define MAX_PLAYERS 32
Re: GetServerVarAsInt + MAX_PLAYERS -
Miguel - 14.01.2010
It doesn't work anyway, i just wanted to know if there's a way to make a non constan
#define...
Thanks!