Jump to content
Sign in to follow this  
donelsarjo

Expanding build-in action in vehicle

Recommended Posts

Hi guys,

I was wondering if it would be possible to expand an already existing action in an object.

That's my case:

I wanted the GAZ-66 R142 from RHS to be a mobile spawnpoint when the mast is deployed.

This means adding a spawnpoint via BIS_fnc_addRespawnPosition when the mast is deployed and removing it when the mast it retracted (every time you use it). I want to achieve this by expanding the "deploy Mast" action with a small script.

I would be glad if somebody could come up with a solution or a workaround.

Cheers Don

Share this post


Link to post
Share on other sites

The RHS team have already given you the ability to run code when the mast is deployed or folded.

If you go in the config viewer and find the GAZ, look under its userActions you will find two for the different mast states.

statement = "[this,1] spawn rhs_fnc_gaz66_radioDeploy";

On the above line it shows you their function used by the actions to change the mast state.

If you now look up this function in the functions viewer (configfile, RHS, gaz66_functions) gaz66_radioDeploy, at the bottom of the functions code you will find this..

/*
to add new deploy EH:
_fnc = (_v getVariable ["rhs_eh_gaz66_deploy",[]]) append ["yourfunctionName"];
_v setVariable ["rhs_eh_gaz66_deploy",_fnc];
*/
_fnc = _v getVariable ["rhs_eh_gaz66_deploy",[]];
{_this call (call (compile _x))}foreach _fnc;

Basically when the mast changes state it will call all functions listed on the vehicle in the variable "rhs_eh_gaz66_deploy" passing along the vehcile and state of the mast (1 raised,0 lowered).

So now you know how to find the information, heres a quick example that you can place in the GAZ's init..

fnc_mastDeployment = {
_vehicle = _this select 0;
_mastState = _this select 1;
switch ( _mastState ) do {
	case 0 : {
		_respawnID = _vehicle getVariable [ "respawnID", [] ];
		if ( count _respawnID > 0 ) then {
			_respawnID call BIS_fnc_removeRespawnPosition;
		};
	};
	case 1 : {
		_respawnID = [ east, _vehicle ] call BIS_fnc_addRespawnPosition;
		_vehicle setVariable [ "respawnID", _respawnID ];
	};
};
};
vfncs = this getVariable ["rhs_eh_gaz66_deploy",[]];
vfncs append ["fnc_mastDeployment"];
this setVariable ["rhs_eh_gaz66_deploy", vfncs ];

Here we create a function called fnc_mastDeployment that takes in a passed vehicle and a mast state and depending on the state adds or removes a respawn position for SIDE east at the position of the vehicle.

We then add the name of this function to the variable "rhs_eh_gaz66_deploy" held on the truck. Ready for it to be called on one of the mast actions being used.

Share this post


Link to post
Share on other sites

Wow thanks for the helpful reply.appreciate it:)

// for idiots like me:

vfncs ist the name of the GAZ ^^,

Edited by DonElSarjo

Share this post


Link to post
Share on other sites

No. vfncs is an array of function names stored on the vehicle in the "rhs_eh_gaz66_deploy" variable, the RHS action will run these functions when ever the mast is changed (either up or down).

this in the example would be the GAZ as i wrote the example as code to place in the vehicles init.

Code with comments

//Function to create spawn position
fnc_mastDeployment = {

//Passed vehicle and mast state
   _vehicle = _this select 0;
   _mastState = _this select 1;

   //What state is the mast in
   switch ( _mastState ) do {

   	//Folded
       case 0 : {
       	//Get previously added respawn point
           _respawnID = _vehicle getVariable [ "respawnID", [] ];

           //If there was a respawn position active
           if ( count _respawnID > 0 ) then {
           	//Remove respawn position
               _respawnID call BIS_fnc_removeRespawnPosition;
           };
       };

       //Deployed
       case 1 : {
       	//Add respawn position for EAST at vehicles position
           _respawnID = [ east, _vehicle ] call BIS_fnc_addRespawnPosition;
           //Save respawn ID on the vehicle
           _vehicle setVariable [ "respawnID", _respawnID ];
       };
   };
};

//Get list of mast deployment functions from vehicle
vfncs = _vehicle getVariable ["rhs_eh_gaz66_deploy",[]];
//Add our new function to the list
vfncs append ["fnc_mastDeployment"];
//Save the list back to the vehicle
_vehicle setVariable ["rhs_eh_gaz66_deploy", vfncs ];  

Edited by Larrow

Share this post


Link to post
Share on other sites

ok thanks for the clearing up. But strangly it only worked for me, when i replaced the vfncs with my vehicle name.

Anyway o.O Thank you very much for your great help. There should be more "Larrows" around :P

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
Sign in to follow this  

×