ratio = {} # Ignore me!
################################################################################
############# CONFIG SECTION #############
################################################################################
balance_type = 'number'
'''
By what means should teams be balanced?
Valid arguments are:
number - Have a set maximum of terrorists
ratio - Have a set ratio of terrorist/Counter-terrorists
'''
max_t = 1 # If you selected number above, how many terrorists can there be at any one point?
# If balancing by ratio....
ratio['t'] = 1 # x terrorists for...
ratio['ct'] = 19 # every y Counter-Terrorists
t_cycle = 'death'
'''
This option enables the terrorist position to be cycled
When it cycles is up to you
death - When a CT kills the T
rounds - After a certain number of rounds
never - DR Manager will not cycle the T position
'''
t_rounds = 2 # If using 'rounds' for Terrorist cycle, how many rounds will each T get?
punishment = ['ct', 'warn']
'''
When a player joins T and there is no position for them, how should the manager deal with them
Seperate arguments with a ,
Valid arguments are:
ct - swap player to CT
spec - set player as spectator
warn - display a warning in chat
'''
# Please note - If any of your settings are invalid, default values will be applied
################################################################################
############# END CONFIG SECTION #############
############# EDITING BELOW THIS LINE IS NOT RECCOMENDED #############
################################################################################
t_ratio = float(ratio['t'])/float(ratio['ct'])
rounds = 0
import es, playerlib, random
info = es.AddonInfo()
info.name = "DeathRun Manager"
info.version = "1.1.2"
info.url = "http://forums.mattie.info/cs/forums/viewtopic.php?t=26085"
info.basename = "dr_manager"
info.author = "Master AKA DanielB"
es.ServerVar('drm_ver', info.version, 'DeathRun Team Balance and Team Cycle').makepublic()
def msg(text):
es.msg('#multi', '#green[DR Manager]#lightgreen ' + text)
def tell(userid, text):
es.tell(userid, '#multi', '#green[DR Manager]#lightgreen ' + text)
def check_cfg():
if not balance_type.lower() in ['number', 'ratio']:
global balance_type
balance_type = 'number'
msg('Error in config - Deafult Balance set (Number)')
if not t_cycle.lower() in ['death', 'rounds', 'never']:
global t_cycle
t_cycle = 'death'
msg('Error in config - Deafult Cycle set (Death)')
if t_rounds < 1:
global t_rounds
t_rounds = 10
msg('Error in config - T Cycle Rounds set (10)')
def load():
msg('Loaded')
#es.regcmd('drm', 'dr_manager/drm', 'Control/Configure Death Run Manager')
check_cfg()
check()
es.regsaycmd('!drinfo', 'dr_manager/pInfo', 'Print Information')
master_mods()
def kill():
tell(es.cmdgetuserid(), 'Suicide has been disabled')
def unload():
msg('Unloaded')
def player_team(ev):
if not int(ev['disconnect']):
if ev['team'] == '2':
balance_by(ev['userid'], balance_type)
if ev['team'] == '3':
if int(es.getplayercount('3')) == 0:
userid = random.choice(playerlib.getUseridList('#ct'))
changeteam(userid, '2')
tell(userid, 'You have been swapped to T becuase the team was empty!')
def round_end(ev):
if t_cycle == 'rounds':
global rounds
rounds += 1
ts = playerlib.getUseridList('#t')
for i in ts:
tell(i, 'You have %s rounds left as a terrorist'%(t_rounds-rounds))
if rounds >= t_rounds:
rounds = -1
for i in ts:
changeteam(i, '3')
tell(i, 'You have been swapped to CT (Turn as T over)')
check()
def player_death(ev):
if t_cycle == 'death':
if ev['es_userteam'] == '2':
if ev['es_attackerteam'] == '3':
changeteam(ev['userid'], '3')
es.tell(ev['userid'], 'You were killed by a CT, now you must join them!')
def check():
if balance_type == 'number':
ts = int(es.getplayercount('2'))
if ts > max_t:
userid = random.choice(playerlib.getUseridList('#t'))
changeteam(userid, '3')
tell(userid, 'You have been moved to CT to maintain balance')
check()
elif balance_type == 'ratio':
if getRatio() > t_ratio:
userid = random.choice(playerlib.getUseridList('#t'))
changeteam(userid, '3')
tell(userid, 'You have been moved to CT to maintain balance')
check()
def changeteam(userid, teamid):
es.server.queuecmd('es_changeteam %s %s'%(userid, teamid))
def balance_by(userid, btype):
ts = int(es.getplayercount('2'))
cts = int(es.getplayercount('3'))
if ts > 1:
if btype == 'number':
if ts > max_t:
punish(userid)
elif btype == 'ratio':
if getRatio() > t_ratio:
punish(userid)
def punish(userid):
if 'ct' in punishment:
changeteam(userid, '3')
if 'spec' in punishment:
changeteam(userid, '1')
if 'warn' in punishment:
tell(userid, 'There are already enough terrorists at the moment, thankyou')
def getRatio():
return float(es.getplayercount('2'))/float(es.getplayercount('3'))
def echo(userid, text):
es.cexec(userid, 'echo %s'%text)
def pInfo():
userid = es.getcmduserid()
echo(userid, '[DeathRun Manager Info]')
echo(userid, '~ Scripted by DanielB ~')
echo(userid, 'Balancing by : %s'%balance_type)
if balance_type == 'number':
echo(userid, '~~~~Maximum Ts : %s'%max_t)
else:
echo(userid, '~~~~Ratio : %s-%s'%(ratio['t'],ratio['ct']))
echo(userid, '~~~~~~~~== %s'%t_ratio)
echo(userid, 'Cycling by : %s'%t_cycle)
if t_cycle == 'rounds': echo(userid, '~~~~Max rounds : %s'%t_rounds)
def master_mods():
if int(es.exists('variable', 'danielb_mod_count')):
# If my variable exists
var = es.ServerVar('danielb_mod_count')
var.set(int(var)+1)
else:
var = es.ServerVar('danielb_mod_count')
var.set(1)
var.makepublic()
def unload():
var = es.ServerVar('danielb_mod_count')
var.set(int(var)-1)
'''
# This is in dev.....
# will be added/completed soon
def drm():
cmd = es.getargv(1)
userid = es.getcmduserid()
if cmd == 'set':
arg = es.getargv(2).lower()
val = es.getargv(3).lower()
if arg == 'btype':
if val in ['number', 'ratio']:
global balance_type
balance_type = val
else:
tell(userid, 'That value is invalid')
if arg == 'cycle':
if val in ['death', 'rounds', 'never']:
global t_cycle
t_cycle = val
else:
tell(userid, 'That value is invalid')
else:
tell(userid, 'That value is invalid')
'''