PDA

View Full Version : Adjusting maxclients



guiismiti
18th February 2015, 18:52
Hi,

I'm trying to adjust the number of slots in my server based on the number of bots online.

Here is code I'm using:



if(getCvarInt("mod_slotadjust") == 1)
{
slots = 16;

players = getentarray("player", "classname");

for(i = 0; i < players.size; i++)
{
if(isdefined(players[i].isbot))
{
slots++;
}
}

setCvar("sv_maxclients", slots);
}


It is placed inside checkTimeLimit(), which is called every second.

The problem is, the game crashes, dedicated or not.

I tried starting the server with mod_slotadjust set to 0, waiting for all bots to be added and only then turn it to 1, and that will also crash.

Here's what I've got in my console, and that is all:



]/mod_slotadjust 1
dvar set mod_slotadjust 1
dvar set restart
dvar set sv_cheats 0
dvar set restart
dvar set sv_cheats 0
dvar set restart
dvar set sv_cheats 0
dvar set restart
dvar set sv_cheats 0
dvar set sv_maxclients 31


I also tried to create a new function that was called every 30 seconds with the same functionality, it still crashed.

Any ideas? Am I missing something obvious?

IzNoGoD
18th February 2015, 18:57
Have you considered the possibility that sv_maxclients wasnt meant to be changed?

Tally
18th February 2015, 19:02
As Izno rightly points out - once the server is compiled, you cannot change the number of maxclients without restarting the server over again. It is not a dynamic dvar.

When you start a server, the game allocates a set amount of memory to each client slot, irrespective of whether or not there are the max number of players online. To do this it has to hard-code the compilation of the server. As such, maxclients cannot be changed once set to a specific amount; not without a server restart.

guiismiti
18th February 2015, 19:10
While coding this, I was under the false impression that I once made that work.

IzNoGoD
18th February 2015, 20:31
You could try to make your server 64 slots, then reduce the amount of visible slots towards the getinfo by people query-ing your server

maxdamage99
19th February 2015, 12:49
Izno, how to make the players to see a different number? or all other information about the server ??
in the list of servers.

IzNoGoD
19th February 2015, 16:32
I dont know, i was just proposing a solution