Gungame.core.players.shortcuts.setAttribute

From GunGame5 Documentation

(Difference between revisions)
Jump to: navigation, search
Line 41: Line 41:
def player_activate(event_var):
def player_activate(event_var):
     # Set the custom attribute "myattribute" for this userid
     # Set the custom attribute "myattribute" for this userid
-
     setAttribute(event_var['userid'], 'myattribute', 'gg_sample')
+
     setAttribute(event_var['userid'], 'myattribute', 0)
def player_disconnect(event_var):
def player_disconnect(event_var):
Line 50: Line 50:
notes=* In order to effectively set a custom attribute on all players, use the [[gungame.core.players.shortcuts.setAttribute|setAttribute()]] function in your addon's load() and player_activate() functions:
notes=* In order to effectively set a custom attribute on all players, use the [[gungame.core.players.shortcuts.setAttribute|setAttribute()]] function in your addon's load() and player_activate() functions:
<source lang="python">def load():
<source lang="python">def load():
-
     setAttribute('#all', 'yourattributename', 'gg_your_addon_name')
+
     setAttribute('#all', 'yourattributename', 0)
def player_activate(event_var):
def player_activate(event_var):
-
     setAttribute(event_var['userid'], 'yourattributename', 'gg_your_addon_name')</source>|}}
+
     setAttribute(event_var['userid'], 'yourattributename', 0)</source>|}}

Revision as of 16:28, 27 April 2009



Function: setAttribute

Module: gungame.core.players.shortcuts
Class: Player
GunGame Version: 5.1

Function Overview

Table of Contents

Contents


Description

A shortcut function for Player.__setattr__ and Player.__setitem__ that allows the scripter to set a custom Player attribute on a single userid, or multiple userids using a filter as provided by playerlib.getPlayerList().

Arguments

setAttribute(filter, attribute, value)
  • filter
  • attribute
    • The str() name of the attribute
  • value
    • The value of the attribute


Examples

# ../<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 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

  • In order to effectively set a custom attribute on all players, use the setAttribute() function in your addon's load() and player_activate() functions:
def load():
    setAttribute('#all', 'yourattributename', 0)
 
def player_activate(event_var):
    setAttribute(event_var['userid'], 'yourattributename', 0)

See Also

{{{seealso}}}

Personal tools