Vehicle Custom Init

  1. 9 years ago

    description.ext

    class Extended_Init_EventHandlers {
    	//All
    	class All {
    		init = "_this call (compile preprocessFileLineNumbers 'events\onKilled.sqf');";
    	};
    };

    events\onKilled.sqf

    private "_unit";
    _unit = _this select 0;
    
    if ((side _unit == east) and (!isPlayer _unit)) then {
    	_unitType = typeOf _unit;
    	
    	diag_log format ["[INS] UNIT TYPE = %1", _unitType];
    	
    	if (_unitType isKindOf "Man") then {
    		diag_log "[INS] Adding init to MAN";
    		[_unit] execVM "events\man_killed.sqf";
    	};
    	
    	if (_unitType isKindOf "Car") then {
    		diag_log "[INS] Adding init to CAR";
    		[_unit] execVM "events\car_killed.sqf";
    	};
    	
    	if (_unitType isKindOf "Truck") then {
    		diag_log "[INS] Adding init to TRUCK";
    		[_unit] execVM "events\car_killed.sqf";
    	};
    	
    	if (_unitType isKindOf "Tank") then {
    		diag_log "[INS] Adding init to TANK";
    		[_unit] execVM "events\tank_killed.sqf";
    	};
    	
    	if (_unitType isKindOf "Helicopter") then {
    		diag_log "[INS] Adding init to HELO";
    		[_unit] execVM "events\helicopter_killed.sqf";
    	};
    };

    events\car_killed.sqf (example, they all look like this)

    private "_unit";
    _unit = _this select 0;
    
    _unit addEventHandler ["Killed", {
    	private["_unit", "_killer", "_unitFac", "_killerFac"];
    	_unit = _this select 0;
    	_killer = _this select 1;
    		
    	_unitFac = side (group _victim);
    	_killerFac = side (group _killer);
    		
    	_killMoney = 1500;
    		
    	_killer globalChat "Killed enemy car +$1500 to Operation Budget!";
    		
    	B_defensebudget = (B_defensebudget + _killMoney);
    	publicVariable "B_defensebudget";
    }];

    The above code works for all enemy man units; but it refuses to work on any vehicles.
    Is there anything I'm doing wrong?

  2. Edited 9 years ago by SpyderBlack723

    hmm, might have to do

    (vehicle _unit) addEventHandler ["Killed", {
  3. It's not even printing the unitType for vehicles in onKilled.sqf

  4. Edited 9 years ago by SpyderBlack723

    isKindOf can be used with objects, try removing
    _unitType = typeOf _unit;
    and switching all if-then statements to this structure
    if (_unit isKindOf "Man") then {

  5.  
    8:16:58 "[INS] UNIT TYPE = any"
     8:16:58 "[INS] Adding init to MAN"

    Tested with empty helicopter and AI controlled helicopter, all found men are still counted, vehicles aren't still

  6. Make sure if you are using a modded faction that it is compatible with CBA Extended Eventhandlers.. what faction are you trying to use?

  7. OPFOR - CSAT, just the default to test the script

  8. hmm, may be a question better suited for the CBA team then (since it's a CBA feature)

    https://forums.bistudio.com/topic/168277-cba-community-base-addons-arma-3/page-27

  9. Alright, thanks, I thought it was with ALiVE :)

  10. Np, good luck!

 

or Sign Up to reply!