bot_kick not working via execute_server_command

All other Source.Python topics and issues.
JustGR
Junior Member
Posts: 20
Joined: Tue Apr 28, 2020 12:39 pm

bot_kick not working via execute_server_command

Postby JustGR » Sun May 03, 2020 4:26 am

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?
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: bot_kick not working via execute_server_command

Postby L'In20Cible » Sun May 03, 2020 4:43 am

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).
JustGR
Junior Member
Posts: 20
Joined: Tue Apr 28, 2020 12:39 pm

Re: bot_kick not working via execute_server_command

Postby JustGR » Sun May 03, 2020 5:07 am

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?
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: bot_kick not working via execute_server_command

Postby L'In20Cible » Sun May 03, 2020 5:33 am

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.
JustGR
Junior Member
Posts: 20
Joined: Tue Apr 28, 2020 12:39 pm

Re: bot_kick not working via execute_server_command

Postby JustGR » Sun May 03, 2020 5:50 am

Alright, one last question. After adding commands to the queue via queue_server_command, how do you handle their execution?
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: bot_kick not working via execute_server_command

Postby L'In20Cible » Sun May 03, 2020 6:02 am

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:
InvisibleSoldiers
Senior Member
Posts: 114
Joined: Fri Mar 15, 2019 6:08 am

Re: bot_kick not working via execute_server_command

Postby InvisibleSoldiers » Sun May 03, 2020 8:48 am

You can kick bots by setting bot_quota to 0.

Syntax: Select all

from cvars import ConVar

ConVar('bot_quota').set_int(0)

Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 22 guests