Arma 3
Loafus Jul 8, 2021 @ 12:58am
[SOLVED] Event handler for throwing grenades or planting an explosive
I've managed to put together 2 scripts, they look like this:

_this addEventHandler ["fired", {(_this select 0) addItem "HandGrenade";}];
_this addEventHandler ["fired", {(_this select 0) addItem "DemoCharge_Remote_Mag";}];

The first script gives the unit a grenade for every shots fired while the second one gives it a demo charge duh .

However, both of those scripts are just placeholders because of 2 problems:
1. They use the "Fired" event handler. I have no idea what the event handlers are for throwing grenades or placing explosives . I've already take a look at the BI wiki but to no avail. Or maybe i've missed something in the wiki, but i'm not checking it out twice cuz reading makes me wanna hurl, at least for now.
2. I don't know how to make both scripts give the unit the same grenade/explosive respectively once they use it.

I would like to ask for a solution for those two things, If there even is one.

P.s i'm a little new to scripting,
Last edited by Loafus; Jul 8, 2021 @ 6:01am
< >
Showing 1-4 of 4 comments
Pathfinder Serza Jul 8, 2021 @ 1:20am 
Well...

The fired Muzzle/Weapon is going to be grenadeMuzzle/Throw for grenades (classnames may be wrong - I've never actually looked at the cfg's for grenades) and demoChargeMuzzle/Put (for these I'm absolutely certain and confirmed them with the cfg, since I'm already doing stuff with it).

So...
_this select 0 = the unit that used the item
_this select 1 = the weapon the unit used (Put/Throw)
_this select 2 = the muzzle the unit used (demoChargeMuzzle and equivalent - different for each item for explosives!)
_this select 3 = mode... uh... full/semi auto? I don't think it's applicable
_this select 4 = the ammo type the unit used. (DemoCharge_Remote_Ammo for the small charge)
_this select 5 = the magazine that the unit had loaded when it fired (DemoCharge_Remote_Mag for the small charge)
_this select 6 = projectile... not applicable for charges, potentially applicable for grenades

Since both Put and Throw are defined under cfgWeapons, the game will see them as Weapons. They all have defined muzzles, magazines and ammunition - even though this makes no sense in reality, it is how the game works.
Loafus Jul 8, 2021 @ 2:32am 
I'm confused, are grenadeMuzzle and demoChargeMuzzle supposed to be the event handlers? They're not working.
Pathfinder Serza Jul 8, 2021 @ 3:44am 
They're the... muzzles... That you reference with the fired eventHandler.

https://community.bistudio.com/wiki/Arma_3:_Event_Handlers#Fired
Loafus Jul 8, 2021 @ 6:00am 
I've finally got it. It took me waaay too long to figure it out. The script goes like this:

_unit addeventhandler ["fired", {if((_this select 1) in ["Put","Throw"]) then {
(_this select 0) addMagazine (_this select 5);
};
}];

apparently the "fired" event handler WAS the right one, at first i thought it'll just add the nades or explosives after you take a shot from your firearm. Turns out it adds them right when they're being used.

In other words, it works like a charm. Thanks for the help champ :steamthumbsup:
< >
Showing 1-4 of 4 comments
Per page: 1530 50

Date Posted: Jul 8, 2021 @ 12:58am
Posts: 4