Playerlib

From EventScripts Community Encyclopedia


Module: playerlib

Module Overview

EventScripts version: 2.0.0.250a

Table of Contents

Contents


Description

Playerlib provides provides access to getting and setting player properties. It also includes some commonly used player functions.

Quick Example

Player object usage examples:

import playerlib
 
# Create a Player object
myPlayer = playerlib.getPlayer(event_var['userid'])
# Now use it to get the amount of ammo in the player's primary weapon
myAmmo = myPlayer.get('ammo', 'primary')
# and set the amount of ammo in the player's pistol clip
myPlayer.set('clip', ['secondary', '34'])
import playerlib
 
def player_hurt(event_var):
    # Make the victim pop into the air like popcorn
    victim = playerlib.getPlayer(event_var['userid'])
    victim.push(0, 700, 1))

Player Attributes:

### Contains everything from es.createplayerlist ###
 
# First, let's get their name
myname = myPlayer.name
# Now let's get their model
model = myPlayer.model
# Now let's set their model
myPlayer.model = '[path_to_model]'
# Now let's tell him what model he is
es.tell(event_var['userid'), "Hello %s your current model is: %s" % (myname, model))
# Kills
mykills = myPlayer.kills
# Deaths
mydeaths = myPlayer.deaths
# SteamID
mysteamID = myPlayer.steamid
# Teamid 0 == unassigned, 1 == Spectator, 2 == T and 3 == CT
myteam = myPlayer.teamid
# Armor
myarmor = myPlayer.armor
# Is dead 1 = dead, 0 = alive
amIdead = myPlayer.isdead
# Is bot 1 = bot, 0 = human
amIabot = myPlayer.isbot
# Am I a spectator
spectator = myPlayer.isobserver
# Health
myhealth = myPlayer.health
# Serial number
serialnumber = myPlayer.serialnumber
# Weapon returns weapon_<name>
myweapon = myPlayer.weapon
# Handle
handle = myPlayer.handle
# Ping
myping = myPlayer.ping
# Packet loss
packetloss = myPlayer.packetloss
# Time player has been connected (returns float don't know if it's in minutes or seconds please update)
timeconnected = myPlayer.timeconnected
# IP address
myIP = myPlayer.address
# X position (Pitch)
myPitch = myPlayer.x
# Y position (Yaw)
myYaw = myPlayer.y
# Z position (Roll)
myRoll = myPlayer.z

Player list usage:

import es
import playerlib
 
# Creates a list of Player objects using a filter
myPlayerList = playerlib.getPlayerList('#ct,#alive')
# Go through the players, get some attributes and print them to the chat area
for ply in myPlayerList:
    es.msg(ply.weapon)
    # Now you can get their Userid from the filtered getPlayerList
    es.tell(ply.userid, 'You are a living CT!')

getPlayerList filters:

import playerlib
 
# Saves a filter function for adding an unique filter to existing filters "#all", "#t", etc.
playerlib.registerPlayerListFilter(filtername, filterfunction)
 
# The following are some example player list filters, all are used by default:
playerlib.returnAlive(x)
playerlib.returnAll(x)
playerlib.returnBot(x)
playerlib.returnDead(x)
playerlib.returnHuman(x)
playerlib.returnTeam0(x)
playerlib.returnTeam1(x)
playerlib.returnTeam2(x)
playerlib.returnTeam3(x)
 
# Unregisters a getPlayerList filter
playerlib.unregisterPlayerListFilter(filtername)

Module Content

Classes

Methods

getPlayer(userid)
Returns a playerlib.Player instance which give access to player properties and functions
getPlayerList(filtername=None)
Returns a list of playerlib.Player instances of users who fit the filters specified by filtername. If filtername is omitted a list of playerlib.Player instances for every connected user will be returned. Default filters are: #alive, #all, #bot, #ct, #dead, #human, #spec, #t, #un
getUseridList(userspec)
If given filters, getUseridList acts similar to getPlayerList except it returns userids instead of playerlib.Player instances. If given a SteamID, userid, partial player name, or player handle getUseridList will return a list of one element if a corresponding player is found. Otherwise an empty list is returned.
nearCoord((x1, y1, z1), distance, filtername=None)
Returns a list of all players in the list returned by getPlayerList(filtername) within distance of the given coordinate.
registerPlayerListFilter(filtername, filterfunction)
Creates a new filter for getPlayerList. When used filterfunction will be called for each userid. If filterfunction returns False the given userid is removed from the player list.
uniqueid(userid, botname=False)
Returns a unique ID for the given userid. If botname is True bots will have an unique ID based on their name instead of the default BOT. Visit the ESS uniqueid page for more information: http://www.eventscripts.com/pages/Uniqueid
unregisterPlayerListFilter(filtername)
Removes a filter from getPlayerList filters.

See Also

Notes

  • Default filters for getPlayerList are the following: #alive, #all, #bot, #ct, #dead, #human, #spec, #t, #un
blog comments powered by Disqus