Jump to content
Sign in to follow this  
1para{god-father}

Help with Script please

Recommended Posts

I am playing with the Vehicle Respawn script by by Tophe of Östgöta Ops [OOPS] v1.7

I am trying to get the add action if the vehicle is destroyed so it will load up the ammo box again. but i get no Add action to load , any idea why and where i am going wrong ? the name is keeping the same i.e "MHQ_1" but no action comes up ?

It does on my PC but on the DEDI it does not work ?

My code is from..... // This checks if it's the MHQ being respawned

Thanks


=========================================================
*/

if (!isServer) exitWith {};

// Define variables
_unit = _this select 0;
_delay = if (count _this > 1) then {_this select 1} else {30};
_deserted = if (count _this > 2) then {_this select 2} else {120};
_respawns = if (count _this > 3) then {_this select 3} else {0};
_explode = if (count _this > 4) then {_this select 4} else {false};
_dynamic = if (count _this > 5) then {_this select 5} else {false};
_unitinit = if (count _this > 6) then {_this select 6} else {};
_haveinit = if (count _this > 6) then {true} else {false};

_hasname = false;
_unitname = vehicleVarName _unit;
if (isNil _unitname) then {_hasname = false;} else {_hasname = true;};
_noend = true;
_run = true;
_rounds = 0;

if (_delay < 0) then {_delay = 0};
if (_deserted < 0) then {_deserted = 0};
if (_respawns <= 0) then {_respawns= 0; _noend = true;};
if (_respawns > 0) then {_noend = false};

_dir = getDir _unit;
_position = getPosASL _unit;
_type = typeOf _unit;
_dead = false;
_nodelay = false;


// Start monitoring the vehicle
while {_run} do 
{	
sleep (2 + random 10);
     if ((getDammage _unit > 0.8) and ({alive _x} count crew _unit == 0)) then {_dead = true};

// Check if the vehicle is deserted.
if (_deserted > 0) then
{
	if ((getPosASL _unit distance _position > 10) and ({alive _x} count crew _unit == 0) and (getDammage _unit < 0.8)) then 
	{
		_timeout = time + _deserted;
		sleep 0.1;
	 	waitUntil {_timeout < time or !alive _unit or {alive _x} count crew _unit > 0};
		if ({alive _x} count crew _unit > 0) then {_dead = false}; 
		if ({alive _x} count crew _unit == 0) then {_dead = true; _nodelay =true}; 
		if !(alive _unit) then {_dead = true; _nodelay = false}; 
	};
};

// Respawn vehicle
     if (_dead) then 
{	
	if (_nodelay) then {sleep 0.1; _nodelay = false;} else {sleep _delay;};
	if (_dynamic) then {_position = getPosASL _unit; _dir = getDir _unit;};
	if (_explode) then {_effect = "M_TOW_AT" createVehicle getPosASL _unit; _effect setPosASL getPosASL _unit;};
	sleep 0.1;

	deleteVehicle _unit;
	sleep 2;
	_unit = _type createVehicle _position;

	// This checks if it's the MHQ being respawned and if so, sets the vehicle name back to "MHQ1" so the scripts all keep working.
	if (_type == "BAF_Merlin_HC3_D") then {
		_VarName = "CH2";
		_unit SetVehicleVarName _VarName;
		_unit Call Compile Format ["%1=_This ; PublicVariable ""%1""",_VarName];
		sleep 1;
		// If for some reason the ammo box is still alive, give the option to load it again.
		if (alive mhq2_ammobox) then {
			_null = CH2 addaction ["Load ammobox", "attachammo1\attach_ammobox.sqf"];
		};
	};
	if (_type == "BAF_Offroad_D") then {
		_VarName = "MHQ_1";
		_unit SetVehicleVarName _VarName;
		_unit Call Compile Format ["%1=_This ; PublicVariable ""%1""",_VarName];
		sleep 1;
		// If for some reason the ammo box is still alive, give the option to load it again.
		if (alive mhq1_ammobox) then {
			_null = MHQ_1 addaction ["Load ammobox", "attachammo\attach_ammobox.sqf"];
		};
	};
//		

	_unit setPosASL _position;
	_unit setDir _dir;

	if (_haveinit) then 
				{_unit setVehicleInit format ["%1;", _unitinit];
				processInitCommands;};
	if (_hasname) then 
				{_unit setVehicleInit format ["%1 = this; this setVehicleVarName ""%1""",_unitname];
				processInitCommands;};
	_dead = false;

	// Check respawn amount
	if !(_noend) then {_rounds = _rounds + 1};
	if ((_rounds == _respawns) and !(_noend)) then {_run = false;};
};
};

Edited by psvialli

Share this post


Link to post
Share on other sites

if (!isServer) exitWith {};

The actions are only added on server. Thus, they show up in editor and not on dedi. Action needs to be added on every machine it should be available.

Share this post


Link to post
Share on other sites

When you want to add an action, you need to make the server to tell clients to add it.

Share this post


Link to post
Share on other sites

setvehicleinit + processinitcommands

or

addpublicvariableeventhandler + publicvariable

Share this post


Link to post
Share on other sites

Looking at the code it has :

if (_haveinit) then 
{_unit setVehicleInit format ["%1;", _unitinit];
processInitCommands;};

Would this not process the INI line again, I have the following in the init line in the vehicle.

_null = mhq_1 addaction ["Load ammobox","attachammo\attach_ammobox.sqf"];

Sorry A little confused as to what your explaining , as still learning.

If I take out

if (!isServer) exitWith {};

It All works but i get 2 x vehicle spawns

Share this post


Link to post
Share on other sites

setVehicleInit doesn't execute the init field again, despite the name of the command. It just adds something new that will be executed on all machines (even for JIPs).

Share this post


Link to post
Share on other sites

Thanks but getting very confused :)

So how can I call the below when the vehicle is respawned so i get the Addaction again.

MHQ_1 addaction ["Load ammobox", "attachammo1\attach_ammobox.sqf"];

sorry been trying for the last 2 days to get thsi to work!

Cheers

Share this post


Link to post
Share on other sites
MHQ_1 setvehicleinit "this addaction ['Load ammobox', 'attachammo1\attach_ammobox.sqf'];";
processinitcommands;

Share this post


Link to post
Share on other sites

Many thanks ,

I now get the add addaction when the vehicle respawns but nothing happend when i click it - it's like it is not firering any code , i put a simple Hint in the attach_ammobox.sqf and it did not show the hint , but it did before the respawn

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  

×