Delay function after server is start

Please post any questions about developing your plugin here. Please use the search function before posting!
nullable
Senior Member
Posts: 137
Joined: Sat Nov 08, 2014 7:22 pm

Delay function after server is start

Postby nullable » Sat Nov 08, 2014 7:28 pm

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)
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sun Nov 09, 2014 1:09 am

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.
Image
nullable
Senior Member
Posts: 137
Joined: Sat Nov 08, 2014 7:22 pm

Postby nullable » Sun Nov 09, 2014 7:23 am

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

Postby L'In20Cible » Sun Nov 09, 2014 10:47 am

Well, it's normal. As the name says, tick_delays rely on game frames and there is no frame while the server is hibernating.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sun Nov 09, 2014 12:57 pm

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
Image
nullable
Senior Member
Posts: 137
Joined: Sat Nov 08, 2014 7:22 pm

Postby nullable » Sun Nov 09, 2014 7:04 pm

The problem has been resolved. Thanks

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 31 guests