The problem:
Players wanted Wave Respawns enabled however setting the respawns to a low value only accomodated low player counts and vice versa for high player counts and respawn times
My solution:
Running the script every 60-120 seconds via cron on linux server this script determines the number of players on the server and sends an rcon command to the server setting the wave respawns to a time based on the number of players like so:
0-4 players: 6 seconds wave respawn
5-8 players: 9 seconds wave respawn
9-12 Players: 12 seconds wave respawn
13+ players: 15 seconds wave respawn
I have decided that I would like to share this with the community so that server admins may gain from it for their own server if in a similiar situation.
The script depends on PyQuake3.py which can be found here: https://github.com/m...ter/pyquake3.py
place both this script and pyquake3 in the same directory the run the wavetimers.py script often (every 60 - 120 seconds) for it to function properly
#!/usr/bin/env python
"""
Wave respawn time adjuster
for Urban Terror ~ www.UrbanTerror.info
By |PWNY|NITR0
www.LilPwny.com
v1.0
Special thanks to:
Gsigms, FenixXx, Fruk, Kne_
for all their support <3
CHANGELOG
v1.0
Fully working script - now requires the use of a more
modern pyquake3.py script which can be found here:
https://github.com/madprof/pyquake3/blob/master/pyquake3.py
This resolves a bug in original script which would fail to
understand fragmented packets.
v0.6
Fixed errors in code from new cvar check module that caused
wave times to be constantly set to wave_low.
v0.5
Added cvar check to determine if server requires wave
timers to be changed. could potentially save bandwidth
if used over remote connection, however I added it to
reduce spam to server rcon port.
v0.4
Thanks to the help of fenix/gsigms I have spruced up the
script to be more readable and cleaner in execution.
v0.3
Added rcon password extract feature this will keep the
script running even when password has been changed
v0.2
Added search for bot players to exclude them from player
count. This way wave timers are not changing constantly
due to bots being added or removed from server
v0.1
Basic Script for determining wave respawns in relation to
player count. When player count decreases then we should
reduce the wave timers for quicker respawns. This helps
on small maps where flags can be capped fast without a
chance to prevent capture if a player dies.
"""
""" Settings """
server_ip = "127.0.0.1:27960" # IP:port of game server
server_dir = "/mnt/ramdisk/urt_ctf/q3ut4/" # Location of the servers game files
server_cfg = server_dir + "ctf_server.cfg" # Name of server configuration file
wave_low = "4" # Threshold for low player count
wave_medium = "8" # Threshold for medium player count
wave_high = "12" # Threshold for high player count
""" Import required code """
import pyquake3
import re
""" Extract the rcon password from config """
with open(server_cfg) as f:
cfg = f.read()
rconpass = re.findall('set\\s+rconpassword\\s+"([^"]*)"', cfg)[-1]
""" Connect to UrT Server """
server = pyquake3.PyQuake3(server_ip, rconpass) # Sets command up with connection details
server.update() # Issues command /rcon <rconpass> getstatus
server.rcon_update() # Issues command /rcon <rconpass> status
""" Number of humans and bots """
bots = len([player for player in server.players if player.address == "bot"]) # Bot player if IP is equal to "bot"
humans = len(server.players) - bots # Total number of player - number of bots
""" Set wave respawn times depending on player count """
if humans > int(wave_high): # If human players is 13+ set times to 15 secs
wave = "15"
elif humans > int(wave_medium): # If human players is between 8 and 12 set times to 12 secs
wave = "12"
elif humans > int(wave_low): # If human players is between 4 and 8 set times to 9 secs
wave = "9"
elif humans <= int(wave_low): # If human players is below or equal to 4 set times to 6 secs
wave = "6"
else: # if all else fails produce error
raise Exception ('Error could not determine value for wave')
""" Get the current wave times on the server """
response = server.rcon_command('g_redwave')[1] # We keep wave times for blue/red team the same so only need to check one
wave_setting = [int(s) for s in re.findall('\\d+', response)]
wave_time = wave_setting[0]
""" check if current wave times need changed """
player_list = ('\n\t'.join(player.name for player in server.players))
if wave_time != int(wave): # If the server wave timer does not match the value of wave, then update
server.rcon_command(('set g_redwave %s') % wave)
server.rcon_command(('set g_bluewave %s') % wave)
print """\
Player List:
------------
%s
number of humans: %i
number of bots: %i
Wave times have been set to %s seconds
""" % (player_list, humans, bots, wave)
else:
print """\
--------------------------------------------
wave timers do not need adjusting right now.
--------------------------------------------
Player List:
------------
%s
number of humans: %i
number of bots: %i
Wave time currently at: %s seconds
""" % (player_list, humans, bots, wave)