Jump to content
MrFata

Vehicle Rearm, Refuel and Repair Script

Recommended Posts

Im looking for a vehicle repair, refuel and rearm script.

Ive tried a couple from arma 2 and they dont work, it seems the arma 3 commands are different for these three functions.

Has anyone made progress on this?

Post your current progress here and maybe we can figure this out together.

Share this post


Link to post
Share on other sites

I think it would have to be.. a marker with a script that makes anything within that marker perfect.

Share this post


Link to post
Share on other sites

You could just add an action to the vehicle init:

this addAction ["Repair", "repair.sqs"]

Then in repair.sqs

_truck = _this select 0

_truck setdammage 0

exit

For weapons it is only slightly more complex but I haven't tried it on Arma3 yet -

In the init of a vehicle put :

this execVM "rearm.sqf";

Then create a file called rearm.sqf -

 
_v=_this;
_mags=magazines _v;

while{true}do{
{if(not(_x in magazines _v))then{_v addmagazine _x;};}foreach _mags;
_v setfuel 1;
sleep(10);
};

This script would do the fuel as well.

Share this post


Link to post
Share on other sites

here you go (from our arma2 missions)

//in mission.sqm
class Sensors
{
	items=3;
	class Item0
	{
		position[]={4619.7158,0.19623651,-1617.5906};
		timeoutMin=1;
		timeoutMid=1;
		timeoutMax=1;
		interruptable=1;
		age="UNKNOWN";
		text="pinit";
		name="pinit";
		expCond="local player";
		expActiv="plays = [] execVM ""scripts\pinit.sqf"";";
		class Effects
		{
		};
	};
	class Item1
	{
		position[]={9645.6133,13,2998.0623};
		a=400;
		b=180;
		angle=90;
		rectangular=1;
		activationBy="ANY";
		age="UNKNOWN";
		text="airport";
		name="AirportIn";
		class Effects
		{
		};
	};
	class Item2
	{
		position[]={8441.6699,678.59814,10571.127};
		a=40;
		b=40;
		angle=50;
		activationBy="WEST";
		repeating=1;
		interruptable=1;
		age="UNKNOWN";
		name="farp1";
		class Effects
		{
		};
	};
};
};

make a folder in your mission folder called "scripts" and place these into it

//scripts\pinit.sqf
_cthread = [] execVM "scripts\MainThreadC.sqf";
//and any other player clientside scripts you care to run at player join

//scripts\mainthreadC.sqf
EGG_EVO_Repair = 
{
_vec = (vehicle player);
_type = typeOf vehicle player;

if(getDammage _vec > 0 or fuel _vec < 0.98 and not (_vec isKindOf "Man")) then
{
	_inrepairzone = ((_vec in list AirportIn) or (_vec in list farp1) );//your sensor zones in the mission named "Airportin" or "farp1" etc
	if(((_vec in list AirportIn) or (_vec in list farp1) ) and _vec != player and speed _vec > -2 and speed _vec < 2 and position _vec select 2 < 2.0 and (local _vec)) then
	{
		 titleText [localize "STR_M04t83", "PLAIN DOWN",0.3];
		 for [{_loop2=0}, {_loop2<1}, {_loop2=_loop2}] do
		 {
		    sleep 0.200;	    		    
		    if (getDammage _vec > 0) then {_vec setDammage ((getDammage _vec)-0.0125);};
		    if (Fuel _vec < 1) then {_vec setFuel ((Fuel _vec)+0.0125);};
		    if (getDammage _vec == 0 and Fuel _vec == 1) then {_loop2=1;};
		    if(_vec != vehicle player or speed _vec < -2 or speed _vec > 2 or position _vec select 2 > 2.0) then {_loop2=1;titleText [localize "STR_M04t84", "PLAIN DOWN",0.3];};
		    _dam = (getDammage _vec)*100;
		    _ful = (Fuel _vec)*100;
		    hint format["Damage: %1\nFuel: %2",Round _dam,Round _ful];
		};
		_vec setVehicleAmmo 1;	
	};
};
};

