weapon_fire event on leftclick
weapon_fire event on leftclick
is there a way to see if a player has used rightclicked knifeattack? weapon_fire e.g. only registers the leftclick attack.
- L'In20Cible
- Project Leader
- Posts: 1536
- Joined: Sat Jul 14, 2012 9:29 pm
- Location: Québec
Re: weapon_fire event on leftclick
The function you want to hook is CBaseCombatWeapon::SecondaryAttack.
Re: weapon_fire event on leftclick
CKnife::PrimaryAttack and CKnife::SecondaryAttack are already included in our entity data. However, I am going to change it so that we include CBaseCombatWeapon::PrimaryAttack and CBaseCombatWeapon::SecondaryAttack instead. Either way, this should work fine for you:
Also, I moved this to a more appropriate forum.
Syntax: Select all
from entities.hooks import EntityCondition, EntityPreHook
is_knife = EntityCondition.equals_entity_classname('weapon_knife')
@EntityPreHook(is_knife, 'secondary_attack')
def _secondary_knife_attack(stack_data):
...
Also, I moved this to a more appropriate forum.
Re: weapon_fire event on leftclick
mhh thanks so far. my goal really is to do this for all players, and all weapons they carrry. basically a replica of weapon_fire event, only for primary AND secondary. so if i did this with your method, are there any disadvantages in creating multiple prehooks?
Re: weapon_fire event on leftclick
actually i think i will just use the weapon_fire event that i mentioned and then use your method for those weapons that are not getting fired in the event. i dont think there will be many exceptions..
Re: weapon_fire event on leftclick
I'm not sure why you would want to do this for all weapons, to be honest. I tested with a couple that don't even have a secondary fire capability, and it spams the function. I could see the merit in doing it for the weapons that actually do have a secondary fire capability, though. And no, they would each need their own specific hook. CKnife::SecondaryAttack is what gets hooked in my example above. The same will hold for CWeaponM4A1::SecondaryAttack, CWeaponGlock::SecondaryAttack, etc..., though I have not tested each one.
If the code in the hook is exactly the same, though, you can always use multiple hooks on the same function:
If the code in the hook is exactly the same, though, you can always use multiple hooks on the same function:
Syntax: Select all
from entities.hooks import EntityCondition, EntityPreHook
is_knife = EntityCondition.equals_entity_classname('weapon_knife')
is_m4a1 = EntityCondition.equals_entity_classname('weapon_m4a1')
is_glock = EntityCondition.equals_entity_classname('weapon_glock')
@EntityPreHook(is_knife, 'secondary_attack')
@EntityPreHook(is_m4a1, 'secondary_attack')
@EntityPreHook(is_glock, 'secondary_attack')
def _secondary_attack(stack_data):
...
Re: weapon_fire event on leftclick
well i tried to use this: EntityCondition.equals_datamap_classname('CWeaponCSBase') but im also getting no secondary attack. does the stackdata contain the players index? cant really find any info on it anywhere..
Re: weapon_fire event on leftclick
Syntax: Select all
is_knife = EntityCondition.equals_entity_classname('weapon_knife')
@EntityPreHook(is_knife, 'secondary_attack')
def _secondary_knife_attack(stack_data):
entity = Weapon(index_from_pointer(stack_data[0]))
print(entity.weapon_name)
i have this, but is there a way to get the owner index of the weapon?
Last edited by L'In20Cible on Tue Jan 24, 2017 5:38 am, edited 1 time in total.
Reason: [code] → [python]
Reason: [code] → [python]
- L'In20Cible
- Project Leader
- Posts: 1536
- Joined: Sat Jul 14, 2012 9:29 pm
- Location: Québec
Re: weapon_fire event on leftclick
Syntax: Select all
owner = entity.owner
if owner is not None and owner.is_player():
player = Player(owner.index)
Re: weapon_fire event on leftclick
well i cant really update my thread so ill repost a solution
Syntax: Select all
@EntityPreHook(is_knife, 'secondary_attack')
def _secondary_knife_attack(stack_data):
weapon = Weapon(index_from_pointer(stack_data[0]))
print(weapon.owner.index,weapon.weapon_name)
Last edited by L'In20Cible on Tue Jan 24, 2017 5:45 am, edited 1 time in total.
Reason: [code] → [python]
Reason: [code] → [python]
Re: weapon_fire event on leftclick
oh yeah, i just found that too. but how come http://wiki.sourcepython.com/developing ... ity.Weapon doesnt show all directory methods of an object, while dir() in python does?
- L'In20Cible
- Project Leader
- Posts: 1536
- Joined: Sat Jul 14, 2012 9:29 pm
- Location: Québec
Re: weapon_fire event on leftclick
D3CEPTION wrote:oh yeah, i just found that too. but how come http://wiki.sourcepython.com/developing ... ity.Weapon doesnt show all directory methods of an object, while dir() in python does?
It does. It tells you Weapon inherits from Entity, and Entity document that property: http://wiki.sourcepython.com/developing ... tity.owner
Also, Please, use [python] instead of [code].
- L'In20Cible
- Project Leader
- Posts: 1536
- Joined: Sat Jul 14, 2012 9:29 pm
- Location: Québec
Re: weapon_fire event on leftclick
As a side note, dir() will prints out more properties due to the following reason: viewtopic.php?f=20&t=1433&p=9516#p9516
Return to “Plugin Development Support”
Who is online
Users browsing this forum: No registered users and 93 guests