Jump to content
Sign in to follow this  
thelane618

Script to make vehicle be locked upon respawn

Recommended Posts

Hey everyone i am trying to check and see if there is a script or something i can put in a certain vehicles init line to make it locked upon respawn? I am using Tophes vehicle respawn script.

Lets assume this is my current init.

veh = [this, 1, 3, 0,] execVM "vehicle.sqf";

Edited by thelane618

Share this post


Link to post
Share on other sites

Thank you for your help in resolving this matter....*Facepalm* ( personally i think it is rude to question someones motives when they are asking for help but here you go )

In a custom domination we keep certain vehicles locked IE: artillery so people dont spam arty into the base. But people are aware that if you destroy a vehicle it respawns unlocked so they have been able to bypass this and troll the server while we have no admins on.

Share this post


Link to post
Share on other sites

I think it's lazy to not even try to search for an answer but there you go. There's almost 70 results for a search for "lock" almost all of them would point you to the wiki for the lock command which is what you need.

Just use this as your init:

veh = [this, 1, 3, 0, FALSE, FALSE, "this lock true"] execVM "vehicle.sqf"; 

Your respawn script should have an option for init field if it's v1.81 so that should do it.

Then again, if these are vehicles that players aren't supposed to be in anyway, get more creative! Setup getIn eventHandlers that launch players into the air as if they were artillery shells if they get in these types of vehicles. :)

Share this post


Link to post
Share on other sites

Thank you for the reply i really appreciate the help, I am running 1.81 and i copied the exact line you have there and it is still not working. The vehicle still spawns unlocked. : /

Also i really did try to search for that and came up blank on a quick fix using tophes. I didnt mean to double post.

Share this post


Link to post
Share on other sites

Next thing to try would be to "manually" lock it after respawn by editing the vehicle.sqf.

Around line 180 or so, just after the private "_sCommand" block of code add something like this:

	if ((typeOf _unit) == "B_WhatEver_Class_F") then {
		_unit lock true;
	};

Changing B_WhatEver_Class_F to be whatever class you wanted to auto-lock.

Share this post


Link to post
Share on other sites

Thanks for the additional help however i do not have 180 lines of code in our vehicle.sqf

This is what i have.

/*  
==================================================================================================================
 Simple Vehicle Respawn Script v1.81 for Arma 3
 by Tophe of �stg�ta Ops [OOPS]

 Put this in the vehicles init line:
 veh = [this] execVM "vehicle.sqf"


 Options:
 There are some optional settings. The format for these are:
 veh = [object, Delay, Deserted timer, Respawns, Effect, Dynamic] execVM "vehicle.sqf"

 Default respawn delay is 30 seconds, to set a custom respawn delay time, put that in the init as well. 
 Like this:
 veh = [this, 15] execVM "vehicle.sqf"

 Default respawn time when vehicle is deserted, but not destroyed is 120 seconds. To set a custom timer for this 
 first set respawn delay, then the deserted vehicle timer. (0 = disabled) 
 Like this:  
 veh = [this, 15, 10] execVM "vehicle.sqf"

 By default the number of respawns is infinite. To set a limit first set preceding values then the number of respawns you want (0 = infinite).
 Like this:
 veh = [this, 15, 10, 5] execVM "vehicle.sqf"

 Set this value to TRUE to add a special explosion effect to the wreck when respawning.
 Default value is FALSE, which will simply have the wreck disappear.
 Like this:
 veh = [this, 15, 10, 5, TRUE] execVM "vehicle.sqf"

 By default the vehicle will respawn to the point where it first was when the mission started (static). 
 This can be changed to dynamic. Then the vehicle will respawn to the position where it was destroyed. 
 First set all preceding values then set TRUE for dynamic or FALSE for static.
 Like this:
 veh = [this, 15, 10, 5, TRUE, TRUE] execVM "vehicle.sqf"

 If you you want to set the INIT field of the respawned vehicle, first set all other values, then set init commands. 
 Those must be inside quotations.
 Like this:
 veh = [this, 15, 10, 5, TRUE, FALSE, "this setDammage 0.5"] execVM "vehicle.sqf"

 Default values of all settings are:
 veh = [this, 30, 120, 0, FALSE, FALSE] execVM "vehicle.sqf"


Contact & Bugreport: [email]cwadensten@gmail.com[/email]
================================================================================================================== */


