Restart the round
Restart the round
Hello, how would I go about restarting the round on command?
You need to execute the "mp_restartgame <delay>" command on the server. This code restarts the round 1 second after typing "!restart":
Syntax: Select all
from engines.server import engine_server
from events import Event
@Event('player_say')
def on_player_say(event):
if event['text'] == '!restart':
engine_server.server_command('mp_restartgame 1\n')
What do you want exactly?
You could try these console command:
Or Mahi could beat me to it, still note the second command I listed. =]
You could try these console command:
Code: Select all
"mp_restartgame" = "0"
game
- If non-zero, game will restart in the specified number of seconds
"mp_restartgame_immediate" = "0"
game
- If non-zero, game will restart immediately
Or Mahi could beat me to it, still note the second command I listed. =]
Or, if you want to preserve players and team scores, you might try executing endround cheat command, but you need to strip CHEAT flag from it first.
Or, if you want to end a round with a certain condition, you might want to check out this example by Doldol
Syntax: Select all
from cvars import cvar
from cvars.flags import ConVarFlags
from engines.server import engine_server
from events import Event
ENDROUND_TEXT = "endround"
CVAR_ENDROUND = cvar.find_command_base(ENDROUND_TEXT)
def restart_round():
"""Strip the CHEAT flag, execute 'endround' and put the flag back."""
CVAR_ENDROUND.remove_flags(ConVarFlags.CHEAT)
engine_server.server_command('{0};'.format(ENDROUND_TEXT))
engine_server.server_execute()
CVAR_ENDROUND.add_flags(ConVarFlags.CHEAT)
@Event('player_say')
def on_player_say(game_event):
"""Detect !restart chat command"""
if game_event.get_string('text') == "!restart":
restart_round()
Or, if you want to end a round with a certain condition, you might want to check out this example by Doldol
- L'In20Cible
- Project Leader
- Posts: 1536
- Joined: Sat Jul 14, 2012 9:29 pm
- Location: Québec
I guess this is caused by server_command adding the command to the parser which then executes waiting commands once a frame. You need to do something like this:iPlayer wrote:I tried putting the flag back right after executing endround, but it didn't work for me, so I decided to put the flag back when a new round starts.
Syntax: Select all
engine_server.server_command('blah')
engine_server.server_execute() # Force any commands waiting to be executed now...
...
Syntax: Select all
engine_server.server_execute()
That works, thanks. I edited my previous post.
Re: Restart the round
How safe it is to execute engine_server.server_execute() multiple times per frame? Won't it crash the server?

My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam
Hail, Companion. [...] Hands to yourself, sneak thief.

Re:
Mahi wrote:You need to execute the "mp_restartgame <delay>" command on the server. This code restarts the round 1 second after typing "!restart":Syntax: Select all
from engines.server import engine_server
from events import Event
@Event('player_say')
def on_player_say(event):
if event['text'] == '!restart':
engine_server.server_command('mp_restartgame 1\n')
Just wanted to add a note that the \n or ; is no longer necessary, as we handle that internally:
https://github.com/Source-Python-Dev-Te ... ines.h#L54
Re: Restart the round
iPlayer wrote:How safe it is to execute engine_server.server_execute() multiple times per frame? Won't it crash the server?
I 'believe' it is safe. It just executes all commands in the current parser. So, if there are no commands in the parser, it just shouldn't do anything. You could always test that to verify.
Syntax: Select all
for x in range(100000):
engine_server.server_execute()
Re: Restart the round
The reason I asked is because of "insertcmd" from EventScripts. It was followed by warnings that it's unsafe to change the flow of the command queue.

My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam
Hail, Companion. [...] Hands to yourself, sneak thief.

Re: Restart the round
InsertCommand is completely different from ServerExecute. With InsertCommand, you are inserting the command into the parser at the beginning, whereas ServerCommand inserts at the end. ServerExecute just executes the current command parser instead of waiting till the appropriate time during the current tick to do so.
Re: Restart the round
I think the reason for this warning was, because there were some random crashes with ES on Linux in combination with psyco. And it was assumed that functions like insertcmd, es.remove and es.fire were causing the crashes, because queuing these functions was working fine.
Edit:
I should also mention that we are planning to update the commands functions, so there is only an execute_server_command() function to execute a command immediately using the Dispatch() method and a queue_server_command() function to queue a command. I already have the code for that locally, but just haven't commited it yet.
Edit:
I should also mention that we are planning to update the commands functions, so there is only an execute_server_command() function to execute a command immediately using the Dispatch() method and a queue_server_command() function to queue a command. I already have the code for that locally, but just haven't commited it yet.
Re:
iPlayer wrote:Syntax: Select all
def restart_round():
"""Strip the CHEAT flag, execute 'endround' and put the flag back."""
CVAR_ENDROUND.remove_flags(ConVarFlags.CHEAT)
engine_server.server_command('{0};'.format(ENDROUND_TEXT))
engine_server.server_execute()
CVAR_ENDROUND.add_flags(ConVarFlags.CHEAT)
Today the code above doesn't seem to work for some reason. Server still reports
Can't use cheat command endround in multiplayer, unless the server has sv_cheats set to 1.
even though there's engine_server.server_execute() right before putting CHEAT flag back on.
But! The following works fine:
Syntax: Select all
from commands import Command
...
def restart_round():
CVAR_ENDROUND.remove_flags(ConVarFlags.CHEAT)
CVAR_ENDROUND.dispatch(Command())
CVAR_ENDROUND.add_flags(ConVarFlags.CHEAT)

