Skip to content

Added the ability to disable hooks#326

Merged
Ayuto merged 3 commits into
masterfrom
disable_hooks
May 3, 2020
Merged

Added the ability to disable hooks#326
Ayuto merged 3 commits into
masterfrom
disable_hooks

Conversation

@Ayuto

@Ayuto Ayuto commented Apr 30, 2020

Copy link
Copy Markdown
Member

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
Comment thread src/core/modules/memory/memory_hooks.cpp Outdated
@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

2 participants