EntityPreHook 'bump_weapon'

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

EntityPreHook 'bump_weapon'

Postby BackRaw » Sat Jun 13, 2015 5:26 pm

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
My Github repositories:

Source.Python: https://github.com/backraw
User avatar
satoon101
Project Leader
Posts: 2698
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sat Jun 13, 2015 5:34 pm

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.
Image
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Postby BackRaw » Sat Jun 13, 2015 9:55 pm

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
My Github repositories:

Source.Python: https://github.com/backraw
User avatar
Doldol
Senior Member
Posts: 200
Joined: Sat Jul 07, 2012 7:09 pm
Location: Belgium

Postby Doldol » Sun Jun 14, 2015 6:08 pm

Why not abstract it like with CommandReturn.BLOCK, etc?

I think that would make it more obvious to people.
User avatar
satoon101
Project Leader
Posts: 2698
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sun Jun 14, 2015 6:14 pm

Image
User avatar
Doldol
Senior Member
Posts: 200
Joined: Sat Jul 07, 2012 7:09 pm
Location: Belgium

Postby Doldol » Sun Jun 14, 2015 6:40 pm



Is the same philosophy then not also applicable to CommandReturn?
User avatar
satoon101
Project Leader
Posts: 2698
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Mon Jun 15, 2015 1:38 am

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.
Image
User avatar
L'In20Cible
Project Leader
Posts: 1534
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Mon Jun 15, 2015 4:43 pm

Well, I think the block/continue concept doesn't apply for hooked functionsfunctions. In fact, you simply override the returned value or not.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 63 guests