for [{_loop=0}, {_loop<1}, {_loop=_loop}] do
{
[] call EGG_EVO_Repair;
sleep 1.01;
};

this is the standard repair/refuel/rearm function for Arma1 and2 for us

just go into your mission in the editor and move the trigger/sensors about until they are where you want them

i'll be polishing this up for use at all fuel stations too soon (repair not rearm!)

Edited by eggbeast

Share this post


Link to post
Share on other sites

just say i wanted it to be a helipad what would i put in the init

Edited by hellstorm77

Share this post


Link to post
Share on other sites
just say i wanted it to be a helipad what would i put in the init

I second this. Dose the script change for applying to the helicopters?

Also is there a good video that shows how this process works? That would be most helpful.

Share this post


Link to post
Share on other sites
I second this. Dose the script change for applying to the helicopters?

Also is there a good video that shows how this process works? That would be most helpful.

You mean you want the script to work when the Vehicle is on the helipad?

You would create a trigger in on the helipad and put the activation line on the on act box.

Thanks everyone with your scripts will try them out and see which one works.

---------- Post added at 01:53 PM ---------- Previous post was at 01:10 PM ----------

It seems non of them worked.

Nothing happened on ether of them, maybe the commands are wrong?

Share this post


Link to post
Share on other sites
here you go (from our arma2 missions)

//in mission.sqm
class Sensors
{
	items=3;
	class Item0
	{
		position[]={4619.7158,0.19623651,-1617.5906};
		timeoutMin=1;
		timeoutMid=1;
		timeoutMax=1;
		interruptable=1;
		age="UNKNOWN";
		text="pinit";
		name="pinit";
		expCond="local player";
		expActiv="plays = [] execVM ""scripts\pinit.sqf"";";
		class Effects
		{
		};
	};
	class Item1
	{
		position[]={9645.6133,13,2998.0623};
		a=400;
		b=180;
		angle=90;
		rectangular=1;
		activationBy="ANY";
		age="UNKNOWN";
		text="airport";
		name="AirportIn";
		class Effects
		{
		};
	};
	class Item2
	{
		position[]={8441.6699,678.59814,10571.127};
		a=40;
		b=40;
		angle=50;
		activationBy="WEST";
		repeating=1;
		interruptable=1;
		age="UNKNOWN";
		name="farp1";
		class Effects
		{
		};
	};
};
};

make a folder in your mission folder called "scripts" and place these into it

//scripts\pinit.sqf
_cthread = [] execVM "scripts\MainThreadC.sqf";
//and any other player clientside scripts you care to run at player join

//scripts\mainthreadC.sqf
EGG_EVO_Repair = 
{
_vec = (vehicle player);
_type = typeOf vehicle player;

if(getDammage _vec > 0 or fuel _vec < 0.98 and not (_vec isKindOf "Man")) then
{
	_inrepairzone = ((_vec in list AirportIn) or (_vec in list farp1) );//your sensor zones in the mission named "Airportin" or "farp1" etc
	if(((_vec in list AirportIn) or (_vec in list farp1) ) and _vec != player and speed _vec > -2 and speed _vec < 2 and position _vec select 2 < 2.0 and (local _vec)) then
	{
		 titleText [localize "STR_M04t83", "PLAIN DOWN",0.3];
		 for [{_loop2=0}, {_loop2<1}, {_loop2=_loop2}] do
		 {
		    sleep 0.200;	    		    
		    if (getDammage _vec > 0) then {_vec setDammage ((getDammage _vec)-0.0125);};
		    if (Fuel _vec < 1) then {_vec setFuel ((Fuel _vec)+0.0125);};
		    if (getDammage _vec == 0 and Fuel _vec == 1) then {_loop2=1;};
		    if(_vec != vehicle player or speed _vec < -2 or speed _vec > 2 or position _vec select 2 > 2.0) then {_loop2=1;titleText [localize "STR_M04t84", "PLAIN DOWN",0.3];};
		    _dam = (getDammage _vec)*100;
		    _ful = (Fuel _vec)*100;
		    hint format["Damage: %1\nFuel: %2",Round _dam,Round _ful];
		};
		_vec setVehicleAmmo 1;	
	};
};
};

