GetMaxPlayers() as a constant
#1

It seems I cannot figure out how to use GetMaxPlayers() to be accepted as a constant...

I've tried defining it:
#define max_players GetMaxPlayers()

I've tried the direct methods:
const max_players=GetMaxPlayers();
new const max_players=GetMaxPlayers();

I've even tried combining variations of the two...

Now I know GetMaxPlayers() works fine in "for" statements:
for (new a=0;a<GetMaxPlayers();a++)

I'm just trying to use it when creating new arrays, like:
new noobs[GetMaxPlayers()]

Tell me it's possible and prove to an old man that it's not just that his medication is wearing off...This has been keeping me up at nights....

Thanx to anyone that responds with a workable solution...






Reply
#2

I myself tried to define it (with equally little success) as it felt wrong constantly redefining it in each loop.. So i'd be interested to see if there's a simple solution to this...

EDIT: Could you not use "GetServerVarAsInt" ? I read that all GetMaxPlayers does is check the server.cfg.. which is much the same as that command does is it not?

Like..

pawn Код:
new Max = GetServerVarAsInt("maxplayers");
Reply
#3

I use something similar in my house script.

pawn Код:
new lines;

//ONGameModeInit
lines = GetFileLines("houses.txt");
for(new i = 0; i < lines; i++)
{
  SetPlayerMapIcon(...);
}
Leopard
Reply
#4

What I said works =) Just tested it with the following:

pawn Код:
if(strcmp(cmdtext, "/players?", true) == 0)
    {
    new string[100], Max = GetServerVarAsInt("maxplayers");
    format(string, sizeof(string), "The maximum number of players this server can take is: %d", Max);
    SendClientMessage(playerid, 0xFF00FFAA, string);
    return 1;
    }
Got the result:

Quote:

The maximum number of players this server can take is: 10

Hope this serves you well!
Reply
#5

I simply changed MAX_PLAYERS in a_samp.inc...
Reply
#6

Quote:
Originally Posted by CrαcK
I simply changed MAX_PLAYERS in a_samp.inc...
But if you release a script, not everyone is going to have changed theirs, and many won't want to have to. And if you just use MAX_PLAYERS for a server with only 10 people, that's 190 iterations of a loop of wasted processing.
Reply
#7

I haven't released anything yet =)
I don't know, so does Spectre how to GetMaxPlayers to a constant... defining MAX_PLAYERS is a workaround for now.
Reply
#8

If you want to change MAX_PLAYERS, i use

pawn Код:
#undef MAX_PLAYERS
#define MAX_PLAYERS 50
Leopard
Reply
#9

Quote:
Originally Posted by [K4L
Leopard ]
If you want to change MAX_PLAYERS, i use

pawn Код:
#undef MAX_PLAYERS
#define MAX_PLAYERS 50
Leopard
But everyone downloading the script would have to customize it to suit their individual needs, whereas checking the server.cfg saves them that extra bit of effort. And let's face it, anything that requires effort results in someone posting a pointless question in the wrong forum.
Reply
#10

I believe you guys are missing my point...

I don't want to redefine MAX_PLAYERS (CAPITAL LETTERS - standard in-game constant set to 200)

I want to define the result of the in-game function GetMaxPlayers() and store it as a constant called max_players (lower case)...Actually, I want to call it maxp but I thought I'd offer it as max_players so you folks would catch the subtle difference...

Check the stars under my name...I've been doing this quite a while now (and would probably have more were it not for extended hospital stays) and know my way around SA-MP/Pawn pretty well but this seemingly easy endeavour still eludes me...

Everything you guys have provided are all interesting approaches but not the answer to the question:
How do you define/assign GetMaxPlayers() as a constant?

Weirdo: The GetServerVarAsInt looks the most interesting...I think I'll play with that a bit...Looks promising...I'll get back to you...If this works it is worthy of a Wiki entry...






Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)