Playerlib

From EventScripts Community Encyclopedia
This article is a stub. Please help by adding to it.


Module: PlayerLib

Module Overview

EventScripts version: 2.0 or greater

Table of Contents

Contents


Description

Playerlib provides extensive access to players, including setting and getting player attributes, and lots more.

Quick Example

Player object usage examples:

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

Player Attributes:

# First, let's get their name
myname = myPlayer.attributes['name']
# Now let's get their model
model = myPlayer.attributes['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.attributes['kills']
# Deaths
mydeaths = myPlayer.attributes['deaths']
# SteamID
mysteamID = myPlayer.attributes['steamid']
# Teamid 0 == unassigned, 1 == Spectator, 2 == T and 3 == CT
myteam = myPlayer.attributes['teamid']
# Armor
myarmor = myPlayer.attributes['armor']
# Is dead 1 = dead, 0 = alive
amIdead = myPlayer.attributes['isdead']
# Is bot 1 = bot, 0 = human
amIabot = myPlayer.attributes['isbot']
# Am I a spectator
spectator = myPlayer.attributes['isobserver']
# Health
myhealth = myPlayer.attributes['health']
# Serial number (I don't know what it is though)
serialnumber = myPlayer.attributes['serialnumber']
# Weapon returns weapon_<name>
myweapon = myPlayer.attributes['weapon']
# Handle (I don't know what this is either)
handle = myPlayer.attributes['handle']
# Ping
myping = myPlayer.attributes['ping']
# Packet loss
packetloss = myPlayer.attributes['packetloss']
# Time player has been connected (returns float don't know if it's in minutes or seconds please update)
timeconnected = myPlayer.attributes['timeconnected']
# IP address
myIP = myPlayer.attributes['address']
# X position (Pitch)
myPitch = myPlayer.attributes['x']
# Y position (Yaw)
myYaw = myPlayer.attributes['y']
# Z position (Roll)
myRoll = myPlayer.attributes['z']

Player list usage:

# Create a PlayerList object using a filter
myPlayerList = playerlib.getPlayerList('#ct,#alive')
# Go through it and get some attributes and print them to the chat area
for ply in myPlayerList:
        es.msg(ply.attributes['weapon'])
        # Now you can get their Userid from the filtered getPlayerList
        es.tell(ply.userid, 'You are a living CT!')

Module Content

Classes

playerlib.Player -- player wrapper that lets you do important things.

Methods

getPlayer(userid)
    Returns a playerlib.Player object for the given userid.

getPlayerList(filtername=None)
    Retrieves a list of Player objects. Allows you to provide a filtername to filter the results by.

getUseridList(userspec)
    getUseridList returns either a list of filtered players or a userid
    if used with a partial name or exact steamid

registerPlayerListFilter(filtername, filterfunction)
    # allow them to save a a filter function for things like "#all", "#t", etc.

# The following are some example player list filters:
returnAlive(x)
returnAll(x)
returnBot(x)
returnDead(x)
returnHuman(x)
returnTeam0(x)
returnTeam1(x)
returnTeam2(x)
returnTeam3(x)

# see uniqueid on http://www.eventscripts.com
uniqueid(userid, botname=None)

# delete a playerlist
unregisterPlayerListFilter(filtername)

See Also

  • Visit playergetset documentation for more information on attributes and items supported by this.

Notes

  • Default filters for getPlayerList are the following: '#alive', '#all', '#bot','#ct','#dead','#human','#spec','#t','#un'
  • TODO: Please replace this with real documentation:
 [14:56]	<Mattie>	myplayer.attributes contains everything from es_createplayerlist
 [14:56]	<Mattie>	kills and deaths are there
 [14:57]	<Mattie>	http://www.eventscripts.com/pages/Es_createplayerlist
 [14:57]	<Mattie>	So it would be
 [14:57]	<Mattie>	myplayer = playerlib.getPlayer(userid)
 [14:57]	<Mattie>	mykills = myplayer.attributes['kills']
 [14:57]	<Mattie>	But you can't set them, only get them
 [14:57]	<Mattie>	mydeaths = myplayer.attributes['deaths']
blog comments powered by Disqus