Jump to content
unidad2pete

AddAction multiplayer for allplayers

Recommended Posts

This is what use for dedicated servers:

_actPilot = _this addaction ["<t color=""#CC0000"">Rescue Pilot</t>", {[[_this,"hostage.sqf"],"BIS_fnc_execVM",true] call BIS_fnc_MP;},[], 9,true, false, "","((vehicle _target) distance  (vehicle _this)) < 3"];
Or simply:

this addaction ["Rescue Pilot", {[[_this,"hostage.sqf"],"BIS_fnc_execVM",true] call BIS_fnc_MP;}];
If you want to see hostage.sqf....

 

_hostage = _this select 0;

_rescuer = _this select 1;

_hostage enableAI "MOVE";

_hostage switchMove "";

_hostage setCaptive true;

[_hostage] joinSilent _rescuer;

removeAllActions _hostage;

 

 

Instead of using a separate file you can simply execute the code inside the addAction.

this addAction ["Rescue Pilot", {
	[_this, {
		(_this select 0) removeAction (_this select 2);
		(_this select 0) enableAI 'MOVE';
		(_this select 0) switchMove "";
		(_this select 0) setCaptive true;
	}] remoteExec ["call", 0, true];
	[_this select 0] joinSilent _this select 1;
};];

Also, BIS_fnc_Mp is outdated and replaced with remoteExec.

Share this post


Link to post
Share on other sites

Can somebody help me with this? I made a car called veh1 and a soldier called man1.

while {true} do
{
	sleep 5;
	_action = man1 addAction ["<t color='#FF0000'>Defense bonus</t>", "man1 removeAction _action; detach veh1; veh1 attachto [men1,[0,2,1.1]];", "", "10"];
	sleep 10;
	if (_action == 1) then
	{
		detach veh1;
		veh1 attachto [placeholder,[0,0,10]];
	}
};

I want to execute the if code if the action got executed from the soldier.

Please help me with this.

 

Thanks,

TheDusty01

Share this post


Link to post
Share on other sites

Can somebody help me with this? I made a car called veh1 and a soldier called man1.

while {true} do
{
	sleep 5;
	_action = man1 addAction ["<t color='#FF0000'>Defense bonus</t>", "man1 removeAction _action; detach veh1; veh1 attachto [men1,[0,2,1.1]];", "", "10"];
	sleep 10;
	if (_action == 1) then
	{
		detach veh1;
		veh1 attachto [placeholder,[0,0,10]];
	}
};

I want to execute the if code if the action got executed from the soldier.

Please help me with this.

 

Thanks,

TheDusty01

 

As far as I understand this is somewhat what you're looking for:

defenseBonus = {
	veh1 attachTo [men1,[0,2,1.1]]; // Should perhaps be: man1 , but wasn't sure if it was a typo or not.
	Sleep 10;
	veh1 attachTo [placeholder,[0,0,10]];
	Sleep 5;
	man1 addAction ["<t color='#FF0000'>Defense bonus", {
		(_this select 0) removeAction (_this select 2);
		[] spawn defenseBonus;
	}, nil, 10];
};
man1 addAction ["<t color='#FF0000'>Defense bonus", {
	(_this select 0) removeAction (_this select 2);
	[] spawn defenseBonus;
}, nil, 10];
  • Like 1

Share this post


Link to post
Share on other sites

 

As far as I understand this is somewhat what you're looking for:

defenseBonus = {
	veh1 attachTo [men1,[0,2,1.1]]; // Should perhaps be: man1 , but wasn't sure if it was a typo or not.
	Sleep 10;
	veh1 attachTo [placeholder,[0,0,10]];
	Sleep 5;
	man1 addAction ["<t color='#FF0000'>Defense bonus", {
		(_this select 0) removeAction (_this select 2);
		[] spawn defenseBonus;
	}, nil, 10];
};
man1 addAction ["<t color='#FF0000'>Defense bonus", {
	(_this select 0) removeAction (_this select 2);
	[] spawn defenseBonus;
}, nil, 10];

Yea! It is perfect, thanks! :) I had to edit it a little to work. If anyone wants to use it place a vehicle called "placeholder", a car/tank called "veh1" and the unit called "man1". He get's after a certain time surviving a defense bonus.

Code:

