''' Survivor Heal Shaun Hellar, 08/22/2008 A fairly simple !heal system that promotes team work. ''' import es, playerlib, gamethread, math, vecmath, usermsg ''' AddonInfo ''' info = es.AddonInfo() info['name'] = "Survivor Heal" info['version'] = "1.0" info['author'] = "Shaun Hellar" info['url'] = "http://addons.eventscripts.com/addons/view/survivorheal" info['description'] = "A teamwork oriented healing system." ''' Globals ''' gHeal_Self_Amount = 25 gHeal_Target_Amount = 40 gTeams_Allowed = '3' gHealth_Packs = 2 gCrippled = True gCrippled_Speed = '0.6' gCrippled_Health = 30 # Create dict to store user data: userdata = {} ''' Events ''' def load(): # Register the say !heal command if not es.exists('saycommand', '!heal'): es.regsaycmd('!heal', 'survivorheal/healcheck') if not es.exists('saycommand', '!healhelp'): es.regsaycmd('!healhelp', 'survivorheal/healhelp') def unload(): # Unregister the command if es.exists('saycommand', '!heal'): es.unregsaycmd('!heal') if es.exists('saycommand', '!healhelp'): es.unregsaycmd('!healhelp') def player_connect(event_var): # add player to userdata with default value False for is_healing userid = int(event_var['userid']) userdata[userid] = { 'health_packs': gHealth_Packs, 'is_healing': False, 'is_being_healed': False, } def player_disconnect(event_var): # remove player from userdata userid = int(event_var['userid']) del userdata[userid] def player_spawn(event_var): # Resupply resupply(int(event_var['userid'])) def round_start(event_var): # Send them a message es.msg('#multi', '#default You have#lightgreen %s #default health packs left this round! Type#lightgreen !healhelp #defaultfor help with health packs.' % gHealth_Packs) def player_hurt(event_var): # If crippled functionality is turned on if gCrippled == True: # If the victim was in the allowed list. if str(event_var['es_userteam']) in str(gTeams_Allowed): # If their health is below the set health limit if event_var['es_userhealth'] <= str(gCrippled_Health): # Set their movement speed to set speed limit playerlib.getPlayer(event_var['userid']).set('speed', gCrippled_Speed) ''' Functions ''' # Send the players some useful tips def healhelp(): # Store userID userid = es.getcmduserid() # Send them help messages es.tell(userid, '#multi', '#lightgreen Bind a key to say !heal') es.tell(userid, '#multi', '#lightgreen When used and targeting another player you will heal him for %s health.' % gHeal_Target_Amount ) es.tell(userid, '#multi', '#lightgreen When used without targeting another player you will heal yourself for %s.' % gHeal_Self_Amount) es.tell(userid, '#multi', '#lightgreen Get close and get your cursor in the center of your target to heal them.') # See if they are eligible to use the !heal command def healcheck(): # Store userID userid = es.getcmduserid() # If they are alive if not playerlib.getPlayer(userid).attributes['isdead']: # If their team is eligible if str(es.getplayerteam(userid)) in str(gTeams_Allowed): # Check their target target_check(userid) else: es.tell(userid, '#multi', '#lightgreen Your team is not allowed to heal.') else: es.tell(userid, '#multi', '#lightgreen You cannot heal while dead.') # Resupply the user ID with health packs and reset related playervars def resupply(userid): userid = int(userid) userdata[userid] = { 'health_packs': gHealth_Packs, 'is_healing': False, 'is_being_healed': False, } # Fancy pants math for getting angles between players def return_angle(watcher, target): wl = vecmath.vector(es.getplayerlocation(watcher)) wp = playerlib.getPlayer(watcher) tl = vecmath.vector(es.getplayerlocation(target)) line = tl - wl line['z'] = 0 viewvec = vecmath.vector(wp.get('viewvector')) viewvec['z'] = 0 return vecmath.angle(line, viewvec) # Check angles against target to see if you are facing them def is_facing(distance, userid, victim): angle = math.degrees(return_angle(userid, victim)) if distance <= 40 and 0 <= angle < 20: return 1 elif distance <= 50 and 0 <= angle < 14: return 1 elif distance <= 60 and 0 <= angle < 10: return 1 else: return 0 # Check if they have a target and pass the information onto heal() def target_check(userid): userid = int(userid) team = es.getplayerteam(userid) # If they have at least 1 health pack left if userdata[userid]['health_packs'] > 0: # If they are not healing if not userdata[userid]['is_healing']: # Get the nearest player on the same team nearest_player = playerlib.getPlayer(userid).get("closestplayer", int(team)) # If there was a target if str(nearest_player[0]) != "None": # If they are looking at their target if is_facing(nearest_player[0], userid, nearest_player[1]) and nearest_player[0] <= 200: #If the target is in range if nearest_player[0] <= 60: heal(userid, nearest_player[1]) else: es.tell(userid, '#multi', '#lightgreen You are too far from %s to heal them!' % es.getplayername(nearest_player[1])) # Player has no target else: heal(userid, userid) # Player has no target else: heal(userid, userid) else: es.tell(userid, '#multi', '#lightgreen You have no health packs left.') # Heal the target_userid def heal(userid, target_userid): # Format userIDs for use with userdata[] userid = int(userid) target_userid = int(target_userid) target = playerlib.getPlayer(target_userid) # Get if the target is already being healed if not userdata[target_userid]['is_being_healed']: # Set them to be healing/ wait 4 seconds and then set to not healing userdata[userid]['is_healing'] = True gamethread.delayed(4, set_playervar, (userid, 'is_healing', False)) # Set the target to being healed/ wait 4 seconds and set the to not being healed userdata[userid]['is_being_healed'] = True gamethread.delayed(4, set_playervar, (userid, 'is_being_healed', False)) # Record their health and name target_health = target.attributes['health'] target_name = es.getplayername(target_userid) #Immoblize the target target.set('speed', 0) # Freeze the healer/ wait 4 seconds then unfreeze es.setplayerprop(userid, "CBasePlayer.m_fFlags", 32.0) gamethread.delayed(4, es.setplayerprop, (userid, "CBasePlayer.m_fFlags", 1)) # Check if the healer is also the target if userid != target_userid: usermsg.hudhint(userid,'You are being healed by %s! '% es.getplayername(userid)) # Grab the heal amount heal_for = gHeal_Target_Amount # If they are healing themself else: target_name = "yourself!" heal_for = gHeal_Self_Amount # Send the healer messages usermsg.hudhint(userid, 'Healing %s \n=======' % target_name) gamethread.delayed(1, usermsg.hudhint, (userid, 'Healing %s\n=====' % target_name)) gamethread.delayed(2, usermsg.hudhint, (userid, 'Healing %s\n===' % target_name)) gamethread.delayed(3, usermsg.hudhint, (userid, 'Healing %s\n=' % target_name)) gamethread.delayed(4, usermsg.hudhint, (userid, 'Healing %s\nDone!' % target_name)) # After 4 seconds heal the target gamethread.delayed(4, set_healed_health, (target_userid, heal_for)) if gCrippled == True: # After 4 seconds set their speed gamethread.delayed(4, set_speed, target_userid) # Tell the target how much they have been healed for gamethread.delayed(4, es.tell, (target_userid, '#multi', '#lightgreenYou have been healed for %s' % heal_for)) # Lower the number of health_packs left. userdata[userid]['health_packs'] = (userdata[userid]['health_packs'] - 1) gamethread.delayed(4, es.tell, (userid, '#multi', '#lightgreenYou have %s health packs left.' % userdata[userid]['health_packs'])) # For use mainly in gamethread.delayed def set_playervar(userid, playervar, value): userid = int(userid) userdata[userid][playervar] = value # Heal the userid for the amount passed def set_healed_health(userid, heal_for): healed = playerlib.getPlayer(userid) healed_health = healed.attributes['health'] healed_to = healed_health + heal_for if healed_to > 100: # Set their health at 100 healed.set('health', 100) else: healed.set('health', healed_to) # Set the speed of the player depening on crippled status def set_speed(userid): user = playerlib.getPlayer(userid) health = user.attributes['health'] if health >= gCrippled_Health: user.set('speed', 1) else: user.set('speed', gCrippled_Speed)