My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam
Hail, Companion. [...] Hands to yourself, sneak thief.

- L'In20Cible
- Project Leader
- Posts: 1536
- Joined: Sat Jul 14, 2012 9:29 pm
- Location: Québec
Re: Restart the round
You should avoid playing with cheat commands. Just use an info_map_parameter entity.
Re: Restart the round
Well, you could've posted example from our Cookbook (by Doldol).
Also, why should I avoid them?
This
Also, why should I avoid them?
This
necavi, even if I unset 'cheat' flag for ent_fire and then immediately set it back, how long does this "immediately" last? Can I strip the flag, use ent_fire and set the flag back in one tick? If so, I guess this is indeed safe. But if I have to bring the flag back in the next tick, this leaves a window for an attacker.
I have always done so in the same tick with no issue, yes, that was the entire premise of this plugin, basically: https://github.com/necavi/Merx

My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam
Hail, Companion. [...] Hands to yourself, sneak thief.

- L'In20Cible
- Project Leader
- Posts: 1536
- Joined: Sat Jul 14, 2012 9:29 pm
- Location: Québec
Re: Restart the round
I redirected where I knew an example was.iPlayer wrote:Well, you could've posted example from our Cookbook (by Doldol).
Cause they are... cheats for a reason. Also, for the simple fact that you assume a state of sv_cheats. What if a server that run your codes wants cheats enabled on their server? Exactly, you will mess his settings.iPlayer wrote:Also, why should I avoid them?
iPlayer wrote:Thisnecavi, even if I unset 'cheat' flag for ent_fire and then immediately set it back, how long does this "immediately" last? Can I strip the flag, use ent_fire and set the flag back in one tick? If so, I guess this is indeed safe. But if I have to bring the flag back in the next tick, this leaves a window for an attacker.I have always done so in the same tick with no issue, yes, that was the entire premise of this plugin, basically: https://github.com/necavi/Merx
I didn't say it was not working. I just believe they should be avoided when there are alternatives.
Re: Restart the round
Cause they are... cheats for a reason.
So what? If I can achieve the same result without cheats, but this approach is way more convenient?
Also, for the simple fact that you assume a state of sv_cheats. What if a server that run your codes wants cheats enabled on their server? Exactly, you will mess his settings.
I don't quite get your point. I don't manipulate sv_cheats in any way here. I just strip a CHEAT flag from a particular command and then put it back on.

My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam
Hail, Companion. [...] Hands to yourself, sneak thief.

Re: Restart the round
I don't understand how it's "way more convenient" than this:
Syntax: Select all
def restart_round():
Entity.find_or_create('info_map_parameters').fire_win_condition(9)
- L'In20Cible
- Project Leader
- Posts: 1536
- Joined: Sat Jul 14, 2012 9:29 pm
- Location: Québec
Re: Restart the round
iPlayer wrote:I don't quite get your point. I don't manipulate sv_cheats in any way here. I just strip a CHEAT flag from a particular command and then put it back on.
My bad I assumed you did, but my point remains the same. What if I want that flag removed on my server? You will put it back in and mess my settings.
satoon101 wrote:I don't understand how it's "way more convenient" than this:Syntax: Select all
def restart_round():
Entity.find_or_create('info_map_parameters').fire_win_condition(9)
Exactly what I think too.
However, I just pointed out that there was better (in my opinion) alternatives but you really seems to be on the defensive and sticky on that method so next time I will just avoid proposing them.

Re: Restart the round
I don't feel like creating a new entity and firing its input just for the sake of restarting the round.
I suppose Invincible misread my code. I didn't set sv_cheats to 1, execute my command and then reset sv_cheats to 0. If that were the case, then I could indeed mess server settings.
I suppose Invincible misread my code. I didn't set sv_cheats to 1, execute my command and then reset sv_cheats to 0. If that were the case, then I could indeed mess server settings.

My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam
Hail, Companion. [...] Hands to yourself, sneak thief.

Return to “Plugin Development Support”
Who is online
Users browsing this forum: No registered users and 117 guests