defenseBonus = {
	veh1 attachto [man1,[0,2,1.1]];
	Sleep 16;
	veh1 attachto [placeholder,[0,0,10]];
	Sleep 60;
	man1 addAction ["<t color='#FF0000'>Defense bonus", {
		(_this select 0) removeAction (_this select 2);
		[] spawn defenseBonus;
	}, nil, 10];
};
sleep 60;
man1 addAction ["<t color='#FF0000'>Defense bonus", {
	(_this select 0) removeAction (_this select 2);
	[] spawn defenseBonus;
}, nil, 10];

Share this post


Link to post
Share on other sites

 

As far as I understand this is somewhat what you're looking for:

defenseBonus = {
	veh1 attachTo [men1,[0,2,1.1]]; // Should perhaps be: man1 , but wasn't sure if it was a typo or not.
	Sleep 10;
	veh1 attachTo [placeholder,[0,0,10]];
	Sleep 5;
	man1 addAction ["<t color='#FF0000'>Defense bonus", {
		(_this select 0) removeAction (_this select 2);
		[] spawn defenseBonus;
	}, nil, 10];
};
man1 addAction ["<t color='#FF0000'>Defense bonus", {
	(_this select 0) removeAction (_this select 2);
	[] spawn defenseBonus;
}, nil, 10];

Could you help me again? I want to force the unit "man1" to getout of the vehicle man1 leaveVehicle off1; doesn't work, here is my code:

defenseBonus = {
	man1 setDamage 0;
	veh1 attachto [man1,[0,2,1.1]];
	Sleep 10;
	veh1 attachto [placeholder,[0,0,10]];
	Sleep 15;
	man1 addAction ["<t color='#FF0000'>Defense bonus", {
		(_this select 0) removeAction (_this select 2);
		[] spawn defenseBonus;
	}, nil, 10];
};
offenseBonus = {
	man1 setDamage 0;
	off1 attachto [man1,[0,0,4]];
	detach off1;
	man1 moveInDriver off1;
	Sleep 10;
	man1 leavevehicle off1;
	man1 setDamage 0;
	off1 attachto [placeholder2,[0,0,10]];
	man1 setDamage 0;
	Sleep 15;
	man1 addAction ["<t color='#FF0000'>Offense bonus", {
		(_this select 0) removeAction (_this select 2);
		[] spawn OffenseBonus;
	}, nil, 10];
};
sleep 15;
man1 addAction ["<t color='#FF0000'>Defense bonus", {
	(_this select 0) removeAction (_this select 2);
	[] spawn defenseBonus;
}, nil, 10];
sleep 15;
man1 addAction ["<t color='#FF0000'>Offense bonus", {
	(_this select 0) removeAction (_this select 2);
	[] spawn offenseBonus;
}, nil, 10];

Share this post


Link to post
Share on other sites

 

Could you help me again? I want to force the unit "man1" to getout of the vehicle man1 leaveVehicle off1; doesn't work, here is my code:

defenseBonus = {
	man1 setDamage 0;
	veh1 attachto [man1,[0,2,1.1]];
	Sleep 10;
	veh1 attachto [placeholder,[0,0,10]];
	Sleep 15;
	man1 addAction ["<t color='#FF0000'>Defense bonus", {
		(_this select 0) removeAction (_this select 2);
		[] spawn defenseBonus;
	}, nil, 10];
};
offenseBonus = {
	man1 setDamage 0;
	off1 attachto [man1,[0,0,4]];
	detach off1;
	man1 moveInDriver off1;
	Sleep 10;
	man1 leavevehicle off1;
	man1 setDamage 0;
	off1 attachto [placeholder2,[0,0,10]];
	man1 setDamage 0;
	Sleep 15;
	man1 addAction ["<t color='#FF0000'>Offense bonus", {
		(_this select 0) removeAction (_this select 2);
		[] spawn OffenseBonus;
	}, nil, 10];
};
sleep 15;
man1 addAction ["<t color='#FF0000'>Defense bonus", {
	(_this select 0) removeAction (_this select 2);
	[] spawn defenseBonus;
}, nil, 10];
sleep 15;
man1 addAction ["<t color='#FF0000'>Offense bonus", {
	(_this select 0) removeAction (_this select 2);
	[] spawn offenseBonus;
}, nil, 10];

 

You can use this:

man1 action ["getOut", off1];

Share this post


Link to post
Share on other sites

 

You can use this:

man1 action ["getOut", off1];

