Gungame.core.players.shortcuts.removeCallBacksForAddon

From GunGame5 Documentation

(Difference between revisions)
Jump to: navigation, search
 
(6 intermediate revisions not shown)
Line 17: Line 17:
arguments=<source lang="python">removeCallBacksForAddon(addon)</source>
arguments=<source lang="python">removeCallBacksForAddon(addon)</source>
-
* '''name'''
+
* '''addon'''
** ''The str() name of the addon.|
** ''The str() name of the addon.|
-
examples=* Deleting the attribute:
+
examples=* Removing multiple callbacks:
-
<source lang="python"># ../<MOD>/addons/eventscripts/gungame/scripts/custom/gg_sample/gg_sample.py
+
<source lang="python">from gungame.core.players.shortcuts import setAttribute
-
 
+
from gungame.core.players.shortcuts import addAttributeCallBack
-
import es
+
from gungame.core.players.shortcuts import removeAttributeCallBack
-
 
+
from gungame.core.players.shortcuts import removeCallBacksForAddon
-
from gungame.core.players.shortcuts import setAttribute
+
-
from gungame.core.players.shortcuts import deleteAttribute
+
def load():
def load():
     # Set the custom attribute "myattribute" on all connected players
     # Set the custom attribute "myattribute" on all connected players
     setAttribute('#all', 'myattribute', 0)
     setAttribute('#all', 'myattribute', 0)
 +
 +
    # Add the attribute callback
 +
    # (this will call on "callbackFunction" any time "myattribute" is set
 +
    #  via the __setitem__ or __setattr__ method)
 +
    addAttributeCallBack('myattribute', callbackFunction, 'gg_sample')
 +
 +
    # Set the custom attribute "myattribute" on all connected players
 +
    setAttribute('#all', 'anotherattribute', 0)
 +
 +
    # Add the attribute callback
 +
    # (this will call on "callbackFunction" any time "myattribute" is set
 +
    #  via the __setitem__ or __setattr__ method)
 +
    addAttributeCallBack('anotherattribute', callbackFunction, 'gg_sample')
def unload():
def unload():
 +
    '''
 +
    When you unload the custom addon, so long as the correct "addon" argument
 +
    was provided, "removeCallBackForAddons('addon_name_being_unloaded')" will be called,
 +
    which in this case will be "removeCallBackForAddon('gg_sample')". Therefore, the
 +
    following "removeAttributeCallBack('myattribute')" and "removeCallBacksForAddon('gg_sample')" is not necessary, but moreso exists for the sake of showing how to use
 +
    the function.
 +
    '''
     # Remove the custom attribute "myattribute" from all players
     # Remove the custom attribute "myattribute" from all players
-
     deleteAttribute('#all', 'myattribute')
+
     removeAttributeCallBack('myattribute')
-
def gg_start():
+
     # Remove all custom attribute callbacks for this addon
-
     # Set the custom attribute "myattribute" on all connected players
+
     removeCallBacksForAddon('gg_sample')
-
    # (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):
+
def callbackFunction(name_of_the_attribute, value_to_be_checked):
-
     # Set the custom attribute "myattribute" for this userid
+
     '''
-
     setAttribute(event_var['userid'], 'myattribute', 0)
+
    This callback function can be used for more than 1 attribute, so that you can
-
 
+
     register multiple attribute callbacks. All that you have to do is check the
-
def player_disconnect(event_var):
+
    name of the attribute (the first argument). The second argument is the value
-
     # Delete the custom attribute "myattribute" from this userid
+
    of the attribute. If you raise an error during your callback, the attribute
-
    deleteAttribute(event_var['userid'], 'myattribute')</source>|
+
    will not be set to the attempted value.
 +
    '''
 +
    if name_of_the_attribute == 'myattribute':
 +
        # Make sure the value is from 0-10
 +
        if value_to_be_checked in range(0, 11):
 +
            pass
 +
        else:
 +
            raise ValueError('Value must be between 0 and 10!')
 +
     elif name_of_the_attribute == 'anotherattribute':
 +
        # Make sure the value is from 0-5
 +
        if value_to_be_checked in range(0, 6):
 +
            pass
 +
        else:
 +
            raise ValueError('Value must be between 0 and 5!'</source>|
Line 58: Line 85:
def player_disconnect(event_var):
def player_disconnect(event_var):
-
     setAttribute(event_var['userid'], 'yourattributename')</source>
+
     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()]].
