import es, gamethread, usermsg, playerlib from math import sqrt #settings initial_message = 1 #flash gordon fg_interval = 0.01 groundbarrier = 285 #barrier for ground speed correction (scout reaches about 280) antispeedstrength = 1 #strength of correction on ground, has to be > 0 and < groundbarrier #superman airbarrier = 277 #barrier for in-air speed antiflystrength = 10 #strength of in-air correction, has to be > 0 and < aribarrier. lesser value means stronger correction #hud hudenable = 0 info = es.AddonInfo() info.name = "referee" info.version = "1.5" info.author = "man in black" info.url = "www.eyesonic.net" info.description = "measures jumps, speed, reports anomalies, intervenes" #make plugin public or hide it by commenting out referee = es.ServerVar("referee",info.version).makepublic() def player_activate(event_var): if initial_message == 1: playername = es.getplayername(event_var['userid']) es.msg('#multi','#lightgreen%s is observed by #greenREFEREE %s #lightgreen(bhop,speed).' % (playername,info.version)) #create dictionaries speeddic = {} airdic = {} #dictionary to turn off measurement at round end offdic = {} def player_spawn(event_var): steamid = event_var['es_steamid'] userid = event_var['userid'] #add/alter player to dictionaries coordinates = es.getplayerlocation(userid) x1 = coordinates[0] y1 = coordinates[1] #fill dictionaries airdic[userid] = 0 speeddic[userid] = 1 offdic[userid] = 0 anti_flashgordon(userid) if hudenable == 1: hud_loop(x1,y1,userid) #hud def hud_loop(x1,y1,userid): x = es.getplayerprop(userid,'CBasePlayer.localdata.m_vecVelocity[0]') y = es.getplayerprop(userid,'CBasePlayer.localdata.m_vecVelocity[1]') velocity = sqrt(x**2 + y**2) new_coordinates = es.getplayerlocation(userid) x2 = new_coordinates[0] y2 = new_coordinates[1] z = new_coordinates[2] distance = sqrt((x2 - x1)**2 + (y2 - y1)**2) speed = distance / (0.1) ispeed = int(speed) airstatus = airdic[userid] speedstatus = speeddic[userid] usermsg.hudhint(userid, "flag: %.2f vector: %.2f \n in-air: %s \n speeddic: %s \n height: %.2f" % (velocity,ispeed,airstatus,speedstatus,z)) #continue loop gamethread.delayed(0.1,hud_loop,(x2,y2,userid)) #this function calculates the vector which slows the player down def calc_correction_vector(x,y,speed,strength): if x == 0 or y == 0: if x == 0: xcor = 0 if y > 0: ycor = y - (speed - strength) if y < 0: ycor = y - (speed + strength) elif y == 0: ycor = 0 if x > 0: xcor = x - (speed - strength) if x < 0: xcor = x - (speed + strength) else: xn = abs(x) # >0 (1) yn = abs(y) # >0 (2) vecratio = xn/yn # >0 because of 1 and 2 (3) corrvec = speed - strength #has to be > 0 by definition (4) xcalc = corrvec/(1+(1/vecratio)) ycalc = xcalc/vecratio #because the vector is added, it has to be opposite direction of original vector if x > 0: xcor = xcalc *(-1) if x < 0: xcor = xcalc if y > 0: ycor = ycalc *(-1) if y < 0: ycor = ycalc #create vector string for treatment v = es.createvectorstring(xcor,ycor,0) return v #ground speed intervention def anti_flashgordon(userid): fgordon = es.getplayername(userid) x = es.getplayerprop(userid, 'CBasePlayer.localdata.m_vecVelocity[0]') y = es.getplayerprop(userid,'CBasePlayer.localdata.m_vecVelocity[1]') speedflag = sqrt(x**2 + y**2) #if player is on ground (but not landing) begin intervention if speeddic[userid] == 1: #above groundbarrier slow player down if speedflag > groundbarrier: v = calc_correction_vector(x,y,speedflag,antispeedstrength) es.setplayerprop(userid,'CBasePlayer.localdata.m_vecBaseVelocity', v) if not playerlib.getPlayer(userid).get('isdead'): usermsg.echo('#all', "%s imitated FLASH GORDON and was beaten by batman. (speed: %.2f)" % (fgordon,speedflag)) #continue loop gamethread.delayed(fg_interval,anti_flashgordon,(userid)) #if player falls down without jumping fgordon has to pause def player_air(event_var): userid = event_var['userid'] #flag player as in-air airdic[userid] = 1 #disable fgordon speeddic[userid] = 0 #read location takeoff_loc = es.getplayerlocation(userid) xa = takeoff_loc[0] ya = takeoff_loc[1] za = takeoff_loc[2] #launch intervention anti_superman(userid,za) def player_jump(event_var): userid = event_var['userid'] speeddic[userid] = 0 #anti bhop def anti_superman(userid,z): superman = es.getplayername(userid) current_loc = es.getplayerlocation(userid) z2 = current_loc[2] vel_x = es.getplayerprop(userid, 'CBasePlayer.localdata.m_vecVelocity[0]') vel_y = es.getplayerprop(userid,'CBasePlayer.localdata.m_vecVelocity[1]') airspeedflag = sqrt(vel_x**2 + vel_y**2) z_difference = abs(z - z2) #in-air continues loop, turns off anti_flashgordon if player jumps downwards if airdic[userid] == 1: #player jumping downwards needs special treatment, flashgordon turned off due to high landing speeds #if z2 < z and z_difference > 50: # speeddic[userid] = 0 #intervention if speed is too high, falling taken out if airspeedflag > airbarrier and z2 >= z: #superman trigger feedback #es.tell(userid,'#green','superman') v = calc_correction_vector(vel_x,vel_y,airspeedflag,antiflystrength) es.setplayerprop(userid,'CBasePlayer.localdata.m_vecBaseVelocity', v) if not playerlib.getPlayer(userid).get('isdead'): usermsg.echo('#all', "%s imitated SUPERMAN and was beaten by batman. (flyspeed: %.2f)" % (superman,airspeedflag)) #continue loop gamethread.delayed(0.01,anti_superman,(userid,z)) def player_land(event_var): userid = event_var['userid'] #es.tell(userid,'#green','landing trigger successful') #deflag player airdic[userid] = 0 #reflag player onground speeddic[userid] = 1 #restart flashgordon gamethread.delayed(0.5,anti_flashgordon,userid) #calculate landing speed, for testing purposes only xl = es.getplayerprop(userid, 'CBasePlayer.localdata.m_vecVelocity[0]') yl = es.getplayerprop(userid,'CBasePlayer.localdata.m_vecVelocity[1]') landingspeed = sqrt(xl**2 + yl**2) #es.tell(userid,'#green','landing_speed: %.2f' %landingspeed) #do not measure dead players def player_death(event_var): userid = event_var['userid'] speeddic[userid] = 0 airdic[userid] = 0 #turn off at end of round def round_end(event_var): speeddic.update(offdic) airdic.update(offdic) #delete from status dic at disconnect def player_disconnect(event_var): userid = event_var['userid'] del speeddic[userid] del airdic[userid] del offdic[userid]