EntityPreHook/EntityPostHook changes
Posted: Fri Aug 07, 2015 7:59 pm
We just updated the EntityPreHook and EntityPostHook decorators. Now, you need to pass a function to the decorator that will be used to test existing and new entities whether they match the entity you are looking for or not. If the function returns True, the hook will get initialized by using the pointer of the entity.
To make things easier for you, we have defined some functions for common entities (see the EntityCondition class).
Example 1:
Example 2:This implementation allows you maximum flexibility. If you have any other methods that should be added to the EntityCondition class, feel free to post them here.
To make things easier for you, we have defined some functions for common entities (see the EntityCondition class).
Example 1:
Syntax: Select all
from entities.hooks import EntityPreHook
from entities.hooks import EntityCondition
# This hook will get initialized as soon as a player (bot or human) is found
# on the server
@EntityPreHook(EntityCondition.is_player, 'bump_weapon')
def pre_bump_weapon(args):
print(args)
Example 2:
Syntax: Select all
from entities.hooks import EntityPreHook
from entities.hooks import EntityCondition
# This hook will only get initialized when an entity was found on the server
# whose first datamap class name is "CCSPlayer" (this is actually the same
# like EntityCondition.is_human_player).
@EntityPreHook(
EntityCondition.equals_datamap_classname('CCSPlayer'), 'bump_weapon')
def pre_bump_weapon(args):
print(args)