Gungame51.core.players.Player
From GunGame5 Documentation
(Difference between revisions)
Line 33: | Line 33: | ||
* Accessing methods from [[gungame.core.players.BasePlayer|BasePlayer]]: | * Accessing methods from [[gungame.core.players.BasePlayer|BasePlayer]]: | ||
- | <source lang="python"></source> | + | <source lang="python">import es |
+ | |||
+ | from gungame.core.players import Player | ||
+ | |||
+ | def player_spawn(event_var): | ||
+ | userid = event_var['userid'] | ||
+ | |||
+ | # Get the Player() object --- Player.__init__(userid) --- requires a userid | ||
+ | myPlayer = Player(userid) | ||
+ | |||
+ | # When a player spawns, strip their weapon and give them their current | ||
+ | # level's weapon as well as message the player telling them what weapon | ||
+ | # we just gave them. | ||
+ | myPlayer.strip() | ||
+ | myPlayer.giveWeapon() | ||
+ | es.tell(userid, 'We just gave you the "%s"!' %myPlayer.getWeapon())</source> | ||
* Using the static class methods: | * Using the static class methods: |
Revision as of 05:53, 28 April 2009
Contents |
Class: Player
Module: gungame.core.players
GunGame Version: 5.1
Overview
Description
This class is intended to be used as the class container for interaction with all GunGame-based player attributes. This class forwards to the stored PlayerDict instance of the player's userid, which returns the stored player's instance of the BasePlayer class. The use of this class eases the process of interacting with players, as opposed to referring to the PlayerDict's instance containing the BasePlayer instance of the player directly.
Quick Example
- Accessing attributes from BasePlayer:
import es from gungame.core.players import Player def player_spawn(event_var): userid = event_var['userid'] # When a player spawns, echo their attributes to console # Below, we will use multiple methods to accomplish retrieving the # player's attributes. # Get the Player() object --- Player.__init__(userid) --- requires a userid myPlayer = Player(userid) # Echo the attributes es.dbgmsg(0, 'Player Userid: %s' %myPlayer.userid) es.dbgmsg(0, 'Player Level: %s' %Player(userid).level) es.dbgmsg(0, 'Player Multikill: %s' %Player(userid)['multikill']) es.dbgmsg(0, 'Player Steamid: %s' %myPlayer['steamid']) es.dbgmsg(0, 'Player Weapon: %s' %myPlayer.weapon)
- Accessing methods from BasePlayer:
import es from gungame.core.players import Player def player_spawn(event_var): userid = event_var['userid'] # Get the Player() object --- Player.__init__(userid) --- requires a userid myPlayer = Player(userid) # When a player spawns, strip their weapon and give them their current # level's weapon as well as message the player telling them what weapon # we just gave them. myPlayer.strip() myPlayer.giveWeapon() es.tell(userid, 'We just gave you the "%s"!' %myPlayer.getWeapon())
- Using the static class methods:
Methods
- __init__(userid)
Static Methods
- addAttributeCallBack(attribute, function, addon)
- removeAttributeCallBack(attribute)
- removeCallBacksForAddon(addon)
Attributes
- userid
This class allows you to both get and set attributes existing and custom attributes to the BasePlayer class. See the BasePlayer class for a list of attributes that can be used with the Player() class container.