for [{_loop=0}, {_loop<1}, {_loop=_loop}] do
{
[] call EGG_EVO_Repair;
sleep 1.01;
};

this is the standard repair/refuel/rearm function for Arma1 and2 for us

just go into your mission in the editor and move the trigger/sensors about until they are where you want them

i'll be polishing this up for use at all fuel stations too soon (repair not rearm!)

Alright. So I did this and it is working. One question though... what does the pinit do? Also is there a way to slow the refueling process down a tad?

Share this post


Link to post
Share on other sites
Also is there a way to slow the refueling process down a tad?

Decrease this value.

if (Fuel _vec < 1) then {_vec setFuel ((Fuel _vec)+[b][u]0.0125[/u][/b]);};

Share this post


Link to post
Share on other sites
Alright. So I did this and it is working. One question though... what does the pinit do? Also is there a way to slow the refueling process down a tad?

How did you manage to get it to work?

EDIT: Nvm had to manually add the trigger nameed farp1

Edited by MrFata

Share this post


Link to post
Share on other sites

do i need to put this in the mission.sqf

//in mission.sqm

class Sensors

{

items=3;

class Item0

{

position[]={4619.7158,0.19623651,-1617.5906};

timeoutMin=1;

timeoutMid=1;

timeoutMax=1;

interruptable=1;

age="UNKNOWN";

text="pinit";

name="pinit";

expCond="local player";

expActiv="plays = [] execVM ""scripts\pinit.sqf"";";

class Effects

{

};

};

class Item1

{

position[]={9645.6133,13,2998.0623};

a=400;

b=180;

angle=90;

rectangular=1;

activationBy="ANY";

age="UNKNOWN";

text="airport";

name="AirportIn";

class Effects

{

};

};

class Item2

{

position[]={8441.6699,678.59814,10571.127};

a=40;

b=40;

angle=50;

activationBy="WEST";

repeating=1;

interruptable=1;

age="UNKNOWN";

name="farp1";

class Effects

{

};

};

};

};

Share this post


Link to post
Share on other sites

Here is one of the best vehicle repair/reload scripts I have used.

Place a trigger, activation anybody present.

Condition Line: ("LandVehicle" countType thislist > 0) && count (thislist unitsBelowHeight 1) > 0

On Act Line: _xhandle= [(thislist select 0)] execVM "v_reload.sqf"

v_reload.sqf

private ["_config","_count","_i","_magazines","_object","_type","_type_name"];

_object = _this select 0;

_type = typeof _object;

if (_object isKindOf "ParachuteBase") exitWith {};

//if (!local _object) exitWith {};

if (!alive _object) exitWith {};
_object setFuel 0;
_object setVehicleAmmo 1;	// Reload turrets / drivers magazine

_type_name = typeOf _object;

_object vehicleChat format ["Servicing %1... Please stand by...", _type];

_magazines = getArray(configFile >> "CfgVehicles" >> _type >> "magazines");

if (count _magazines > 0) then {
_removed = [];
{
	if (!(_x in _removed)) then {
		_object removeMagazines _x;
		_removed = _removed + [_x];
	};
} forEach _magazines;
{
	_object vehicleChat format ["Reloading %1", _x];
	sleep 4;
	if (!alive _object) exitWith {};
	_object addMagazine _x;
} forEach _magazines;
};

_count = count (configFile >> "CfgVehicles" >> _type >> "Turrets");

