Gungame.core.players.shortcuts.deleteAttribute
From GunGame5 Documentation
(Difference between revisions)
(13 intermediate revisions not shown) | |||
Line 1: | Line 1: | ||
{{Function| | {{Function| | ||
- | |||
name=deleteAttribute| | name=deleteAttribute| | ||
+ | |||
+ | |||
+ | module=gungame.core.players.shortcuts| | ||
Line 8: | Line 10: | ||
- | ggversion=5.1 | + | ggversion=5.1| |
+ | |||
+ | |||
+ | description=A shortcut function for [[gungame.core.players.Player|Player.__delattr__()]] and [[gungame.core.players.Player|Player.__delitem__()]] that allows the scripter to delete a custom [[gungame.core.players.Player|Player]] attribute on a single userid or multiple userids using a filter as provided by [http://python.eventscripts.com/pages/Playerlib#Notes playerlib.getPlayerList()].| | ||
+ | arguments=<source lang="python">deleteAttribute(filter, attribute)</source> | ||
+ | * '''filter''' | ||
+ | ** ''userid'' | ||
+ | ** ''A str() filter as used by [http://python.eventscripts.com/pages/Playerlib#Notes playerlib.getPlayerList()]'' | ||
+ | * '''attribute''' | ||
+ | ** ''The str() name of the attribute''| | ||
+ | |||
+ | |||
+ | examples=* Deleting the attribute: | ||
+ | <source lang="python"># ../<MOD>/addons/eventscripts/gungame/scripts/custom/gg_sample/gg_sample.py | ||
+ | |||
+ | import es | ||
+ | |||
+ | from gungame.core.players.shortcuts import setAttribute | ||
+ | from gungame.core.players.shortcuts import deleteAttribute | ||
+ | |||
+ | def load(): | ||
+ | # Set the custom attribute "myattribute" on all connected players | ||
+ | setAttribute('#all', 'myattribute', 0) | ||
+ | |||
+ | def unload(): | ||
+ | # Remove the custom attribute "myattribute" from all players | ||
+ | deleteAttribute('#all', 'myattribute') | ||
+ | |||
+ | def gg_start(): | ||
+ | # Set the custom attribute "myattribute" on all connected players | ||
+ | # (due to the fact that all custom player attributes are removed | ||
+ | # when the GunGame match ends, we need to re-instantiated the | ||
+ | # custom attribute "myattribute" when a new GunGame round starts) | ||
+ | setAttribute('#all', 'myattribute', 0) | ||
+ | |||
+ | def player_activate(event_var): | ||
+ | # Set the custom attribute "myattribute" for this userid | ||
+ | setAttribute(event_var['userid'], 'myattribute', 0) | ||
+ | |||
+ | def player_disconnect(event_var): | ||
+ | # Delete the custom attribute "myattribute" from this userid | ||
+ | deleteAttribute(event_var['userid'], 'myattribute')</source>| | ||
+ | |||
+ | |||
+ | notes=* If you set any custom [[gungame.core.players.Player|Player]] attributes, insure that you remove them when the player disconnects (optional) or when your addon is unloaded (required): | ||
+ | <source lang="python">def unload(): | ||
+ | deleteAttribute('#all', 'yourattributename') | ||
+ | def player_disconnect(event_var): | ||
+ | deleteAttribute(event_var['userid'], 'yourattributename')</source> | ||
+ | * Deleting an attribute using this function will remove any custom attribute callbacks that were set by [[gungame.core.players.shortcuts.addAttributeCallBack|addAttributeCallBack()]]. | ||
+ | * If you try to delete a custom attribute that does not exist using this method, no error will be raised. | ||
+ | * If you attempt to delete any required GunGame attributes, an error will be raised.| | ||
- | }} | + | seealso=* [[gungame.core.players]] |
+ | ** [[gungame.core.playersPlayer|Player]] | ||
+ | * [[gungame.core.players.shortcuts]] | ||
+ | ** [[gungame.core.playersPlayer|Player]] | ||
+ | ** [[gungame.core.players.shortcuts.setAttribute|setAttribute]](''filter, attribute, value'') | ||
+ | ** [[gungame.core.players.shortcuts.addAttributeCallBack|addAttributeCallBack]](''attribute, function, addon'') | ||
+ | ** [[gungame.core.players.shortcuts.removeAttributeCallBack|removeAttributeCallBack]](''attribute'') | ||
+ | ** [[gungame.core.players.shortcuts.removeCallBacksForAddon|removeCallBacksForAddon]](''addon'')|}} |
Current revision as of 20:52, 27 April 2009
Function: deleteAttribute
Module: gungame.core.players.shortcuts
Class: Player
GunGame Version: 5.1
Function Overview
Table of Contents
Contents |
Description
A shortcut function for Player.__delattr__() and Player.__delitem__() that allows the scripter to delete a custom Player attribute on a single userid or multiple userids using a filter as provided by playerlib.getPlayerList().
Arguments
deleteAttribute(filter, attribute)
- filter
- userid
- A str() filter as used by playerlib.getPlayerList()
- attribute
- The str() name of the attribute
Examples
- Deleting the attribute:
# ../<MOD>/addons/eventscripts/gungame/scripts/custom/gg_sample/gg_sample.py import es from gungame.core.players.shortcuts import setAttribute from gungame.core.players.shortcuts import deleteAttribute def load(): # Set the custom attribute "myattribute" on all connected players setAttribute('#all', 'myattribute', 0) def unload(): # Remove the custom attribute "myattribute" from all players deleteAttribute('#all', 'myattribute') def gg_start(): # Set the custom attribute "myattribute" on all connected players # (due to the fact that all custom player attributes are removed # when the GunGame match ends, we need to re-instantiated the # custom attribute "myattribute" when a new GunGame round starts) setAttribute('#all', 'myattribute', 0) def player_activate(event_var): # Set the custom attribute "myattribute" for this userid setAttribute(event_var['userid'], 'myattribute', 0) def player_disconnect(event_var): # Delete the custom attribute "myattribute" from this userid deleteAttribute(event_var['userid'], 'myattribute')
Notes
- If you set any custom Player attributes, insure that you remove them when the player disconnects (optional) or when your addon is unloaded (required):
def unload(): deleteAttribute('#all', 'yourattributename') def player_disconnect(event_var): deleteAttribute(event_var['userid'], 'yourattributename')
- Deleting an attribute using this function will remove any custom attribute callbacks that were set by addAttributeCallBack().
- If you try to delete a custom attribute that does not exist using this method, no error will be raised.
- If you attempt to delete any required GunGame attributes, an error will be raised.
See Also
- gungame.core.players
- gungame.core.players.shortcuts
- Player
- setAttribute(filter, attribute, value)
- addAttributeCallBack(attribute, function, addon)
- removeAttributeCallBack(attribute)
- removeCallBacksForAddon(addon)
- Forum search for Gungame.core.players.shortcuts.deleteAttribute