Shootable Weapon events?

derkoi

New member
Hi,

I'm trying to add vibration/rumble on the controller when a weapon is fired, reloaded etc but I can't find any events for the weapon being fired and if it's shooting a bullet (has ammo) or dry firing.

Can anyone tell me how to achieve this please? Thanks
 
The correct way is to subscribe to the OnItemAbilityActive event and then filter based on the item ability that was active. When you get the Use ability you can see what item is being used with the UsableItems property.

 
Hi,

Thanks for the reply I've got the OnItemAbilityActive event working but I'm not sure where the UsableItems property is, also I can't get the OnDeath event working at all.
 
Last edited:
You'll need to cast the itemAbility to use:

Code:
var use = itemAbility as Use;
if (use == null) {
   return;
}

for (int i = 0; i < use.UsableItems.length; ++i) {

}

also I can't get the OnDeath event working at all.
Make sure you are subscribing to OnDeath on the main character GameObject. OnDeath is used in a decent amount of locations so if you search through the code you can find a few examples.
 
To get the actual weapon that shot, we look for the shootable weapon component on those items? Using GetComponent?
Trying to find the easiest way to get to "weapon just shot" event.
Currently I'm going through the consumable types on the UsableItems list and making sure that it consumed more than zero, is that a correct way of going about it?
 
Any IUsableItem that is within the use.UsableItems list is currently being used. If you want the actual shootable weapon you can just do a cast:

Code:
for (int i = 0; i < use.UsableItems.length; ++i) {
   if (use.UsableItems[i] == null) {
      continue;
   }  
   var shootableWeapon = use.UsableItems[i] as ShootableWeapon;
   if (shootableWeapon == null) {
      continue;
   }
   // Do stuff.
}
 
Awesome, thanks a lot.

------
The one thing that I see is that this happens only as soon as the ability gets activated (as the event name does suggest), then it is our responsibility to trigger the following events for everytime the gun shoots (let me know if I'm missing something here).

Maybe we should listen to "OnItemUseConsumableItemType" or the crosshair spread one which happens to trigger every fire event?
 
This is still way more complicated than it needs to be, can't events for Shoot, reload and dry fire be added to the ShootableWeapon script?
 
As a quick fix I added a script to the muzzle flash prefab that communicates with my Rumble script on enable, works fine.
 
Top