Jump to content

Recommended Posts

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

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

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

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;

 

  • Like 1

Share this post


Link to post
Share on other sites
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 ];
			};
		};
	};
}];

 

  • Thanks 1

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×