import es import keyvalues import os import sqlite3 info = es.AddonInfo() info.name = "Crazyranks 2 for teams!" info.version = "1.1" info.url = "http://addons.eventscripts.com/addons/view/crazyranks2teams" info.author = "Ajurna" info.basename = "crazyranks2teams" def config(): global crazyadvert, headscore, pelvisscore, bodyscore, armscore, legscore, punishscore, crazyranks, ranksaycmd #settings ranksaycmd = 'yarr' crazyadvert = 1 #Set to 1 to turn on Round_Start Advertisment of CrazyRanks headscore = 100 #Score for headshots AND knife kills pelvisscore = 25 #Pelvis/lower torso kills bodyscore = 50 #Upper body kills armscore = 10 #Arm kills legscore = 10 #Leg kills punishscore = 100 #Score to DEDUCT for TeamKills and Suicides #create top dict crazyranks = {} #create subdicts for each rank and team. crazyranks['0'] = {} crazyranks['500'] = {} crazyranks['4000'] = {} crazyranks['20000'] = {} crazyranks['50000'] = {} crazyranks['100000'] = {} crazyranks['200000'] = {} crazyranks['400000'] = {} crazyranks['600000'] = {} crazyranks['800000'] = {} crazyranks['1000000'] = {} #Terrorist ranks crazyranks['0']['2'] = 'n00b need more kills' crazyranks['500']['2'] = 'Last Mate AKA n00b' crazyranks['4000']['2'] = '2nd Pirate..' crazyranks['20000']['2'] = '1st Pirate' crazyranks['50000']['2'] = 'Master' crazyranks['100000']['2'] = 'Lieutenant' crazyranks['200000']['2'] = 'Rambo' crazyranks['400000']['2'] = 'Insane in the Membrane' crazyranks['600000']['2'] = 'CrAzZzY MoThErFuCkEr' crazyranks['800000']['2'] = 'Cap\'n Dick Steel' crazyranks['1000000']['2'] = 'Highest Rank |Jolly Roger|' #Counter-Terrorist ranks crazyranks['0']['3'] = 'n00b need more kills' crazyranks['500']['3'] = 'Last Mate AKA n00b' crazyranks['4000']['3'] = '2nd Pirate..' crazyranks['20000']['3'] = '1st Pirate' crazyranks['50000']['3'] = 'Master' crazyranks['100000']['3'] = 'Lieutenant' crazyranks['200000']['3'] = 'Rambo' crazyranks['400000']['3'] = 'Insane in the Membrane' crazyranks['600000']['3'] = 'CrAzZzY MoThErFuCkEr' crazyranks['800000']['3'] = 'Cap\'n Dick Steel' crazyranks['1000000']['3'] = 'Highest Rank |Jolly Roger|' def load(): config() es.server.cmd('es_doblock corelib/noisy_on') score_file = es.getAddonPath('crazyranks2teams') + '/crazyscoreteams.db' if not os.path.isfile(score_file): createdb(score_file) else: connectdb(score_file) es.msg('crazyranks loaded') def createdb(score_file): global conn, scoredb conn = sqlite3.connect(score_file) scoredb = conn.cursor() scoredb.execute('create table crazyscore(steamid text UNIQUE PRIMARY KEY, ctscore text, ctrank text, tscore text, trank text)') def connectdb(score_file): global conn, scoredb conn = sqlite3.connect(score_file) scoredb = conn.cursor() def unload(): es.server.cmd('es_doblock corelib/noisy_off') conn.commit() scoredb.close() conn.close() def player_spawn(event_var): scoredb.execute('select * from crazyscore where steamid = ?',(event_var['es_steamid'],)) if not scoredb.fetchone(): scoredb.execute('insert into crazyscore values (?,0,0,0,0)',(event_var['es_steamid'],)) def round_start(event_var): if crazyadvert == 1: es.msg('#multi', '#default [CrazyRanks]#green Type #lightgreen'+ranksaycmd+'#green to check your official rank.') conn.commit() def player_say(event_var): if event_var['text'] == ranksaycmd: rankdata = scoredb.execute('select * from crazyscore where steamid = ?',(event_var['es_steamid'],)).fetchone() if event_var['es_userteam'] == '2': es.msg(event_var['es_username']+' is ranked '+crazyranks[rankdata[4]][event_var['es_userteam']]+' with the score of '+rankdata[3]+' points!') elif event_var['es_userteam'] == '3': es.msg(event_var['es_username']+' is ranked '+crazyranks[rankdata[2]][event_var['es_userteam']]+' with the score of '+rankdata[1]+' points!') def player_hurt(event_var): global addscore if int(event_var['hitgroup']) < 2: addscore = headscore elif int(event_var['hitgroup']) == 2: addscore = bodyscore elif int(event_var['hitgroup']) == 3: addscore = pelvisscore elif int(event_var['hitgroup']) <= 5: addscore = armscore elif int(event_var['hitgroup']) > 5: addscore = legscore def player_death(event_var): if event_var['es_userteam'] != event_var['es_attackerteam']: if event_var['es_attackerteam'] == 0: score(event_var['es_steamid'], event_var['es_userteam'], event_var['es_username'], 1) else: score(event_var['es_attackersteamid'], event_var['es_attackerteam'], event_var['es_attackername'], 0) else: score(event_var['es_attackersteamid'], event_var['es_attackerteam'], event_var['es_attackername'], 1) def score(steamid, team, name, type):#type 0 for award, 1 for punish rankdata = scoredb.execute('select * from crazyscore where steamid = ?',(steamid,)).fetchone() if team == '2': if type == 0: myscore = addscore + int(rankdata[3]) else: myscore = int(rankdata[3]) - punishscore myrank = rankdata[4] else: if type == 0: myscore = addscore + int(rankdata[1]) else: myscore = int(rankdata[1]) - punishscore myrank = rankdata[2] newrank = rankcheck(myscore) if newrank != myrank: if type == 0: es.msg('#multi', '#default[CrazyRank]#green '+name+' has just been promoted to#lightgreen '+crazyranks[newrank][team]+'#green!') else: es.msg('#multi', '#default[CrazyRank]#green '+name+' has just been demoted to#lightgreen '+crazyranks[newrank][team]+'#green!') myrank = newrank if team == '2': scoredb.execute('update crazyscore set trank = ?, tscore = ? where steamid = ?',(myrank, myscore, steamid,)) else: scoredb.execute('update crazyscore set ctrank = ?, ctscore = ? where steamid = ?',(myrank, myscore, steamid,)) def rankcheck(myscore): max = 0 for rank in crazyranks: if myscore > int(rank): if int(rank) > max: max = int(rank) return str(max)