Defining Max Players from server.cfg
#1

I run a little private server, ergo I am NOT going to have 500 players...Ever...
Rather than have all my player checks go through all 500 non-existent players I like to limit it to 50...

I have the line: maxplayers 50 in my server.cfg

Why can I define max_p (my variable) in a filterscript but NOT in the main game mode?

In the filterscript I use:
#define max_p GetServerVarAsInt("maxplayers") and it works fine...

But when I try that in the main game mode I get a "Pawn Compiler Library has stopped working" error...

Anyone have a clue or can tell me what I'm doing wrong?
8^}>
Reply
#2

1. Definitions are used by pawn pre-rpocessor, so you cannot define something non-constant
2. There's function GetMaxPlayers to get servers slots
3. In your case you need to do this:
Код:
#undef MAX_PLAYERS
#define MAX_PLAYERS (50)
Reply
#3

I'll go play with variations on that...
I STILL want to actually pull the info from the server.cfg if at all possible...
That'll keep me busy for a while anyway...
Thanx...
8^}>
Reply
#4

Quote:
Originally Posted by Spectre
Посмотреть сообщение
I'll go play with variations on that...
I STILL want to actually pull the info from the server.cfg if at all possible...
That'll keep me busy for a while anyway...
Thanx...
8^}>
Why would you want that?
Reading the server.cfg file everytime that function gets executed won't improve the execution time.
Variables in the memory are faster.

Correct me if I'm wrong.
Reply
#5

You're not.
Reply
#6

You misunderstand...
I don't want to pull it from the server.cfg for every instance, only upon initialisation...
Reply
#7

Obviously you didn't read Sergei's post congratz
Reply
#8

Why not use foreach? Then, if you only have 4 players in your server, it'll only loop through those 4 IDs.

https://sampforum.blast.hk/showthread.php?tid=92679
Reply
#9

I'd also recommend to put a check if you did #define MAX_PLAYERS (sumthing) correctly.
pawn Код:
// For example, you have maxplayers 40 in server.cfg
// And you do
#define MAX_PLAYERS (50)
// It will print that your MAX_PLAYERS is not the same as the one in server.cfg and it will close your server
public OnFilterScriptInit( )
{
    print( "Testing if you have set the MAX_PLAYERS define... " );
    if( MAX_PLAYERS != GetMaxPlayers( ) )
    {
        print( "Your MAX_PLAYERS define is not the same as the one in server.cfg, please change it" );
        return SendRconCommand( "exit" );
    }
    print( "Success! You have the MAX_PLAYERS define as it should be! ");
    return 1;
}
Reply
#10

just use GetMaxPlayers() in your loops..
pawn Код:
for(new i=0; i<GetMaxPlayers(); i++)
That only checks through the amount of players that are in the server.cfg...
(/me hopes that was something you can use and nothing of which you think "man noob that's nothing I need" :P)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)