[Solved] GetServerVarAsInt + MAX_PLAYERS
#1

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 .
Reply
#2

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");
}
Reply
#3

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
Reply
#4

It doesn't work anyway, i just wanted to know if there's a way to make a non constan #define...

Thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)