Thank you very much again! :) You helped me a lot!!

  • Like 1

Share this post


Link to post
Share on other sites

Sorry to necro, not able to post new threads yet and had a question similar to the above. The action Im adding works fine for the host, but not for any other players. they can see it, but not interact with it.

 

Trying to create a simple killhouse for my unit.  The targets should not pop back up once shot, and i have a console in front of the house to reset all the targets inside the house.  Im very new to scripting in Arma so apologies if I give some bad info off the bat.

 

Each of my targets in named in sequence with the nopop=true in the init field

 

The console has the following code in it:

[controlLaptop_2 addAction["Reset Small Killhouse","popup_reset.sqf",[target_1,target_2,target_3,target_4,target_5,target_6,target_7,target_8,target_9,target_10,target_11,target_12,target_13,target_14,target_15,target_16,target_17,target_18,target_19,target_20,target_21,target_22,target_23,target_24,target_25,target_26,target_27,target_28,target_29,target_30,target_31],false]]] call BIS_fnc_MP;

 

This adds the action for all to see, and when the host uses the action, it resets the targets as normal.

 

popup_reset.sqf references this script, i downloaded this off armaholic:

 

// Check to make sure this script is executed on the server ONLY
if (!isServer) exitWith {};
 
// Ensure the targets do not pop up again once shot
nopop = true;
 
// Step 1a
_selection = _this select 3 select 0; // Gets the first element in the list (list is at index 3), should be array of targets
// Step 1b
_display = _this select 3 select 1; // Gets the second element in the list (list is at index 3), should be a boolean
 
_printStr = "";
 
// Step 2
{ BIS_fnc_MP;
_x setDamage 1;
_x animate ["terc",0];
// Step 2a
if (_display) then {
_printStr = format["%1\n%2",_printStr,_x];
};
} forEach _selection;
 
// Step 3
if (_display) then {
hint format ["Targets reset:\n%1", _printStr];
};
 
I feel like its referencing some older code with the bit about the !isServer, but I, not totally sure.  I tried removing the ! and had the opposite problem, where others could use the action but I was unable to. I tried adding the call BIS_fnc_MP; line to the script as well with little luck

Share this post


Link to post
Share on other sites

hi !

 

i have the similar problem and i dont find solution, maybe you can help me !

 

 all player can use addaction :

a1 = radiocar addaction["Déploy","deploy.sqf"];

and this is what action do : 

if (!isDedicated) then {
[{
    if ((radiocar distance player) < 500) then {
player setVariable ['tf_sendingDistanceMultiplicator', 4, true];
}
else { player setVariable ['tf_sendingDistanceMultiplicator', 1, true];
};
if (isNull radiocar) exitWith {(_this select 1) call CBA_fnc_removePerFrameHandler;
};
}, 10] call CBA_fnc_addPerframeHandler;


radiocar forceSpeed 0;
radiocar removeAction a1;
a2 = radiocar addaction["removed radio","deployed.sqf"];
[radiocar,1] spawn rhs_fnc_gaz66_radioDeploy;


}
The problem is when i use action "Deploy",  i have the new action action "removed", but others players still have action "Deploy"
 
Can you help me ???
 
 
Ps : sorry for my very bad english

Share this post


Link to post
Share on other sites

with this ?  

