Jump to content
Johnsonsbil29

Trying to create a repair trigger

Recommended Posts

Hey guys!

I'm trying to make a trigger-box that repairs my vehicles when i park in it.

 

My code so far looks like this:

hint "Repairing, Refueling, and Rearming. Standby 2 minutes";

[] spawn {

sleep 120; 

{_x Setdamage 0} Foreach thislist;
{_x Setfuel 1} Foreach thislist;
{_x setVehicleAmmo 1} Foreach thislist;

};

 

Returns this error: Error Undefined Variable in expression thislist

 

The code is a collection of stuff i have found on the internet, as i have no real knowledge of coding in ARMA3.

How can i fix it? 

 

Thanks in advance! :) 

  • Like 1

Share this post


Link to post
Share on other sites

Search for generic vehicle service script. It will do all that you need and has a fancy interface

  • Like 1

Share this post


Link to post
Share on other sites
1 hour ago, Johnsonsbil29 said:

Returns this error: Error Undefined Variable in expression thislist

This is because thisList is undefined in spawn's scope.

 

1 hour ago, Johnsonsbil29 said:

How can i fix it?

You need to pass thisList to spawned code:

thislist spawn {
	sleep 120;

	{_x Setdamage 0} Foreach _this;
	{_x Setfuel 1} Foreach _this;
	{_x setVehicleAmmo 1} Foreach _this;
};
  • Like 2

Share this post


Link to post
Share on other sites

Hello Johnsonsbil29!

 

1. Create a  trigger

 

type none
activation blufor
activation type present
repeatable
this and ((getPos (thisList select 0)) select 2 < 1)
_handle = [(thisList select 0)] execVM "rearmVehicle.sqf";

 

2. Create a  "rearmVehicle.sqf"

 

// type none
// activation blufor
// activation type present
// repeatable
// this and ((getPos (thisList select 0)) select 2 < 1)
// _handle = [(thisList select 0)] execVM "rearmVehicle.sqf";
                                                       
private ["_veh"];
_veh = _this select 0;

if (_veh isKindOf "ParachuteBase" || !alive _veh) exitWith {};

if (!(_veh isKindOf "LandVehicle")) exitWith { 
	_veh vehicleChat "This pad is for Vehicles service only, soldier!"; 
};

_veh vehicleChat "Servicing vehicle, Stand by...";

_veh setFuel 0;

//---------- RE-ARMING

sleep 15;

_veh vehicleChat "Re-arming ...";

//---------- REPAIRING

sleep 15;

_veh vehicleChat "Repairing ...";

//---------- REFUELING

sleep 20;

_veh vehicleChat "Refueling ...";

//---------- FINISHED

sleep 20;

_veh setDamage 0;
_veh vehicleChat "Repaired (100%).";

_veh setVehicleAmmo 1;
_veh vehicleChat "Re-armed (100%).";

_veh setFuel 1;
_veh vehicleChat "Refuelled (100%).";

sleep 2;

_veh vehicleChat "Service complete. Ready to GO.!";

 

You can make a unique repair pad for helicopters , planes , or certain type of vehicle "classname", by changing:

 

if (!(_veh isKindOf "helicopter")) exitWith { 
	_veh vehicleChat "This pad is for Helicopter service only, soldier!"; 
};

_veh vehicleChat "Servicing Helicopter, Stand by...";

or

if (!(_veh isKindOf "plane")) exitWith { 
	_veh vehicleChat "This pad is for plane service only, soldier!"; 
};

_veh vehicleChat "Servicing airplane, Stand by...";

and

if (!(_veh isKindOf "B_UAV_02_CAS_F")) exitWith { 
	_veh vehicleChat "This pad is for UAV service only, soldier!"; 
};

 

Share this post


Link to post
Share on other sites
47 minutes ago, Schatten said:

This is because thisList is undefined in spawn's scope.

 

You need to pass thisList to spawned code:


thislist spawn {
	sleep 120;

	{_x Setdamage 0} Foreach _this;
	{_x Setfuel 1} Foreach _this;
	{_x setVehicleAmmo 1} Foreach _this;
};

 

This will repair every vehicle in the list after 120 seconds, no matter if it's still in the trigger area or not.

Triggers are best used for one time only stuff or basic things like detecting if a unit is in its area, a repair script is a bit more complex if done right.

Best would be to spawn a loop and get rid of the trigger.

 

Simple example:


GOM_fnc_autoRepair = {

	params ["_repairStation","_repairPerSecond","_distance"];

	while {alive _repairStation} do {

		_nearVehicles = getPosATL _repairStation nearEntities [["Air", "Car", "Ship", "Tank"], _distance];

		{

			_busy = _x getVariable ["GOM_fnc_busy",false];

			if (!_busy) then {

				_repair = [_x,_repairStation,_repairPerSecond,_distance] spawn {

					params ["_veh","_repairStation","_repairPerSecond","_distance"];
					_veh setVariable ["GOM_fnc_busy",true,true];
					sleep 1;
					["Turn off the engine and remain stationary during the repair"] remoteExec ["hintSilent",driver _veh];
					["click"] remoteExec ["playSound",driver _veh];
					_timer = time + 10;//give players 10 seconds to turn off engine
					waitUntil {!alive _veh OR _veh distance2D _repairStation >= _distance OR (isEngineOn _veh AND time > _timer) OR !isEngineOn _veh};

					if (!alive _veh) exitWith {};

					if (_veh distance2D _repairStation >= _distance) exitWith {};

					if (isEngineOn _veh AND time > _timer) exitWith {
					["Repair aborted, you failed to turn off the engine!\nPlease leave the area!"] remoteExec ["hintSilent",driver _veh];
					["click"] remoteExec ["playSound",driver _veh];

					waitUntil {_veh distance2D _repairStation >= _distance * 1.3};
					["You are now allowed to enter the repair area again!"] remoteExec ["hintSilent",driver _veh];
					["click"] remoteExec ["playSound",driver _veh];
					_veh setVariable ["GOM_fnc_busy",false,true];

					};
					sleep 1;
					//exceptions handled, now we repair

					_timeNeeded = damage _veh / _repairPerSecond;

					[format["Repair will begin in 3 seconds and will take %1 seconds\nDo not move the vehicle or start the engine or the repair will be aborted!",_timeNeeded]] remoteExec ["hintSilent",driver _veh];
					["click"] remoteExec ["playSound",driver _veh];
					sleep 3;
					_timeout = time + _timeNeeded;

					while {alive _veh AND !isEngineOn _veh AND damage _veh > 0 AND time < _timeout} do {

					[format["---Repair in Progress---\nVehicle Damage: %1%2!",(damage _veh * 100),"%"]] remoteExec ["hintSilent",driver _veh];
						sleep 1;
						_veh setDamage (damage _veh - _repairPerSecond);
					};
					if (alive _veh AND !isEngineOn _veh) then {

											["Repair finished!\nHave a nice day!"] remoteExec ["hintSilent",driver _veh];
					["click"] remoteExec ["playSound",driver _veh];
						_veh setDamage 0;
						sleep 3;
						[""] remoteExec ["hintSilent",driver _veh];
						sleep 7;
						_veh setVariable ["GOM_fnc_busy",false,true];

						} else {

					["Repair aborted, you failed follow the instructions!\nPlease leave the area!"] remoteExec ["hintSilent",driver _veh];
					["click"] remoteExec ["playSound",driver _veh];

					waitUntil {_veh distance2D _repairStation >= _distance * 1.3};
					["You are now allowed to enter the repair area again!"] remoteExec ["hintSilent",driver _veh];
					["click"] remoteExec ["playSound",driver _veh];
					_veh setVariable ["GOM_fnc_busy",false,true];

					};
				}
			}
		} forEach _nearVehicles;
		sleep 5;//check for vehicles every 5 seconds
	}
};

_repairObject = someObject;
_repairPerSecond = 0.1;//with 0.5 repairPerSecond a vehicle with 0.5 damage will take 5 seconds to be repaired to 100%
_distance = 10;

_repair = [_repairObject,_repairPerSecond,_distance] spawn GOM_fnc_autoRepair;

Place an ammoCrate or other object of preference, name it someObject, hop into a damaged vehicle and drive towards it.

 

Cheers

  • Like 2

Share this post


Link to post
Share on other sites

In opposite what Grumpy Old Man said here is my trigger example

vehrepair.sqf

params [
    ["_pos",[],[[]]],
    ["_side",sideUnknown,[sideUnknown]]
];

private ["_dir","_markerText","_instance","_repairPos", "_objects", "_normal", "_repairTrigger", "_repairMarker", "_repairMarkerType"];

_dir = 0;
_markerText = "Field";
_instance = floor (random 1000);
_composition = [
    ["Land_HelipadRescue_F",[0.0358887,0.520386,0],0,1,0,[0,0],"","",true,false],
    ["Land_LandMark_F",[-6.70825,0.497559,0],0,1,0,[0,0],"","",true,false],
    ["Land_LandMark_F",[6.87939,0.624878,0],0,1,0,[0,0],"","",true,false],
    ["Land_LandMark_F",[6.93457,-2.95435,0],0,1,0,[0,0],"","",true,false],
    ["Land_LandMark_F",[-6.83813,-3.38745,0],0,1,0,[0,0],"","",true,false],
    ["Land_LandMark_F",[-6.66528,4.56262,0],0,1,0,[0,0],"","",true,false],
    ["Land_LandMark_F",[6.90259,4.23962,0],0,1,0,[0,0],"","",true,false],
    ["Land_fs_feed_F",[9.16479,-3.66418,0],0,1,0,[0,0],"","",true,false],
    ["Land_Tank_rust_F",[10.105,0.335938,0],88.7784,1,0,[0,0],"","",true,false]
];