if (_count > 0) then {
for "_i" from 0 to (_count - 1) do {
	scopeName "xx_reload2_xx";
	_config = (configFile >> "CfgVehicles" >> _type >> "Turrets") select _i;
	_magazines = getArray(_config >> "magazines");
	_removed = [];
	{
		if (!(_x in _removed)) then {
			_object removeMagazines _x;
			_removed = _removed + [_x];
		};
	} forEach _magazines;
	{
		_object vehicleChat format ["Reloading %1", _x];
		sleep 4;
		if (!alive _object) then {breakOut "xx_reload2_xx"};
		_object addMagazine _x;
		sleep 4;
		if (!alive _object) then {breakOut "xx_reload2_xx"};
	} forEach _magazines;
	// check if the main turret has other turrets
	_count_other = count (_config >> "Turrets");

	if (_count_other > 0) then {
		for "_i" from 0 to (_count_other - 1) do {
			_config2 = (_config >> "Turrets") select _i;
			_magazines = getArray(_config2 >> "magazines");
			_removed = [];
			{
				if (!(_x in _removed)) then {
					_object removeMagazines _x;
					_removed = _removed + [_x];
				};
			} forEach _magazines;
			{
				_object vehicleChat format ["Reloading %1", _x]; 
				sleep 4;
				if (!alive _object) then {breakOut "xx_reload2_xx"};
				_object addMagazine _x;
				sleep 4;
				if (!alive _object) then {breakOut "xx_reload2_xx"};
			} forEach _magazines;
		};
	};
};
};
_object setVehicleAmmo 1;	// Reload turrets / drivers magazine

sleep 4;
if (!alive _object) exitWith {};
_object vehicleChat "Repairing...";
_object setDamage 0;
sleep 4;
if (!alive _object) exitWith {};
_object vehicleChat "Refueling...";
while {fuel _object < 0.99} do {
//_object setFuel ((fuel _vehicle + 0.1) min 1);
_object setFuel 1;
sleep 0.01;
};
sleep 4;
if (!alive _object) exitWith {};
_object vehicleChat format ["%1 is ready...", _type_name];

if (true) exitWith {};

Share this post


Link to post
Share on other sites

Hellstorm, share with the community my friend, don't keep it too yourself hahah;)

Share this post


Link to post
Share on other sites

Vehicle resupply

Place a helipad marker name it Base_Rearm1 then place a trigger name that Rearmlist1. in the activation put Blufor, present. On Act Line: {[_x] execVM "rearm.sqf"} foreach thislist;

rearm.sqf

// Written by Weasel [PXS] - andy@andymoore.ca

// This script rearms, refuels, and repairs vehicles.
// Vehicles must be less than height 2 (typically landed, if air vehicles) and must remain in the
// trigger area for 3 seconds. It then drains all fuel, repairs, rearms, and refuels.
//
// Setup a trigger area to activate this (F3 in map editor) with the following settings:
//
// Trigger REPEATEDLY, BLUFOR, PRESENT
// Name: Rearmlist
// Condition: this;
// Activation: {[_x] execVM "rearm.sqf"} foreach thislist;
// 
// Warning: If this trigger area overlaps another trigger area (such as ammo-transport Scripts), sometimes
// things don't work as planned. Keep this seperate if you can.

_unit = _this select 0;

// Don't start the script until the unit is below a height of 2, and make sure they hold that 
// height for at least 3 seconds.
WaitUntil{(getPos _unit select 2)<2}; 
sleep 3;
if((getPos _unit select 2)>2) exitWith{};
WaitUntil{speed _unit < 2};
sleep 3;
if(speed _unit > 5) exitWith{};

// Make sure unit is inside one of these lists (trigger areas)
if( not (_unit in list rearmlist1) and  not (_unit in list rearmlist2) and not (_unit in list rearmlist3) and not (_unit in list rearmlist4)) exitWith{};



_unit setFuel 0;
_unit VehicleChat "Repairing...";
sleep 15;
_unit setDammage 0;
_unit VehicleChat "Rearming...";
sleep 10;
_unit setVehicleAmmo 1;
_unit VehicleChat "Refueling...";
sleep 5;
_unit setFuel 1;
_unit VehicleChat "Finished.";

if(true) exitWith{};

---------- Post added at 14:48 ---------- Previous post was at 14:46 ----------

(not sure if this works with air vehicles)

Edited by hellstorm77

Share this post


Link to post
Share on other sites