private ["_hasname","_delay","_deserted","_respawns","_noend","_dead","_nodelay","_timeout","_position","_dir","_effect","_rounds","_run","_unit","_explode","_dynamic","_unitinit","_haveinit","_unitname","_type"];
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 (5 + (random 20));
 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
{
   _nearPlayers = false;
   {
     if ((_x distance _unit) < PARAMS_VehicleRespawnDistance) exitWith { _nearPlayers = true; };
   } forEach playableUnits;
	if ((getPosASL _unit distance _position > 10) and ({alive _x} count crew _unit == 0) and (getDammage _unit < 0.8) and !_nearPlayers) 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_AT" createVehicle getPosASL _unit; _effect setPosASL getPosASL _unit;};
	sleep 0.1;

	deleteVehicle _unit;
	sleep 2;
	_unit = _type createVehicle _position;
	_unit setPosASL _position;
	_unit setDir _dir;

	_dead = false;

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

Edited by thelane618

Share this post


Link to post
Share on other sites

Hmm, drastically different version. :) Put it towards the end between:

_unit setDir _dir;

       if ((typeOf _unit) == "B_WhatEver_Class_F") then {
           _unit lock true;
       };  

_dead = false;

Share this post


Link to post
Share on other sites

Ah gotcha, great thats working! now i have the second issue i am working on. Is it possible to unlock an entire class of vehicles by using the class name on a trigger. IE : If X is not detected Unlock Xclassname of vehicles?

Ive tried putting in the on Act. B _MBT_01_mlrs_F lock False and obviously its not working because it is looking for a unit name not a class name.

I tried using a unit name but as soon as the vehicle respawns it loses its name.

Edit: Or i guess in a way to respawn a vehicle with a unique unit name would work as well.

Share this post


Link to post
Share on other sites

Here's the copy of vehicle.sqf I had which supports both init and name. Also the "add something special to one class of vehicle" thing.

/*  
==================================================================================================================
 Simple Vehicle Respawn Script v1.81 for Arma 3
 by Tophe of Östgöta Ops [OOPS]

 Put this in the vehicles init line:
 veh = [this] execVM "vehicle.sqf"


 Options:
 There are some optional settings. The format for these are:
 veh = [object, Delay, Deserted timer, Respawns, Effect, Dynamic] execVM "vehicle.sqf"

 Default respawn delay is 30 seconds, to set a custom respawn delay time, put that in the init as well. 
 Like this:
 veh = [this, 15] execVM "vehicle.sqf"

 Default respawn time when vehicle is deserted, but not destroyed is 120 seconds. To set a custom timer for this 
 first set respawn delay, then the deserted vehicle timer. (0 = disabled) 
 Like this:  
 veh = [this, 15, 10] execVM "vehicle.sqf"

 By default the number of respawns is infinite. To set a limit first set preceding values then the number of respawns you want (0 = infinite).
 Like this:
 veh = [this, 15, 10, 5] execVM "vehicle.sqf"

 Set this value to TRUE to add a special explosion effect to the wreck when respawning.
 Default value is FALSE, which will simply have the wreck disappear.
 Like this:
 veh = [this, 15, 10, 5, TRUE] execVM "vehicle.sqf"

 By default the vehicle will respawn to the point where it first was when the mission started (static). 
 This can be changed to dynamic. Then the vehicle will respawn to the position where it was destroyed. 
 First set all preceding values then set TRUE for dynamic or FALSE for static.
 Like this:
 veh = [this, 15, 10, 5, TRUE, TRUE] execVM "vehicle.sqf"

 If you you want to set the INIT field of the respawned vehicle, first set all other values, then set init commands. 
 Those must be inside quotations.
 Like this:
 veh = [this, 15, 10, 5, TRUE, FALSE, "this setDammage 0.5"] execVM "vehicle.sqf"

 Default values of all settings are:
 veh = [this, 30, 120, 0, FALSE, FALSE] execVM "vehicle.sqf"


Contact & Bugreport: cwadensten@gmail.com
================================================================================================================== */

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;

