Page 1 of 1

Hook Player Weapon Equip

Posted: Fri Apr 28, 2017 1:07 am
by decompile
Hey,
How can I hook the function when someones equipped a new weapon?

I tried it with bump_weapon and EntityPostHook but it seems like it doesnt work.

Syntax: Select all

@EntityPostHook(EntityCondition.is_player, 'bump_weapon')
def pre_bump_weapon(args):
player = memory.make_object(Entity, args[0])
weapon = memory.make_object(Entity, args[1])

Re: Hook Player Weapon Equip

Posted: Fri Apr 28, 2017 5:45 am
by Ayuto
What exactly do you want to do? Because if no hook is needed, you can also use the event item_pickup.

Re: Hook Player Weapon Equip

Posted: Fri Apr 28, 2017 8:43 am
by existenz
Hey !
Try the following code (I used a PreHook you can change to PostHook if you want):

Syntax: Select all

@EntityPreHook(EntityCondition.is_human_player, 'bump_weapon')
def _on_weapon_bump(stack):
player= make_object(Player, stack[0])
weapon = make_object(Entity, stack[1])

Re: Hook Player Weapon Equip

Posted: Fri Apr 28, 2017 8:57 am
by iPlayer
If you crash in a post-hook but everything seems to work fine in a pre-hook, this might be related.

Re: Hook Player Weapon Equip

Posted: Fri Apr 28, 2017 11:04 am
by satoon101
I am a bit confused. The thread title and first sentence of the OP reference equipping a weapon, but the code you use is for bumping into a weapon. Those are 2 totally different things.

*Edit: if you want to hook equipping, hook equip_weapon instead:
CS:S
CS:GO