I believe there are bugs (to be expected.. it's ALPHA!!) with the ArmA3 landscape where some land is just not exactly at "0" height. I had difficulty with these scripts running until I removed the height restrictions, even though my helo had fully landed. The script would just not work.

Share this post


Link to post
Share on other sites
Here is one of the best vehicle repair/reload scripts I have used.

Place a trigger, activation anybody present.

Condition Line: ("LandVehicle" countType thislist > 0) && count (thislist unitsBelowHeight 1) > 0

On Act Line: _xhandle= [(thislist select 0)] execVM "v_reload.sqf"

v_reload.sqf

private ["_config","_count","_i","_magazines","_object","_type","_type_name"];

_object = _this select 0;

_type = typeof _object;

if (_object isKindOf "ParachuteBase") exitWith {};

//if (!local _object) exitWith {};

if (!alive _object) exitWith {};
_object setFuel 0;
_object setVehicleAmmo 1;	// Reload turrets / drivers magazine

_type_name = typeOf _object;

_object vehicleChat format ["Servicing %1... Please stand by...", _type];

_magazines = getArray(configFile >> "CfgVehicles" >> _type >> "magazines");

if (count _magazines > 0) then {
_removed = [];
{
	if (!(_x in _removed)) then {
		_object removeMagazines _x;
		_removed = _removed + [_x];
	};
} forEach _magazines;
{
	_object vehicleChat format ["Reloading %1", _x];
	sleep 4;
	if (!alive _object) exitWith {};
	_object addMagazine _x;
} forEach _magazines;
};

_count = count (configFile >> "CfgVehicles" >> _type >> "Turrets");

if (_count > 0) then {
for "_i" from 0 to (_count - 1) do {
	scopeName "xx_reload2_xx";
	_config = (configFile >> "CfgVehicles" >> _type >> "Turrets") select _i;
	_magazines = getArray(_config >> "magazines");
	_removed = [];
	{
		if (!(_x in _removed)) then {
			_object removeMagazines _x;
			_removed = _removed + [_x];
		};
	} forEach _magazines;
	{
		_object vehicleChat format ["Reloading %1", _x];
		sleep 4;
		if (!alive _object) then {breakOut "xx_reload2_xx"};
		_object addMagazine _x;
		sleep 4;
		if (!alive _object) then {breakOut "xx_reload2_xx"};
	} forEach _magazines;
	// check if the main turret has other turrets
	_count_other = count (_config >> "Turrets");

	if (_count_other > 0) then {
		for "_i" from 0 to (_count_other - 1) do {
			_config2 = (_config >> "Turrets") select _i;
			_magazines = getArray(_config2 >> "magazines");
			_removed = [];
			{
				if (!(_x in _removed)) then {
					_object removeMagazines _x;
					_removed = _removed + [_x];
				};
			} forEach _magazines;
			{
				_object vehicleChat format ["Reloading %1", _x]; 
				sleep 4;
				if (!alive _object) then {breakOut "xx_reload2_xx"};
				_object addMagazine _x;
				sleep 4;
				if (!alive _object) then {breakOut "xx_reload2_xx"};
			} forEach _magazines;
		};
	};
};
};
_object setVehicleAmmo 1;	// Reload turrets / drivers magazine

sleep 4;
if (!alive _object) exitWith {};
_object vehicleChat "Repairing...";
_object setDamage 0;
sleep 4;
if (!alive _object) exitWith {};
_object vehicleChat "Refueling...";
while {fuel _object < 0.99} do {
//_object setFuel ((fuel _vehicle + 0.1) min 1);
_object setFuel 1;
sleep 0.01;
};
sleep 4;
if (!alive _object) exitWith {};
_object vehicleChat format ["%1 is ready...", _type_name];

if (true) exitWith {};

I tried this with no luck..

Do i need to change the trigger name or text or leave them blank?

I put the v_reload.sqf in my mission folder with all of my other sqfs

copied and pasted your condition and act lines.

I want this to work for heli's. perhaps it doesnt?

Also I put a heli pad on top of the trigger. Maybe this has something to do with it?

I am new to this.

Share this post


Link to post
Share on other sites

place a trigger in the activation put Blufor, repeatedly, present... On the condition Type ("AllVehicles" countType thislist > 0) && ((getpos (thislist select 0)) select 2 < 1) On Act Line: rearm = [(thislist select 0)] execVM "vehicle_service.sqf";

vehicle_service.sqf

private ["_object", "_time", "_magazines","_cmagazines"];

_object = _this select 0; 
_time = 10;
_cmagazines = _object magazinesTurret[0];
_object vehicleChat "Servicing...please hold position";
sleep _time;
if (isEngineOn _object) exitwith {_object vehicleChat "Service Cancelled"};
_object vehicleChat "Repairing...";
sleep _time;
if (isEngineOn _object) exitwith {_object vehicleChat "Service Cancelled"};
_object setDammage 0;
_object vehicleChat "Rearming...";
_magazines = getArray(configFile >> "CfgVehicles" >> _type >> "magazines");

if (count _magazines > 0) then {
_removed = [];
{
	if (!(_x in _removed)) then {
		_object removeMagazines _x;
		_removed set [count _removed, _x];
	};
} forEach _magazines;
{
	if (!isDedicated) then {[_object, format ["Reloading %1", _x]] call XfVehicleChat};
	sleep x_reload_time_factor;
	if (!alive _object) exitWith {};
	_object addMagazine _x;
} forEach _magazines;
};

_turrets = [configFile >> "CfgVehicles" >> _type >> "Turrets"] call X_fnc_returnVehicleTurrets;

_reloadTurrets = {
private ["_turrets", "_path"];
_turrets = _this select 0;
_path = _this select 1;

private ["_i"];
_i = 0;
while {_i < (count _turrets)} do {
	private ["_turretIndex", "_thisTurret"];
	_turretIndex = _turrets select _i;
	_thisTurret = _path + [_turretIndex];

	_magazines = _object magazinesTurret _thisTurret;
	if (!alive _object) exitWith {};
	_removed = [];
	{
		if (!(_x in _removed)) then {
			_object removeMagazinesTurret [_x, _thisTurret];
			_removed set [count _removed, _x];
		};
	} forEach _magazines;
	if (!alive _object) exitWith {};
	{
		_mag_disp_name = [_x,2] call XfGetDisplayName;
		if (_mag_disp_name == "") then {_mag_disp_name = _x};
		if (!isDedicated) then {[_object,format ["Reloading %1", _mag_disp_name]] call XfVehicleChat};
		sleep x_reload_time_factor;
		if (!alive _object) exitWith {};
		_object addMagazineTurret [_x, _thisTurret];
		sleep x_reload_time_factor;
		if (!alive _object) exitWith {};
	} forEach _magazines;

	if (!alive _object) exitWith {};

	[_turrets select (_i + 1), _thisTurret] call _reloadTurrets;
	_i = _i + 2;
	if (!alive _object) exitWith {};
};
};

[_turrets, []] call _reloadTurrets;

if (!alive _object) exitWith {};

//{_object addMagazineTurret [_x,[0]];} forEach _magazines;
sleep _time;
if (isEngineOn _object) exitwith {_object vehicleChat "Service Cancelled"};
_object setVehicleInit "this setVehicleAmmo 1"; processInitCommands;
_object vehicleChat "Refuelling...";
sleep _time;
if (isEngineOn _object) exitwith {_object vehicleChat "Service Cancelled"};
_object setFuel 1;
_object vehicleChat "Servicing complete";

if (true) exitwith { };
// 

Share this post


Link to post
Share on other sites

Here's a proof of concept mission.

Farp_Test.Stratis

You start off in the air with a crippled AH9 (and she'll handle like a dog). Fly south 1km to the FARP and land.

Remain on the FARP for approx 20 seconds while your vehicle refuels and repairs and re-arms, then take off.

N.B.: vehicle_service.sqf scripts is in scripts\vehicle_service.sqf path.

----- UPDATE 13th March 2013 -----

FARP now pops smoke when your within 750m of it's location to help guide you in.

Edited by Beerkan

Share this post


Link to post
Share on other sites

Working on my own maintenance script with a buddy. Made a lot of progress today but still. Something is missing... We can't acheive to make "vehiclechat" work. I can't even manage to make sidechat work ingame. Any clue ? :x

Share this post


Link to post
Share on other sites

#21 Thanks so much! Work really fine with all vehicle types!

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

×