Page 1 of 1

Delay function after server is start

Posted: Sat Nov 08, 2014 7:28 pm
by nullable
I need help. I want call a function afer server is start, but I think next code start implemention after game is starting (user connection to game).

Code: Select all

from listeners.tick import tick_delays

def game_run_checker():
    print('CHECKER TEST')

def load():
    tick_delays.delay(5, game_run_checker)

Posted: Sun Nov 09, 2014 1:09 am
by satoon101
I'm not fully sure what you are looking for. As long as that script above is loaded in your autoexec.cfg, it should cause the function to be called relatively close to 5 seconds after the server starts.

Also, instead of using basic code blocks, you can use [python][/python] to provide Python syntax blocks in forum posts.

Posted: Sun Nov 09, 2014 7:23 am
by nullable
Ok. I mean next. The script is already in autoexec.cfg and should be called after the server has started. I want to turn off the server after 5 minutes after starting the server, even if no one came into play. I get so that counting begins after someone walked into the first game and not after the server has started:

Syntax: Select all

import time

from engines.server import engine_server
from messages import HintText
from listeners.tick import tick_delays

round_num = -1

def load():
tick_delays.delay(5*60, game_run_checker)

def game_run_checker():
global round_num
if round_num == -1:
HintText(message='Commands have not completed').send()
time.sleep(10)
engine_server.server_command('quit;')

Posted: Sun Nov 09, 2014 10:47 am
by L'In20Cible
Well, it's normal. As the name says, tick_delays rely on game frames and there is no frame while the server is hibernating.

Posted: Sun Nov 09, 2014 12:57 pm
by satoon101
To make sure the game doesn't hibernate when empty, use the following in your autoexec.cfg:

Code: Select all

sv_hibernate_when_empty 0

Posted: Sun Nov 09, 2014 7:04 pm
by nullable
The problem has been resolved. Thanks