// Kronzky's code
KRON_StrToArray = {
private["_in","_i","_arr","_out"];
_in=_this select 0;
_arr = toArray(_in);
_out=[];
for "_i" from 0 to (count _arr)-1 do {
	_out=_out+[toString([_arr select _i])];
};
_out
};

KRON_StrLen = {
private["_in","_arr","_len"];
_in=_this select 0;
_arr=[_in] call KRON_StrToArray;
_len=count (_arr);
_len
};

KRON_Replace = {
private["_str","_old","_new","_out","_tmp","_jm","_la","_lo","_ln","_i"];
_str=_this select 0;
_arr=toArray(_str);
_la=count _arr;
_old=_this select 1;
_new=_this select 2;
_na=[_new] call KRON_StrToArray;
_lo=[_old] call KRON_StrLen;
_ln=[_new] call KRON_StrLen;
_out="";
for "_i" from 0 to (count _arr)-1 do {
	_tmp="";
	if (_i <= _la-_lo) then {
		for "_j" from _i to (_i+_lo-1) do {
			_tmp=_tmp + toString([_arr select _j]);
		};
	};
	if (_tmp==_old) then {
		_out=_out+_new;
		_i=_i+_lo-1;
	} else {
		_out=_out+toString([_arr select _i]);
	};
};
_out
};
// End of Kronzky's code

// 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_AT" createVehicle getPosASL _unit; _effect setPosASL getPosASL _unit;};
	sleep 0.1;

	deleteVehicle _unit;
	sleep 2;
	_unit = _type createVehicle _position;
	_unit setPosASL _position;
	_unit setDir _dir;
       if (_haveinit) then {
		//_unit setVehicleInit format ["%1;", _unitinit];
           //processInitCommands;
		// Modified by BearBison
		private ["_IDunit", "_sCommand"];
		_IDunit = format["(objectFromNetID '%1')", netID _unit];
		_sCommand=[format["%1",_unitinit],"this",format["%1",_IDunit]] call KRON_Replace;
		// End of code modified by BearBison
		// Modified by naong and AgentRev
           [call compile format["[{%1}]",_sCommand], "BIS_fnc_spawn", true, true] spawn BIS_fnc_MP;
       };
       if (_hasname) then {
           //_unit setVehicleInit format ["%1 = this; this setVehicleVarName ""%1""",_unitname];
           //processInitCommands;
		private "_sCommand";
           _sCommand = format["[{(objectFromNetID '%1') setVehicleVarName '%2';}]", netID _unit, _unitname];
		[call compile format["%1",_sCommand],"BIS_fnc_spawn", true, true] spawn BIS_fnc_MP;
		_unit call compile format ["%1=_This; PublicVariable '%1'",_unitname];
       };
	if ((typeOf _unit) == "B_Boat_Armed_01_minigun_F") then {
		[[_unit, ["<t color='#ff1111'>DEPLOY CRRC</t>", {[_this select 0] call RSG_fnc_spawnCRRC}]], "RSG_fnc_addAction", nil, true] spawn BIS_fnc_MP;
	};



	// End of code modified by naong
       _dead = false;

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

Share this post


Link to post
Share on other sites

Ah ok this is great, I really dont want to be a huge pain so im not sure if im asking too much of you but im looking at this and i see the area that im supposed to edit but im not sure what to set to accomplish what im looking for.

Lets assume that i wanted once an MLRS is destroyed to have to respawn named...i dunno coconut and locked.

As well as having a kajman respawn and named toast and locked.

Would you be able to give me a quick rundown of how to do so?

PS: im assuming i would do the lock the same way as before, so i guess the big question is how to change the name of the unit using that script.

I tried this but it didnt seem to work

if ((typeOf _unit) == "B_MBT_01_mlrs_F") then {

_unit lock true & setIdentity "Coconut";;

};

Edited by thelane618

Share this post


Link to post
Share on other sites

For the name you should just give it a name in the editor. It should keep it after 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  

×