beako 13 Posted August 15, 2018 What is the best way to create and eventhandler for currentThrowable items? I want an event handler to track every time I throw a throwable, so when my player's inventory of "HandGrenade"or "SmokeShellGreen" is depleted I can refill it. I have tried to use an "explosion" EH with the following but does not work as _throwableArray is an array of strings, and I can't figure out how to create an array of throwables on the player...Also I don't think this would work for a "SmokeShell" _throwableArray = []; { if (_x == _throwable) then {_throwableArray pushBack _x} } forEach (magazines player); { _x addEventHandler ["Explosion", { params ["_vehicle", "_damage"]; if (damage _vehicle > 0.1) then { if !( _throwable in (magazines player) ) then {for "_i" from 1 to 3 do {player addItemToVest _throwable};}; }; }]; } forEach _throwableArray; I have tried to use "AnimDone" EH, but could not even find the common animation for throwing... player addEventHandler ["AnimDone", { params ["_unit", "_anim"]; if (_anim == "AmovPercMrunSlowWpstDf_AmovPercMstpSrasWpstDnon_gthThrow") then { if !( _throwable in (magazines player) ) then {for "_i" from 1 to 3 do {player addItemToVest _throwable};}; }; }]; Share this post Link to post Share on other sites
Grumpy Old Man 3548 Posted August 15, 2018 This will give the player one RGO grenade when he's throwing the last one: player addEventHandler ["Fired",{ params ["_unit", "_weapon", "_muzzle", "_mode", "_ammo", "_magazine", "_projectile", "_gunner"]; _toCheck = "HandGrenade"; _last = magazines _unit findIf {_x isEqualTo _toCheck} < 0; if (_last) then {_unit addMagazineGlobal _toCheck}; }]; Cheers 1 2 Share this post Link to post Share on other sites
diwako 413 Posted August 15, 2018 In case you are using ace with advanced throwing, the event handler is similar, it is just moved to cba event frame work ["ace_firedPlayer", { params ["_unit", "_weapon", "_muzzle", "_mode", "_ammo", "_magazine", "_projectile", "_gunner"]; _toCheck = "HandGrenade"; _last = magazines _unit findIf {_x isEqualTo _toCheck} < 0; if (_last) then {_unit addMagazineGlobal _toCheck}; }] call CBA_fnc_addEventHandler; 1 Share this post Link to post Share on other sites
Larrow 2823 Posted August 15, 2018 6 hours ago, beako said: I want an event handler to track every time I throw a throwable, so when my player's inventory of "HandGrenade"or "SmokeShellGreen" is depleted I can refill it. //initPlayerLocal.sqf //Get a list of all throwable magazine types _throwables = []; "_throwables append getArray( _x >> 'magazines' )" configClasses( configFile >> "CfgWeapons" >> "Throw" ); //Get a list of all players current throwables _initialThrowables = magazines player select { _x in _throwables } call BIS_fnc_consolidateArray; //Keep a note of intial throwables player setVariable[ "initialThrowables", _initialThrowables ]; //Make a copy so we can track how many are left player setVariable[ "throwableCounts", +_initialThrowables ]; //When the player fires player addEventHandler [ "Fired", { params[ "_unit", "_weapon", "", "", "", "_magazine" ]; //If he threw something if ( _weapon == "Throw" ) then { //Get our info for the thrown type _thrownInfo = _unit getVariable "throwableCounts" select { _x select 0 == _magazine } select 0; //If we are tracking this type //remember we are only tracking initial throwables //any different throwable types picked up after initialisation will have no info if !( isNil "_thrownInfo" ) then { //Decrease its count by 1 _count = ( _thrownInfo select 1 ) - 1; //If we have run out of this type if ( _count isEqualTo 0 ) then { //Get the initial info for this type _initialInfo = player getVariable "initialThrowables" select { _x select 0 == _magazine } select 0; //Resupply _unit addMagazines _initialInfo; //Reset type count _thrownInfo set [ 1, _initialInfo select 1 ]; }else{ //Otherwise just update its count value _thrownInfo set [ 1, _count ]; }; }; }; }]; 1 Share this post Link to post Share on other sites
kibaBG 54 Posted December 25, 2023 If anyone wants to have code executed when throwing a smoke grenade (color green). Good for calling heli extraction, paradrop, etc: ["ace_firedPlayer", { params ["_unit", "_weapon", "_muzzle", "_mode", "_ammo", "_magazine", "_projectile", "_gunner"]; if (_magazine == "rhssaf_mag_brd_m83_green") then {some code;} else {["Not working"] remoteExec ["hint",0];}; }] call CBA_fnc_addEventHandler; //add it to initPLayerLocal.sqf or where you see fit Merry Christmas btw! ✨🎄 Share this post Link to post Share on other sites