Jump to content

Recommended Posts

Hey! 

 

If I want to add eventHandlers to:

EDIT:
class CfgVehicles {
    class Man;
    class CAManBase: Man {
      class EventHandlers {
      	addEventHandler ["GetInMan", {[player] call Salmon_fnc_function}];
        addEventHandler ["GetOutMan", {[player] call Salmon_fnc_function}]
		};
	};
};

How would I go about doing that? I want to call a function every time a player with the mod loaded gets in or out of a vehicle. 

Edited by Spatsiba
Found some more info

Share this post


Link to post
Share on other sites

There are 3 ways to do this in vanilla (at least I am thinking of 3 ways)

  • the EventHandlers class (what you tried)
    class CfgVehicles
    {
        class Man;
        class CAManBase: Man
        {
          class EventHandlers
          {
          	GetInMan = "(_this select 0) call Salmon_fnc_function";
            GetOutMan = "(_this select 0)  call Salmon_fnc_function";
    		};
    	};
    };

     

  • the cfgFunction class
    class CfgFunctions
    {
    	class Salmon
    	{
    		tag = "Salmon";
    		class SalmonFuntions
    		{
    			file = "Salmon\functions";
    			class function // you will be able to call this function by the name "Salmon_fnc_function"
                {
                  postinit = 1; // if postinit is set to 1, the function will not be executed at the initialization of the game but at the initialization of your mission
                  recompile = 0; // do not allow recompile
                };
    		};
    	};
    };

     

  • the initPlayerLocal.sqf script file inside of your mission folder
    player addEventHandler [
    	"GetInMan",
    	{
    		_vehIn = [player] call "Salmon\functions\fn_function.sqf";
    	}
    ];
    
    player addEventHandler [
    	"GetOutMan",
    	{
    		_vehOut = [player] call "Salmon\functions\fn_function.sqf";
    	}
    ];

     

  • Thanks 1

Share this post


Link to post
Share on other sites

config.cpp

class CfgPatches {
	class test_manEH {
		units[] = {};
		requiredVersion = 1.0;
		requiredAddons[] = {"A3_Characters_F"};
	};
};


class CfgVehicles {
	class Man;
	class CAManBase: Man {
		class EventHandlers {
			GetInMan = "( _this + [ 'in' ] ) call Salmon_fnc_function";
			GetOutMan = "( _this + [ 'out of' ] ) call Salmon_fnc_function";
		};
	};
};

class CfgFunctions {
	class test_manEH {
		tag = "Salmon";
		class test_manEH {
			//LARs << as this is my base folder I pack from, change to suit
			//test_manEH << as this is the name of the folder containing the files that was packed
			file = "LARs\test_manEH\functions";
			class function {};
		};
	};
};

test_manEH\functions\fn_function.sqf

//Top of Salmon_fnc_function
params[ "_unit", "_position", "_vehicle", "_turretPath", "_action" ];

if !( _unit isEqualTo player ) exitWith {};

//If we get here we must be the local client

//Send hint to everyone for testing, so we can see server sontrolled AI are not producing hint
format[ "%1 got %2 %3", name _unit, _action, getText( configFile >> "CfgVehicles" >> typeOf _vehicle >> "displayName" ) ] remoteExec [ "Hint", 0 ];

TEST_ADDON

 

  • Thanks 2

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

×