Skip to content

Conversation

@Ayuto
Copy link
Member

@Ayuto Ayuto commented Apr 30, 2020

Generic fix for issue #236

Test code:

from memory.hooks import hooks_disabled
from entities.hooks import EntityPreHook, EntityCondition
from events import Event
from players.entity import Player

@EntityPreHook(EntityCondition.is_human_player, 'on_take_damage')
def pre_take_damage(args):
    print('take damage', args)

@Event('player_say')
def on_player_say(event):
    player = Player.from_userid(event['userid'])
    target = player.view_player
    if target is None:
        print('not a player or no target')
        return

    with hooks_disabled(event['text'] == 'yes'):
        target.take_damage(5)

When looking at a player and typing yes, the hook shouldn't get called. In all other cases the hook gets called.

@Ayuto Ayuto requested review from jordanbriere and satoon101 April 30, 2020 23:33
@Ayuto Ayuto linked an issue May 2, 2020 that may be closed by this pull request
@Ayuto Ayuto requested a review from jordanbriere May 2, 2020 09:00
@Ayuto Ayuto merged commit 7b3de7d into master May 3, 2020
@Ayuto Ayuto deleted the disable_hooks branch May 3, 2020 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

take_damage() with skip_hooks=True doesn't work as expected

3 participants