Page 1 of 1

bot_kick not working via execute_server_command

Posted: Sun May 03, 2020 4:26 am
by JustGR

Syntax: Select all

Code: Select all

from engines.server import execute_server_command

@TypedSayCommand(cvar_saycommand_bot_kick.get_string())
def on_bot_kick(commandInfo):
   execute_server_command('bot_kick')
   commandInfo.reply("Bots kicked!")
   return False

This snippet doesn't work, as no bots get kicked. Works fine from console (all bots are kicked), just not via the command. The same code would work with the mp_warmup_end and changelevel commands.
Any idea why?

Re: bot_kick not working via execute_server_command

Posted: Sun May 03, 2020 4:43 am
by L'In20Cible
Some commands won't be processed if they are forced to execute. They will be dispatched, but they won't perform their logic unless they are handled by the queue (through queue_server_command or insert_server_command).

Re: bot_kick not working via execute_server_command

Posted: Sun May 03, 2020 5:07 am
by JustGR
What on earth.. insert_server_command worked.

Could I get more info on this? Why did changelevel and mp_warmup_end work with execute, but not this one? And for future reference : how would I be able to tell which ones would work?

Re: bot_kick not working via execute_server_command

Posted: Sun May 03, 2020 5:33 am
by L'In20Cible
JustGR wrote:What on earth.. insert_server_command worked.

Could I get more info on this? Why did changelevel and mp_warmup_end work with execute, but not this one? And for future reference : how would I be able to tell which ones would work?

Can't really provide more info as it is up to the engine. Source.Python is just a middleman that forward the commands, what it does with them is out of our control. You can tell by testing I guess, as it will be on a case-by-case basis. But generally, I would recommend queuing all the commands and forcing their execution only when necessary. For example:

Syntax: Select all

from commands.server import *
from cvars import *
from engines.server import *

foo = 0

@ServerCommand('foo')
def _foo(command):
global foo
foo = 1

queue_server_command('foo')
print(foo)


This would prints 0, because foo wasn't modified yet so forcing its execution would be required here for it to properly prints 1, etc. But when it comes to engine commands that you don't expect anything back on the same frame such as the ones you mentioned above then you should really just queue them.

Re: bot_kick not working via execute_server_command

Posted: Sun May 03, 2020 5:50 am
by JustGR
Alright, one last question. After adding commands to the queue via queue_server_command, how do you handle their execution?

Re: bot_kick not working via execute_server_command

Posted: Sun May 03, 2020 6:02 am
by L'In20Cible
JustGR wrote:Alright, one last question. After adding commands to the queue via queue_server_command, how do you handle their execution?

You don't have anything special to do and the engine will process them on the next frame. Take the following example:

Syntax: Select all

queue_server_command('echo', '3')
insert_server_command('echo', '2')
execute_server_command('echo', '1')


This would prints 1, 2 and 3 although they were done as 3, 2 and 1 because queue_ adds at the end of the queue, insert_ adds at the beginning of the queue, and execute_ ignore the queue and dispatch the command right away. The queue is basically processed once per frame, so unless you absolutely need it to happens right away then just be polite and wait your turn by queuing the command. :tongue:

Re: bot_kick not working via execute_server_command

Posted: Sun May 03, 2020 8:48 am
by InvisibleSoldiers
You can kick bots by setting bot_quota to 0.

Syntax: Select all

from cvars import ConVar

ConVar('bot_quota').set_int(0)