if (isServer) then {

or with this maybe ?

if (!isDedicated) then { 

Share this post


Link to post
Share on other sites

i tried this :

 

[{
    if ((radiocar distance player) < 500) then {
player setVariable ['tf_sendingDistanceMultiplicator', 4, true];
}
else { player setVariable ['tf_sendingDistanceMultiplicator', 1, true];
};
if (isNull radiocar) exitWith {(_this select 1) call CBA_fnc_removePerFrameHandler;
};
}, 10] call CBA_fnc_addPerframeHandler;


radiocar forceSpeed 0;
[radiocar,1] spawn rhs_fnc_gaz66_radioDeploy;


if (!isDedicated) then {

radiocar removeAction a1;
a2 = radiocar addaction["removed radio","deployed.sqf"];

}

but same problem when i use "deploy", this action is remove and "removed" is add but my mates  still have "deploy"

Share this post


Link to post
Share on other sites

Replace the removeAction bit with:

[radiocar, a1] remoteExec ["removeAction", 0, true];

This might work, can't test right now

 

Edit - I was being an idiot. Changed code

Edited by hallyg

Share this post


Link to post
Share on other sites

so i tried this : 

 

[{
    if ((radiocar distance player) < 500) then {
player setVariable ['tf_sendingDistanceMultiplicator', 4, true];
}
else { player setVariable ['tf_sendingDistanceMultiplicator', 1, true];
};
if (isNull radiocar) exitWith {(_this select 1) call CBA_fnc_removePerFrameHandler;
};
}, 10] call CBA_fnc_addPerframeHandler;


radiocar forceSpeed 0;
[radiocar,1] spawn rhs_fnc_gaz66_radioDeploy;


[radiocar, a1] remoteExec ["removeAction", 0, true];
a2 = radiocar addaction["remove radio","deployed.sqf"];
 

so now  when anyone use action "deploy" , this action is remove for everybody but my next addaction a2 doesn't appear for, i guess it s same problem , addaction is local and i must use 

this addaction ["Rescue Pilot", {[[_this,"hostage.sqf"],"BIS_fnc_execVM",true] call BIS_fnc_MP;}];

but how can i say this action is a2 ?

a2 = radiocar addaction ["removed radio", {[[_this,"deployed.sqf"],"BIS_fnc_execVM",true] call BIS_fnc_MP;}];

Share this post


Link to post
Share on other sites

so now  when anyone use action "deploy" , this action is remove for everybody but my next addaction a2 doesn't appear for, i guess it s same problem , addaction is local and i must use 

this addaction ["Rescue Pilot", {[[_this,"hostage.sqf"],"BIS_fnc_execVM",true] call BIS_fnc_MP;}];

but how can i say this action is a2 ?

a2 = radiocar addaction ["removed radio", {[[_this,"deployed.sqf"],"BIS_fnc_execVM",true] call BIS_fnc_MP;}];

 

 

addAction has local effects. You need to add the action to all clients. As far as I know, you can't return the actionID when you remoteExec so try this:

[
	[], 
	{
		private _a = radiocar addaction ["Remove Radio", {
			[[_this, "deployed.sqf"], "BIS_fnc_execVM", true] call BIS_fnc_MP;
		}];
		if ((missionNameSpace getVariable ["a2", false]) isEqualType false) then {
			missionNameSpace setVariable ["a2", _a, true];
		};
	}
] remoteExec ["call", 0, true];

Share this post


Link to post
Share on other sites

So now, this is my scripts : 

 

for deploy radio : 

 

[{
    if ((radiocar distance player) < 500) then {
player setVariable ['tf_sendingDistanceMultiplicator', 4, true];
}
else { player setVariable ['tf_sendingDistanceMultiplicator', 1, true];
};
if (isNull radiocar) exitWith {(_this select 1) call CBA_fnc_removePerFrameHandler;
};
}, 10] call CBA_fnc_addPerframeHandler;


radiocar forceSpeed 0;
[radiocar,1] spawn rhs_fnc_gaz66_radioDeploy;
[radiocar, a1] remoteExec ["removeAction", 0, true];


[
[], 
{
private _a = radiocar addaction ["remove radio", {
[[_this, "deployed.sqf"], "BIS_fnc_execVM", true] call BIS_fnc_MP;
}];
if ((missionNameSpace getVariable ["a2", false]) isEqualType false) then {
missionNameSpace setVariable ["a2", _a, true];
};
}
] remoteExec ["call", 0, true];

et for remove radio : 

 

[{
    if ((radiocar distance player) < 500) then {
player setVariable ['tf_sendingDistanceMultiplicator', 1, true];
};
if (isNull radiocar) exitWith {(_this select 1) call CBA_fnc_removePerFrameHandler;
};
}, 10] call CBA_fnc_addPerframeHandler;


radiocar forceSpeed -1;
[radiocar,0] spawn rhs_fnc_gaz66_radioDeploy;
[radiocar, a2] remoteExec ["removeAction", 0, true];


[
[], 
{
private _a = radiocar addaction ["déploy radio", {
[[_this, "deploy.sqf"], "BIS_fnc_execVM", true] call BIS_fnc_MP;
}];
if ((missionNameSpace getVariable ["a1", false]) isEqualType false) then {
missionNameSpace setVariable ["a1", _a, true];
};
}
] remoteExec ["call", 0, true];

on my vehicme init : 

 

a1 = radiocar addaction ["déploy radio", { 
   [[_this, "deploy.sqf"], "BIS_fnc_execVM", true] call BIS_fnc_MP; 
  }];

this is what happen when i use actions :

 

http://images.akamai.steamusercontent.com/ugc/252588856179858807/97834F1A0F43C7249FA238648DB003774CF925E1/

 

 

so can you help me one more time ^^

Share this post


Link to post
Share on other sites

How are you calling those scripts above?
If you're using BIS_fnc_MP to call them then, the remoteExec will be executed multiple times meaning multiple addactions on each player.

A quick fix, although it won't stop what I mentioned above, (UNTESTED):
 

[
	[], 
	{
		if ((missionNameSpace getVariable ["a1", false]) isEqualType false) then {
			private _a = radiocar addaction ["déploy radio", {
				[[_this, "deploy.sqf"], "BIS_fnc_execVM", true] call BIS_fnc_MP;
			}];
			missionNameSpace setVariable ["a1", _a];
		};
	}
] remoteExec ["call", 0, true];

Share this post


Link to post
Share on other sites

i call this scripts with "init" of my vehicle "radiocar" like that :

a1 = radiocar addaction ["déploy radio", { 
   [[_this, "deploy.sqf"], "BIS_fnc_execVM", true] call BIS_fnc_MP; 
  }];

If i use your last script : 


[{    if ((radiocar distance player) < 500) then {player setVariable ['tf_sendingDistanceMultiplicator', 1, true];
};
if (isNull radiocar) exitWith {(_this select 1) call CBA_fnc_removePerFrameHandler;
};
}, 10] call CBA_fnc_addPerframeHandler;


radiocar forceSpeed -1;
[radiocar,0] spawn rhs_fnc_gaz66_radioDeploy;
[radiocar, a2] remoteExec ["removeAction", 0, true];


[
    [],
    {
        if ((missionNameSpace getVariable ["a1", false]) isEqualType false) then {
            private _a = radiocar addaction ["déploy radio", {
                [[_this, "deploy.sqf"], "BIS_fnc_execVM", true] call BIS_fnc_MP;
            }];
            missionNameSpace setVariable ["a1", _a];
        };
    }
] remoteExec ["call", 0, true];

 i can only use action one time and it disapear after so impossible to deploy one more time my radio

Share this post


Link to post
Share on other sites

Okay so essentially, you're running the script on each client, then the action is being added to each client on each client hence the multiple actions. It's probably best to try and make it server sided then try that.


Try this (I'm at work so i can't test any of this, sorry):

 

After:

[radiocar, a1] remoteExec ["removeAction", 0, true];

Put:

missionNameSpace setVariable ["a1", false, true];

Share this post


Link to post
Share on other sites

it s ok i solve the problem 

 

 

véhicul init : 

 

a1 = radiocar addaction ["déploy radio", { 
   [[_this, "deploy.sqf"], "BIS_fnc_execVM", true] call BIS_fnc_MP; 
  }];

deploy.sqf

 

[{
    if ((radiocar distance player) < 500) then {
player setVariable ['tf_sendingDistanceMultiplicator', 4, true];
}
else { player setVariable ['tf_sendingDistanceMultiplicator', 1, true];
};
if (isNull radiocar) exitWith {(_this select 1) call CBA_fnc_removePerFrameHandler;
};
}, 10] call CBA_fnc_addPerframeHandler;


radiocar forceSpeed 0;
[radiocar,1] spawn rhs_fnc_gaz66_radioDeploy;
[radiocar, a1] remoteExec ["removeAction", 0, true];


a2 = radiocar addaction ["remove radio", { 
   [[_this, "deployed.sqf"], "BIS_fnc_execVM", true] call BIS_fnc_MP; 
  }];

deployed.sqf

 

[{
    if ((radiocar distance player) < 500) then {
player setVariable ['tf_sendingDistanceMultiplicator', 1, true];
};
if (isNull radiocar) exitWith {(_this select 1) call CBA_fnc_removePerFrameHandler;
};
}, 10] call CBA_fnc_addPerframeHandler;


radiocar forceSpeed -1;
[radiocar,0] spawn rhs_fnc_gaz66_radioDeploy;
[radiocar, a2] remoteExec ["removeAction", 0, true];


a1 = radiocar addaction ["déploy radio", { 
   [[_this, "deploy.sqf"], "BIS_fnc_execVM", true] call BIS_fnc_MP; 
  }];

thank you very much  ! you help me so much !

  • Like 1

Share this post


Link to post
Share on other sites

Glad you got it solved- I was definitely over complicating it!

Share this post


Link to post
Share on other sites

I don't know hallyg, I think you are right to be cautious about the network portion of the script.

 

For instance lets say we have 10 players on the server, everyone has just started and each have got their action from the vehicle init.

Now 1 player goes up and raises the mast via his action. So 10 network messages get sent out, one for each client.

[[_this, "deploy.sqf"], "BIS_fnc_execVM", true] call BIS_fnc_MP;
 

10 players are all calling

[radiocar,1] spawn rhs_fnc_gaz66_radioDeploy;
only needs to be the client who the vehicle is local to for the contained setFuel command as animateDoor is global.

 

And each player calls

[radiocar, a2] remoteExec ["removeAction", 0, true];
RemoteExecing it to all other players so thats 10x10 = 100 network messages.

Plus 10 messages put in the JIP queue.

 

Then it happens all over again for mast down. Now if the mast has been put up, taken down, put up. You now have 30 messages in the JIP queue that a connecting client would have to process. :/ and as object inits are done before persistent functions it could be possible to leave a joining client with no action.

Using a1 a2 for removing actions is also open for error if there are other actions used in the mission as you cannot guarantee the actionID is correct and the same for all clients.

And this problem is compounded by n^numberOfPlayers * number of times the mast has been changed.

Description.ext

class CfgFunctions
{
	class GAZ_mast
	{
		tag = "LARs";
		class mast
		{
			file = "functions";
			class radioVehicle {};
			class toggleRadioVehicle {};
		};
	};
};
functions\fn_radioVehicle.sqf

//LARs_fnc_radioVehicle
//
//[ vehicle ] call LARs_fnc_radioVehicle
//

params[ "_radioVehicle", [ "_isInit", true ] ];

//If we are initialising could be from..
//script - server or client
//from init box - server or client
if ( _isInit ) exitWith {
	
	//If this vehicle has not already been initialised
	if !( _radioVehicle in ( missionNamespace getVariable [ "RadioVehicles", [] ] ) ) then {
		
		//If we cannot suspend re-spawn script
		if !( canSuspend ) exitWith {
			_this spawn LARs_fnc_radioVehicle;
		};
		
		//Wait until the mission has started
		waitUntil{ time > 0 };
				
		if ( isServer ) then {
			//Create a unique name for the vehicle
			//will use name given in editor if there is one
			[ _radioVehicle, "RadioVehicle" ] call BIS_fnc_objectVar;
			
			//Update global list of radio Vehicles
			missionNamespace setVariable [ "RadioVehicles", ( missionNamespace getVariable [ "RadioVehicles", [] ] ) + [ _radioVehicle ], true ];
			
			//Assign remote function to be called by vehicles RHS mast script
			_remote_fnc = format[ "{ _this remoteExec [ 'LARs_fnc_toggleRadioVehicle', 0, 'RVToggle_%1' ] }", vehicleVarName _radioVehicle ];
			_radioVehicle setVariable [ "rhs_eh_gaz66_deploy", ( _radioVehicle getVariable [ "rhs_eh_gaz66_deploy", [] ] ) + [ _remote_fnc ], true ];
			
			//Init clients
			[ _radioVehicle, false ] remoteExec [ "LARs_fnc_radioVehicle", 0, format[ "initRV_%1", vehicleVarName _radioVehicle ] ];
			
			_radioVehicle addEventHandler [ "Killed", {
				params[ "_killed" ];
				
				//Remove JIP queue function calls
				remoteExec [ "", format[ "initRV_%1", vehicleVarName _killed ] ];
				remoteExec [ "", format[ "RVToggle_%1", vehicleVarName _killed ] ];
				
				//Remove vehicle from Global list
				RadioVehicles set[ RadioVehicles find _killed, objNull ];
				publicVariable "RadioVehicles";
				
				//Remove client action
				[ _killed, false ] remoteExec [ "LARs_fnc_radioVehicle", 0 ];
			}];
			
			//ReInit respawning radio vehicles
			//do we need respawn on a vehicle?
			//most vehicle respawners actually make a copy not respawn
			_radioVehicle addEventHandler [ "Respawn", {
				params[ "_new" ];
				
				[ _new ] spawn LARs_fnc_radioVehicle;
			}];
			
		}else{
			//Call master init on the server
			[ _radioVehicle ] remoteExec [ "LARs_fnc_radioVehicle", 2 ];
		};
	};
};


//Init client
if ( hasInterface ) then {
	
	//Remove vehicles action if we are informing the client that the vehicle is dead
	if !( alive _radioVehicle ) exitWith {
		_actionID = _radioVehicle getVariable [ "RVActionID", -1 ];
		if !( _actionID isEqualTo -1 ) then {
			_radioVehicle removeAction _actionID;
		};
	};
	
	//Wait for availability of player and make sure mast has finished any current animations
	waitUntil{ !isNull player && ( _radioVehicle doorPhase "mast_source" ) in [ 0, 1 ] };

	//Add action to radio Vehicle and store it locally
	_radioVehicle setVariable [ "RVActionID", _radioVehicle addAction[ [ "Deploy Mast", "Fold Mast" ] select ( _radioVehicle doorPhase "mast_source" ), {
		params [ "_target", "_caller", "_id" ];
		
		//Call RHS mast script where vehicle is local
		[ _target, ( _target doorPhase "mast_source" ) *-1 +1 ] remoteExec [ "rhs_fnc_gaz66_radioDeploy", _target ];
		
						//hide action if we are the driver or mast is currently animating
	},[],1,false,true,"","!( driver _target isequalto _this ) && { _target doorPhase 'mast_source' in [ 0, 1 ] }"]];
	
	//Start EH to look after player TF vars when in range of a radio vehicle
	if ( isNil "RadioVehiclesEH" ) then {

		RadioVehiclesEH = addMissionEventHandler [ "EachFrame", {
			//If we have reached a new check timeout and we have some valid radio vehicles
			if (
				missionNamespace getVariable[ "RVLastCheck", time ] <= time &&
				{ count ( RadioVehicles select { !isNull _x } ) > 0 }
			) then {
				
				//Remove null vehicles
				RadioVehicles = RadioVehicles select { !isNull _x };
				
				//default TF multiplier
				_multiplier = 1;
				
				//Check range to all radio vehicles
				{
					if ( _x doorPhase "mast_source" isEqualTo 1 ) then {
						if ( player distanceSqr _x < 500^2 ) then {
							//If in range change multiplier
							_multiplier = 4;
						};
					};
				}forEach RadioVehicles;
				
				//If the multiplier is different from our current setting
				if !( _multiplier isEqualTo ( player getVariable [ "tf_sendingDistanceMultiplicator", 1 ] ) ) then {
					//Update player TF var - does this need to be globally set?
					player setVariable ['tf_sendingDistanceMultiplicator', _multiplier, true ];
				};
				
				//Set next check time
				missionNamespace setVariable [ "RVLastCheck", time + 10 ]; //10 seconds between checks
			};
		}];
	};
	
};
functions\fn_toggleRadioVehicle.sqf

//LARs_fnc_toggleRadioVehicle
//
//Called remotely by LARs_fnc_radioVehicle
//

params[ "_radioVehicle", "_deployed" ];

//Incase we are calling on a JIPed player wait here until his RV action is available
waitUntil { !isNil { _radioVehicle getVariable "RVActionID" } };

switch ( _deployed ) do {
	//deploying
	case ( 1 ) : {
		_radioVehicle setUserActionText [ _radioVehicle getVariable "RVActionID", "Fold Mast" ];
	};
	//retracting
	case ( 0 ) : {
		_radioVehicle setUserActionText [ _radioVehicle getVariable "RVActionID", "Deploy Mast" ];
	};
};
Sorry i really didnt want to go into explaining locality and server/client architecture as it i a big topic and can be hard to get your head around so I thought an example would be better for you to play around with. I have heavily commented it so you can follow what is happening.

The bit that maybe the most confusing is the //Assign remote function to be called by vehicles RHS mast script, the RHS function ''rhs_fnc_gaz66_radioDeploy" will also call some code for you, if supplied in the vehicles variable 'rhs_eh_gaz66_deploy', so i use this as a call back to update all clients actions for that vehicle.

Think i have covered most usage variants, can be init from anywhere and allows for multiple radio vehicles to exist. example mission

  • Like 1

Share this post


Link to post
Share on other sites

Brilliant - Thanks for taking the time to write such a detailed explanation.

Will give this a more thorough look when I have some free time later on today

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

×