Hook Player Weapon Equip

Please post any questions about developing your plugin here. Please use the search function before posting!
decompile
Senior Member
Posts: 416
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

Hook Player Weapon Equip

Postby decompile » Fri Apr 28, 2017 1:07 am

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])
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Hook Player Weapon Equip

Postby Ayuto » Fri Apr 28, 2017 5:45 am

What exactly do you want to do? Because if no hook is needed, you can also use the event item_pickup.
existenz
Senior Member
Posts: 111
Joined: Thu Feb 09, 2017 3:33 pm
Location: France
Contact:

Re: Hook Player Weapon Equip

Postby existenz » Fri Apr 28, 2017 8:43 am

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])
User avatar
iPlayer
Developer
Posts: 590
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Re: Hook Player Weapon Equip

Postby iPlayer » Fri Apr 28, 2017 8:57 am

If you crash in a post-hook but everything seems to work fine in a pre-hook, this might be related.
Image /id/its_iPlayer
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam

Hail, Companion. [...] Hands to yourself, sneak thief. Image
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: Hook Player Weapon Equip

Postby satoon101 » Fri Apr 28, 2017 11:04 am

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
Image

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 33 guests