+
* Deleting an attribute 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 try to delete a custom attribute callback 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.|
+
* When any script is unloaded, [[gungame.core.players.shortcuts.removeCallBacksForAddon|removeCallBacksForAddon()]] is automatically called for the addon being unloaded.|
Line 69: Line 96:
** [[gungame.core.playersPlayer|Player]]
** [[gungame.core.playersPlayer|Player]]
** [[gungame.core.players.shortcuts.setAttribute|setAttribute]](''filter, attribute, value'')
** [[gungame.core.players.shortcuts.setAttribute|setAttribute]](''filter, attribute, value'')
 +
** [[gungame.core.players.shortcuts.deleteAttribute|deleteAttribute]](''addon'')
** [[gungame.core.players.shortcuts.addAttributeCallBack|addAttributeCallBack]](''attribute, function, addon'')
** [[gungame.core.players.shortcuts.addAttributeCallBack|addAttributeCallBack]](''attribute, function, addon'')
-
** [[gungame.core.players.shortcuts.removeAttributeCallBack|removeAttributeCallBack]](''attribute'')
+
** [[gungame.core.players.shortcuts.removeAttributeCallBack|removeAttributeCallBack]](''attribute'')|}}
-
** [[gungame.core.players.shortcuts.removeCallBacksForAddon|removeCallBacksForAddon]](''addon'')|}}
+
[http://iresearchpapers.com/ buy research paper]

Current revision as of 12:03, 26 February 2012



Function: removeCallBacksForAddon

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

Function Overview

Table of Contents

Contents


Description

A shortcut function for the static class method Player.removeCallBacksForAddon() that allows the scripter to remove all custom Player attribute callbacks that have been associated with the named addon.

Arguments

removeCallBacksForAddon(addon)
  • addon
    • The str() name of the addon.


Examples

  • Removing multiple callbacks:
from gungame.core.players.shortcuts import setAttribute
from gungame.core.players.shortcuts import addAttributeCallBack
from gungame.core.players.shortcuts import removeAttributeCallBack
from gungame.core.players.shortcuts import removeCallBacksForAddon
 
def load():
    # Set the custom attribute "myattribute" on all connected players
    setAttribute('#all', 'myattribute', 0)
 
    # Add the attribute callback
    # (this will call on "callbackFunction" any time "myattribute" is set
    #  via the __setitem__ or __setattr__ method)
    addAttributeCallBack('myattribute', callbackFunction, 'gg_sample')
 
    # Set the custom attribute "myattribute" on all connected players
    setAttribute('#all', 'anotherattribute', 0)
 
    # Add the attribute callback
    # (this will call on "callbackFunction" any time "myattribute" is set
    #  via the __setitem__ or __setattr__ method)
    addAttributeCallBack('anotherattribute', callbackFunction, 'gg_sample')
 
def unload():
    '''
    When you unload the custom addon, so long as the correct "addon" argument
    was provided, "removeCallBackForAddons('addon_name_being_unloaded')" will be called,
    which in this case will be "removeCallBackForAddon('gg_sample')". Therefore, the
    following "removeAttributeCallBack('myattribute')" and "removeCallBacksForAddon('gg_sample')" is not necessary, but moreso exists for the sake of showing how to use
    the function.
    '''
    # Remove the custom attribute "myattribute" from all players
    removeAttributeCallBack('myattribute')
 
    # Remove all custom attribute callbacks for this addon
    removeCallBacksForAddon('gg_sample')
 
def callbackFunction(name_of_the_attribute, value_to_be_checked):
    '''
    This callback function can be used for more than 1 attribute, so that you can
    register multiple attribute callbacks. All that you have to do is check the
    name of the attribute (the first argument). The second argument is the value
    of the attribute. If you raise an error during your callback, the attribute
    will not be set to the attempted value.
    '''
    if name_of_the_attribute == 'myattribute':
        # Make sure the value is from 0-10
        if value_to_be_checked in range(0, 11):
            pass
        else:
            raise ValueError('Value must be between 0 and 10!')
    elif name_of_the_attribute == 'anotherattribute':
        # Make sure the value is from 0-5
        if value_to_be_checked in range(0, 6):
            pass
        else:
            raise ValueError('Value must be between 0 and 5!'

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 will remove any custom attribute callbacks that were set by addAttributeCallBack().
  • If you try to delete a custom attribute callback that does not exist using this method, no error will be raised.
  • When any script is unloaded, removeCallBacksForAddon() is automatically called for the addon being unloaded.

See Also

buy research paper