import es import keyvalues import os import sqlite3 info = es.AddonInfo() info.name = "Crazy Ranks 2" info.version = "1.0" info.author = "Ajurna" info.url = "http://www.unbuinc.net" info.description = "Dynamic ranks picked by you! inspired by Venjax" info.basename = "crazyranks" def config(): global crazyadvert, headscore, pelvisscore, bodyscore, armscore, legscore, punishscore, crazyranks, rankphrase #settings crazyadvert = 1 #Set to 1 to turn on Round_Start Advertisment of CrazyRanks rankphrase = '!rank' # set to what you want ppl to type in to get their rank. 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 crazyranks = {} #follow the syntax to add or change ranks crazyranks['0'] = 'n00b need more kills' crazyranks['500'] = 'Last Mate AKA n00b' crazyranks['4000'] = '2nd Pirate..' crazyranks['20000'] = '1st Pirate' crazyranks['50000'] = 'Master' crazyranks['100000'] = 'Lieutenant' crazyranks['200000'] = 'Rambo' crazyranks['400000'] = 'Insane in the Membrane' crazyranks['600000'] = 'CrAzZzY MoFo' crazyranks['800000'] = 'Cap\'n Dick Steel' crazyranks['1000000'] = 'Highest Rank |Jolly Roger|' def load(): es.setinfo('ven_crazyrank', 'V1.1') es.makepublic('ven_crazyrank') config() es.server.cmd('es_doblock corelib/noisy_on') score_file = es.getAddonPath('crazyranks') + '/crazyscore.db' if not os.path.isfile(score_file): createdb(score_file) old_scorefile = es.getAddonPath('crazyranks') + '/es_crazyscore_db.txt' if os.path.isfile(old_scorefile): importolddb(old_scorefile) else: connectdb(score_file) es.msg('crazyranks loaded') def importolddb(old_scorefile): if es.exists('keygroup', 'crazyscore'): es.keygroupdelete('crazyscore') es.keygroupload('crazyscore', '|crazyranks') oldscore = keyvalues.getKeyGroup("crazyscore") for player in oldscore: scoredb.execute('insert into crazyscore values (?,?,?)',(player.getName(),player['rank'],player['score'],)) conn.commit() es.keygroupdelete('crazyscore') 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, rank text, score 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_activate(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)',(event_var['es_steamid'],)) conn.commit() def round_start(event_var): if crazyadvert == 1: es.msg('#multi', '#default [CrazyRanks]#green Type #lightgreen'+rankphrase+'#green to check your official Pirate rank.') def player_say(event_var): if event_var['text'] == rankphrase: scoredb.execute('select * from crazyscore where steamid = ?',(event_var['es_steamid'],)) rankdata = scoredb.fetchone() es.msg(event_var['es_username']+' is ranked '+rankdata[1]+' with the score of '+rankdata[2]+' 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: rankdata = scoredb.execute('select * from crazyscore where steamid = ?',(event_var['es_steamid'],)).fetchone() myscore = int(rankdata[2]) - punishscore myrank = rankdata[1] max = 0 for rank in crazyranks: if myscore > int(rank): if int(rank) > max: max = int(rank) newrank = crazyranks.get(rank) if newrank != myrank: es.msg('#multi', '#default[CrazyRank]#green '+event_var['es_username']+' has just been demoted to#lightgreen '+newrank+'#green for committing suicide!') myrank = newrank scoredb.execute('update crazyscore set rank = ?, score = ? where steamid = ?',(myrank, myscore, event_var['es_steamid'],)) else: rankdata = scoredb.execute('select * from crazyscore where steamid = ?',(event_var['es_attackersteamid'],)).fetchone() myscore = addscore + int(rankdata[2]) myrank = rankdata[1] max = 0 newrank = str(rankcheck(myscore)) if newrank != myrank: es.msg('#multi', '#default[CrazyRank]#green '+event_var['es_attackername']+' has just been promoted to#lightgreen '+newrank+'#green!') myrank = newrank scoredb.execute('update crazyscore set rank = ?, score = ? where steamid = ?',(myrank, myscore, event_var['es_attackersteamid'],)) else: rankdata = scoredb.execute('select * from crazyscore where steamid = ?',(event_var['es_attackersteamid'],)).fetchone() myscore = int(rankdata[2]) - punishscore myrank = rankdata[1] max = 0 for rank in crazyranks: if myscore > int(rank): if int(rank) > max: max = int(rank) newrank = crazyranks.get(rank) if newrank != myrank: es.msg('#multi', '#default[CrazyRank]#green '+event_var['es_attackername']+' has just been demoted to#lightgreen '+newrank+'#green for teamkilling!') myrank = newrank scoredb.execute('update crazyscore set rank = ?, score = ? where steamid = ?',(myrank, myscore, event_var['es_attackersteamid'],)) conn.commit() def rankcheck(myscore): max = 0 for rank in crazyranks: if myscore > int(rank): if int(rank) > max: max = int(rank) newrank = crazyranks[rank] return crazyranks[str(max)]