_repairPos = [_pos, 0, 100, 10, 0, 0.6, 0, [], []] call BIS_fnc_findSafePos;
_objects = [_repairPos, _dir, _composition,0.0] call BIS_fnc_ObjectsMapper;
{
_normal = surfaceNormal (position _x);
_x setVectorUp _normal;
} forEach _objects;

_repairTrigger = createTrigger ["EmptyDetector", _repairPos, false];
_repairTrigger setTriggerArea [5, 5, _dir, true, 3];
_repairTrigger setTriggerActivation ["ANY", "PRESENT", true];
_repairTrigger setTriggerStatements [

"
private _vehicles = thisList select {_x isKindOf 'LandVehicle' || {_x isKindOf 'Helicopter'}};
private _vehicle = _vehicles select 0;
this && {!isNil '_vehicle'} && {(speed _vehicle) isEqualTo 0}
",
"
if (isServer) then {

private _fnc_sendNotif = {
params [['_oapos',[],[[]]],['_notifclass','',['']],['_text','',['']],
['_playersinOA',(allPlayers inAreaArray [_this select 0, 1000, 1000, 0, false, -1]),[[]]]
];
if !( _playersinOA isEqualTo [] ) then {
    if (_text isEqualTo '') then {
        0 = [_notifclass,[]] remoteExecCall ['BIS_fnc_showNotification', _playersinOA, false];
    } else {
        0 = [_notifclass,[toUpper _text]] remoteExecCall ['BIS_fnc_showNotification', _playersinOA, false];
    };
};
};
private _vehicles = thisList select {_x isKindOf 'LandVehicle' || {_x isKindOf 'Helicopter'}};
private _vehicle = _vehicles select 0;
0 = [_vehicle] spawn {  

params [['_veh',objNull,[objNull]]];  
private ['_turrets','_gethit','_fuel','_damage','_damaged','_proceded'];

_turrets = !((allTurrets _veh) isEqualTo []);  
_gethit = getAllHitPointsDamage _veh;
_fuel = ((fuel _veh) < 1);  
_damage = _gethit select 2;
_damaged = ((count (_damage select {_x > 0})) > 0);   
_proceded = false;  
sleep 2;  

if (_damaged) then {  

(vehicle _veh) setDamage 0;  
_proceded = true;  
};  
if (_fuel) then {  

0 = [_veh, 1] remoteExecCall ['setFuel', _veh, false];  
_proceded = true;  
};  

if (_turrets) then {  

{
if !( _veh turretLocal _x ) then {
_0 = [_veh, 1] remoteExecCall ['setVehicleAmmoDef',(_veh turretOwner _x), false];
}else{
_veh setVehicleAmmoDef 1;
};
}forEach (allTurrets _veh);
_proceded = true;  
};  

if (_proceded) then {  

[getPos _veh, 'vehrepaired', '', crew _veh] call _fnc_sendNotif;  

};
};  
};
",
""];

_repairMarker = createMarker [format ["field_repair_%1",_instance], _repairPos];
_repairMarkerType = ["o_service","b_service","n_service"] select ([EAST,WEST,INDEPENDENT] find _side);
_repairMarker setMarkerShape "ICON";
_repairMarker setMarkerType _repairMarkerType;
_repairMarker setMarkerText (format ["%1 Vehicle Service",_markerText]);

 

description.ext

class CfgNotifications {

	class vehrepaired	{
	
		title = "VEHICLE REPAIR";
		iconPicture = "\A3\Ui_f\data\GUI\Cfg\Ranks\general_gs.paa";
		description = "VEHICLE SERVICED";
		color[] = {0.3,0.6,0.3,1};
		sound = "FD_Finish_F";
		duration = 8;
		priority = 0;
	};
};

 

init.sqf

if (isServer) then {

0 = [some empty pos, side] execVM "vehrepair.sqf";

};

 

  • Like 1

Share this post


Link to post
Share on other sites
7 hours ago, Grumpy Old Man said:
8 hours ago, Schatten said:

You need to pass thisList to spawned code:



thislist spawn {
	sleep 120;

	{_x Setdamage 0} Foreach _this;
	{_x Setfuel 1} Foreach _this;
	{_x setVehicleAmmo 1} Foreach _this;
};

This will repair every vehicle in the list after 120 seconds, no matter if it's still in the trigger area or not.

Sure. To prevent this, you need to set up trigger's timer of "timeout" type and use this code in on act. field:

{
	_x setDamage 0;
	_x setFuel 1;
	_x setVehicleAmmo 1;
} forEach thisList;

Share this post


Link to post
Share on other sites
1 minute ago, Schatten said:

Sure. To prevent this, you need to set up trigger's timer of "timeout" type.

Then it would repair anyone in the list 120 seconds after the timeout went through, or am I missing something here?

 

Cheers

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

×