Page 1 of 1

EntityPreHook 'bump_weapon'

Posted: Sat Jun 13, 2015 5:26 pm
by BackRaw
No matter what I return (True or False), the player won't pick up the bumped weapon

Syntax: Select all

from memory.hooks import EntityPreHook 

@EntityPreHook('player', 'bump_weapon')
def pre_bump_weapon(args):
"""Gets called when a player walks onto a weapon."""
# Get the entity's Entity instance
player = Player(index_from_pointer(args[0]))

# do something with the player

return True # or False - same result

Posted: Sat Jun 13, 2015 5:34 pm
by satoon101
You don't return anything (or return None) if you don't want to block the function.

Also, just so you know, in the next release, EntityPreHook and EntityPostHook will be in entities.hooks.

Posted: Sat Jun 13, 2015 9:55 pm
by BackRaw
satoon101 wrote:You don't return anything (or return None) if you don't want to block the function.

Also, just so you know, in the next release, EntityPreHook and EntityPostHook will be in entities.hooks.


Aaaaaaahhh, that makes sense now. :D

Posted: Sun Jun 14, 2015 6:08 pm
by Doldol
Why not abstract it like with CommandReturn.BLOCK, etc?

I think that would make it more obvious to people.

Posted: Sun Jun 14, 2015 6:14 pm
by satoon101

Posted: Sun Jun 14, 2015 6:40 pm
by Doldol


Is the same philosophy then not also applicable to CommandReturn?

Posted: Mon Jun 15, 2015 1:38 am
by satoon101
Well, the two are quite different. With commands you either want to block or continue. In fact, the only way to block is to return a False value. None or True type (or, since None, not returning anything) values will result in the command continuing.

With hooked functions, any type of value can be returned. The return value is more specific than simply continue or block. So, only returning None (or returning no value at all) is the only way to "continue". That being said, we "could" have a value for continuing that is "is" None, but there is no possible way to have a HookAction.BLOCK, as that value could be anything. That is, unless we required 2 return values, but what would be the point in that. I think proper documentation will help make this clear to everyone what is expected within a hooked function.

Posted: Mon Jun 15, 2015 4:43 pm
by L'In20Cible
Well, I think the block/continue concept doesn't apply for hooked functionsfunctions. In fact, you simply override the returned value or not.