def getViewCoords(userid, mask=0xFFFFFFFF, collisiongroup=0): player = playerlib.getPlayer(userid) startvec = player.getEyeLocation() # Create start and end vector pointers pStart = createVector(*startvec) pEnd = createVector(*list(Vector(startvec) + Vector(player.viewvector) \ * MAX_COORD_RANGE)) # Allocate space for the CGameTrace object ptr = spe.alloc(SIZE_TRACE_T) # Call UTIL_TraceLine() spe.call('TraceLine', pStart, pEnd, mask, spe.getPlayer(int(userid)), collisiongroup, ptr) # Wrap the end vector... x = spe.makeObject('Vector', ptr + 12) # ... and save the result result = x.x, x.y, x.z # Deallocate reserved space spe.dealloc(pStart) spe.dealloc(pEnd) spe.dealloc(ptr) # Finally, return the result return result
def getWeaponDict(userid): # Make sure the player is valid if not spe.getPlayer(int(userid)): # Return None due to the invalid player instance return None # Set up the list weapons = {} # Loop through the maximum range of 48 weapons for i in range(0, 48): # Retrieve the weapon instance/pointer wPointer = spe.getWeaponFromSlot(userid, i) # Make sure the weapon instance/pointer is valid if wPointer: # Create the valid key:value pair weapons[spe.getEntityClassName(wPointer)] = { "instance": wPointer, "slot": i, "index": spe.getEntityIndex(wPointer) } # Return the populated dictionary return weapons
def getWeaponDict(userid): # Make sure the player is valid if not spe.getPlayer(int(userid)): # Return None due to the invalid player instance return None # Set up the list weapons = {} # Loop through the maximum range of 48 weapons for i in range(0, 48): # Retrieve the weapon instance/pointer wPointer = spe.getWeaponFromSlot(userid, i) # Make sure the weapon instance/pointer is valid if wPointer: # Create the valid key:value pair weapons[spe.getEntityClassName(wPointer)] = { "instance": wPointer, "slot": i, "index": spe.getEntityIndex(wPointer)} # Return the populated dictionary return weapons
def getWeaponIndexList(userid): # Make sure the player is valid if not spe.getPlayer(int(userid)): # Return None due to the invalid player instance return None # Return a list of weapon indexes return [spe.getEntityIndex(i) for i in spe.getWeaponInstanceList(userid)]
def give(users, entity): '''Give a entity to a player...''' # Loop through all matching players... for userid in _get_matching_players(users): # Give the entity... spe.call('GiveNamedItem', spe.getPlayer(userid), entity, -0)
def ownsWeapon(userid, weapon_name): # Get player instance pPlayer = spe.getPlayer(int(userid)) if not pPlayer: return None # Call function and return weapon instance return spe.call("OwnsWeapon", pPlayer, weapon_name, 0)
def getWeaponFromSlot(userid, weapon_slot): # Get player instance pPlayer = spe.getPlayer(int(userid)) if not pPlayer: return None # Call function and return player weapon instance return spe.call("GetWeapon", pPlayer, int(weapon_slot))
def giveNamedItem(userid, item_name): # Get the player instance pPlayer = spe.getPlayer(int(userid)) # Is the player instance valid? if not pPlayer: # Return None since the player instance was not valid return None # Give the player the item return spe.call('GiveNamedItem', pPlayer, str(item_name), 0)
def getActiveWeapon(userid): # Get the player instance pPlayer = spe.getPlayer(int(userid)) # Is the player instance valid? if not pPlayer: # Return None since the player instance was not valid return None # Call and return player's active weapon return spe.call("GetActiveWeapon", pPlayer)
def radioIcon(users, fDelay, userid, queue=True): ''' Creates an exclamation mark above the player's head. ''' if not es.exists('userid', userid): return player = spe.getPlayer(int(userid)) QueueSystem.add(spe.call, ('RadioIcon', IRecipientFilter(users), fDelay, player), queue)
def __new__(cls, users): ''' Adds all given users to the new created pointer. ''' pointer = spe.alloc(40) spe.call('RecipientFilterConst', pointer) for userid in getUsers(users): player = spe.getPlayer(userid) spe.call('AddRecipient', pointer, player) return super(cls, cls).__new__(cls, pointer)
def removeWeapon(users, weapon): '''Remove a player weapon...''' # Loop through all matching players... for userid in _get_matching_players(users): # Is the player dead? if es.getplayerprop(userid, 'CBasePlayer.pl.deadflag'): # Don't go further... continue # Is the given weapon an integer? if str(weapon).isdigit(): # Get the weapon by its slot... pWeapon = spe.call( 'GetWeapon', spe.getPlayer(userid), int(weapon)) # Otherwise... else: # Is the weapon not starting by 'weapon_'? if not str(weapon).lower().startswith('weapon_'): # Add the 'weapon_' prefix... weapon = 'weapon_' + weapon # Get the weapon by its name... pWeapon = spe.call( 'OwnsWeapon', spe.getPlayer(userid), str(weapon), 0) # Is the weapon not valid? if not pWeapon: # Don't go further... continue # Remove the weapon... spe.call('Remove', pWeapon)
def respawn(userid): # Get the player instance pPlayer = spe.getPlayer(int(userid)) # Make sure the player instance is valid if not pPlayer: # Return False since the player instance was not valid return False # Respawn the player spe.call("Respawn", pPlayer) return True
def switchTeam(userid, team_index): # Get the player instance pPlayer = spe.getPlayer(int(userid)) # Is the player instance valid? if not pPlayer: # Return False since the player instance was not valid return False # Switch their team spe.call("ChangeTeam", pPlayer, int(team_index)) return True
def spawn(users, force_respawn=False): '''Respawn a player...''' # Loop through all matching players... for userid in _get_matching_players(users): # Get the player's dead state... isdead = es.getplayerprop(userid, 'CBasePlayer.pl.deadflag') # Does we need to respawn the player? if force_respawn or isdead: # Respawn the player... spe.call('Respawn', spe.getPlayer(userid))
def changeTeam(users, teamid): '''Switch a player to the given team...''' # Format the given team... teamid = str(teamid).lower() # Is the team not valid? if not g_TeamIndexes.has_key(teamid): # Don't go further... return # Loop through all matching players... for userid in _get_matching_players(users): # Switch the player... spe.call('ChangeTeam', spe.getPlayer(userid), g_TeamIndexes[teamid])
def setClanTag(userid, clan_tag): MAX_SIZE = 64 length = len(clan_tag) if length >= MAX_SIZE: raise ValueError('Clan tag is too long') player = spe.getPlayer(userid) if not player: raise ValueError('Could not find player pointer') for offset, char in enumerate(clan_tag): spe.setLocVal('i', player + clantag_offset + offset, ord(char))
def getViewEntity(userid): '''Get the entity a player is looking at...''' # Is the player not valid? if not es.exists('userid', userid): # Don't go further... return None # Get the entity pointer... pEntity = spe.call('FindPickerEntity', spe.getPlayer(int(userid))) # Is the entity not valid? if not pEntity: # Don't go further... return None # Return the entity index... return spe.getEntityIndex(pEntity)
def getWeaponInstanceList(userid): # Make sure the player is valid if not spe.getPlayer(int(userid)): # Return None due to the invalid player instance return None # Set up the list weapon_pointers = [] # Loop through the maximum range of 48 weapons for i in range(0, 48): # Retrieve the weapon instance/pointer wPointer = spe.getWeaponFromSlot(userid, i) # Make sure the weapon instance/pointer is valid if wPointer: # Append the valid instance/pointer to the list weapon_pointers.append(wPointer) # Return the populated list return weapon_pointers
def dropWeapon(userid, weapon_name, throwWeapon=True): # Get the player instance pPlayer = spe.getPlayer(int(userid)) # Is the player instance valid? if not pPlayer: # Return False since the player instance was not valid return False # Get the weapon instance weapon_instance = spe.ownsWeapon(userid, weapon_name) # Is the weapon instance valid? if not weapon_instance: # Return False since the weapon instance was not valid return False # Throw the weapon? if throwWeapon: return spe.call('DropWeapon', pPlayer, weapon_instance, 0, 1) # Otherwise, don't. return spe.call('DropWeapon', pPlayer, weapon_instance, 0, 0)
def test(): for userid in es.getUseridList(): if es.isbot(userid): spe.call("NHide", spe.getPlayer(userid), -1, 9999, 1)
def OnTick(): for i in amounts: if i not in parachuted and not es.getplayerprop(i, "CBasePlayer.pl.deadflag") and spe.getLocVal("i", spe.getPlayer(i) + buttonPressedOffset) & 32 and es.getplayerprop(i, "CBasePlayer.localdata.m_Local.m_flFallVelocity") >= 1.0 and amounts[i] > 0: index = es.createentity("prop_dynamic_override") parachuted[i] = index es.entitysetvalue(index, "solid", 0) es.entitysetvalue(index, "model", random.choice(rpgParachuteModels)) es.server.insertcmd("es_xspawnentity %i" % index) amounts[i] -= 1 for i in parachuted.copy(): if not es.exists("userid", i) or es.getplayerprop(i, "CBasePlayer.pl.deadflag") or es.getplayerprop(i, "CBasePlayer.localdata.m_hGroundEntity") != -1 or es.getplayerprop(i, "CBasePlayer.localdata.m_nWaterLevel") > 1 or not spe.getLocVal("i", spe.getPlayer(i) + buttonPressedOffset) & 32: spe.removeEntityByIndex(parachuted[i]) del parachuted[i] else: es.entitysetvalue(parachuted[i], "angles", "0 %f 0" % es.getplayerprop(i, "CCSPlayer.m_angEyeAngles[1]")) es.entitysetvalue(parachuted[i], "origin", es.getplayerprop(i, "CBaseEntity.m_vecOrigin").replace(",", " ")) es.setplayerprop(i, "CBasePlayer.localdata.m_vecBaseVelocity", "0,0,%f" % es.getplayerprop(i, "CBasePlayer.localdata.m_Local.m_flFallVelocity"))
def get_userid_from_pointer(ptr): for userid in es.getUseridList(): if spe.getPlayer(userid) == ptr: return userid return -1