Jump to content
thy_

[HELP] Reliable vehicle rearming (from vanilla and mod vehicles)

Recommended Posts

EDITED on Oct 13th, 2022:


Folks, here is the best solution I have developed to rearm ground vehicles (works fine with nautical too but not really reliable with air vehicles, mainly from RHS, CUP, etc), so feel free to check the code and point fixes, changes, improvements. 

 

THY_VO_functions.hpp

Spoiler

class THY_VO_functions 
{
	tag = "THY"; 
	
	class rearming
	{
		file = "rearming";
		
		class VO_parameters
		{
			preInit = 1;
		};
		
		class VO_globalFunctions
		{
			preInit = 1;
		};

		class VO_coreGrd
		{ 
			preInit = 1;
		};
	};
};

 

 

fn_VO_parameters.sqf

Spoiler

if (!isServer) exitWith {};

// EDITOR'S OPTIONS:

	VO_debugMonitor = true;           // true = turn on to test your script config / false = turn it off.
	VO_feedbackMsgs = true;           // true = the station shows all service msgs for the driver (recommended) / false = turns off the most msgs, keeping the critical ones. Default: true.
	
	// GROUND DOCTRINE SERVICES
	VO_groundDoctrine = true;         // true = the mission needs ground stations / false = doesn't need.
 
		VO_grdServRearm = true;       // true = rearm stations for ground veh are available / false = not available.
		VO_grdServFull = true;        // true = chosen assets will bring all available ground services in one place / false = no assets for full service.
		VO_grdServiceRange = 20;      // in meters, the area around the station that identifies the ground vehicle to be serviced. Default: 20.
		VO_grdCooldown = 5;          // in seconds, time among each available ground services. Default: 10.
		
		// Define which assets (classnames) are ground full (repair, refuel, rearm) stations:
		VO_grdFullAssets = ["Land_RepairDepot_01_tan_F"];
		
		// Define which assets (classnames) are ground rearm stations:
		VO_grdRearmAssets = [];
		
	// BE CAREFUL, HIGHLY RECOMMENDED DO NOT CHANGE ANY BELOW:
		// Vehicle types recognized by doctrine:
		VO_grdVehicleTypes = [ "Car","Motorcycle","Tank","WheeledAPC","TrackedAPC" ];

		// ACE detection for server:
		if ( isClass(configfile >> "CfgPatches" >> "ace_medical") OR isClass(configfile >> "CfgPatches" >> "ace_repair") ) then { VO_isACErun = true } else { VO_isACErun = false };
	
		// Debug initial counting:
		VO_grdCyclesDone = 0;

 

 

fn_VO_globalFunctions.sqf

Spoiler


THY_fnc_VO_debugMonitor = {
	// This function: helps the mission's editor to find errors out and possible fixes.
	// return nothing.

	private ["_vehCategory"];

	_vehCategory = [vehicle player] call BIS_fnc_objectType;
	
	format ["\n\n||||||||  DEBUG MONITOR  ||||||||\n\n%1.\n\n- - - YOU'RE BY - - -\n%2\n%3\n\n- - - GROUND - - -\n%4\nRearming = %5\nGround while-cycles done: %6x\n\n", VO_debug_ACE, _vehCategory, if ((_vehCategory select 0) isNotEqualTo "Soldier") then {typeOf (vehicle player)} else {"on foot"}, VO_groundDoctrine, VO_grdServRearm, VO_grdCyclesDone] remoteExec ["hintSilent"];

	true
};


THY_fnc_VO_compatibility = {
	// This function: compatibility checking with Arma 3 vanilla assets and ACE services.
	// Returns nothing.
	
	params ["_fullAssets", "_reaAssets"];
	
	if ( VO_isACErun ) then               // detecting basic ACE components to check if ACE is running in server.
	{
		// Stations conformity with ACE:
		{
			_x setVariable ["ACE_isRepairFacility", 0];  // 0 = disable
			[_x, 0] call ace_refuel_fnc_setFuel;
			[_x] call ace_rearm_fnc_disable;
		
		} forEach _fullAssets + _reaAssets;
		
		// Vehicles conformity with ACE:
		{
			_x setVariable ["ACE_isRepairVehicle", 0];  // 0 = disable
			[_x, 0] call ace_refuel_fnc_setFuel;
			[_x] call ace_rearm_fnc_disable;
			
		} forEach allMissionObjects "Tank" + allMissionObjects "Truck";  // https://community.bistudio.com/wiki/ArmA:_Armed_Assault:_CfgVehicles
		
		VO_debug_ACE = "ACE ON";
	
	} else {
	
		// Stations conformity with NO ACE:
		{
			_x setRepairCargo 0;
			_x setFuelCargo 0;
			_x setAmmoCargo 0;
			
		} forEach _fullAssets + _reaAssets;
		
		// Vehicles conformity with NO ACE:
		// not needed.
		
		VO_debug_ACE = "ACE OFF";
	};

	true
};


THY_fnc_VO_playersAlive = {
	// This function identifies only and all humam players are alive in-game.
	// Returns _playersAlive array.

	private _playersAlive = [];
	_playersAlive = (allPlayers - (entities "HeadlessClient_F")) select {alive _x};

	_playersAlive  // returning.
};


THY_fnc_VO_isDroneConnected = {
	// This function checks wether the player is connected.
	// Returns _isDroneConnected bool.

	params [["_player", objNull]];
	private ["_isDroneConnected", "_connected"];

	_isDroneConnected = false;

	_connected = getConnectedUAV _player;
	if (!isNull _connected) then { _isDroneConnected = true };

	_isDroneConnected  // Returning.
};


THY_fnc_VO_addConnectedDrone = {
	// This function understands if vehicle is a drone and, if so, adds to the current vehicle list next to the player.
	// Returns _currentPlayerVehList array.

	params [["_player", objNull], ["_doctrine", ""], "_playerVehList"];
	private ["_isDroneConnected", "_connected"];

	_isDroneConnected = [_player] call THY_fnc_VO_isDroneConnected;

	if ( !_isDroneConnected ) exitWith { _playerVehList  /* Returning. */};

	_currentPlayerVehList = _playerVehList;

	_connected = getConnectedUAV _player;

	switch (_doctrine) do
	{
		case "grd":  // Ground doctrine vehicles
		{
			if (_connected isKindOf "Car" OR _connected isKindOf "Motorcycle" OR _connected isKindOf "Tank" OR _connected isKindOf "WheeledAPC" OR _connected isKindOf "TrackedAPC") then { _currentPlayerVehList append [_connected] };
		};
		case "air":  // Air doctrine vehicles
		{
			if ( _connected isKindOf "Helicopter" OR _connected isKindOf "Plane" ) then { _currentPlayerVehList append [_connected] };
		};
		case "nau":  // Nautical doctrine vehicles
		{
			if ( _connected isKindOf "Ship" OR _connected isKindOf "Submarine" ) then { _currentPlayerVehList append [_connected] };
		};
	};

	_currentPlayerVehList  // Returning.
};


THY_fnc_VO_playerVehicles = {
	// This function detects all allowed vehicles (by doctrine) in certain range from the player and set them in a list.
	// Returns the array _playerVehList.

	params [["_player", objNull], ["_allowedVehTypes", []], ["_range", 20]];
	private ["_playerVehList"];

	_playerVehList = [];

	// if player in a vehicle, it's avoid to search for new vehicles around:
	if (!isNull objectParent _player) exitWith 
	{ 
		{
			// adds the current vehicle if it's a allowed doctrine type:
			if ((vehicle _player) isKindOf _x) exitWith {_playerVehList pushBackUnique (vehicle _player)};
		
		} forEach _allowedVehTypes;

		_playerVehList  // Returning.
	};

	sleep 0.5;
	
	_playerVehList = _player nearEntities [_allowedVehTypes, _range];

	_playerVehList  // returning
};


THY_fnc_VO_isOnSurface = {
	// This function checks if the object (station or player's vehicle) is on ground or water surface. Remember, unfortunately Arma 3 command "isTouchingGround" somehow is not reliable.
	// returns _isOnSurface bool.

	params [["_obj", objNull]];
	private ["_isOnSurface"];

	_isOnSurface = true;

	// checks if the object's axis Y is NOT close enough to the ground of water surface:
	if ( (getPos _obj) select 2 > 0.2 ) then { _isOnSurface = false };

	_isOnSurface  // returning
};


THY_fnc_VO_isRearmNeeded = {
	// This function checks the mag capacity and how much ammo still remains within.
	// Returns _isRearmNeeded bool.
	
	params [["_veh", objNull]];
	private ["_isRearmNeeded", "_driverWeapons", "_gunnerWeapons", "_secGunnerWeapons", "_hasDriverNoWeapon", "_hasGunnerNoWeapon", "_hasSecGunnerNoWeapon", "_notWeaponWords", "_turretPath", "_vehMagsStr", "_vehMagDetail", "_ammoName", "_ammoInMag", "_capacityMag"];

	_isRearmNeeded = false;
	_driverWeapons = _veh weaponsTurret [-1];
	_gunnerWeapons = _veh weaponsTurret [0];
	_secGunnerWeapons = _veh weaponsTurret [1];
	_hasDriverNoWeapon = false;
	_hasGunnerNoWeapon = false;
	_hasSecGunnerNoWeapon = false;
	_notWeaponWords = ["horn", "flare"];  // add here the key-word that indicates "the ammo name" is NOT an ammo.
	
	// Extra debug for rearming:
	if ( VO_debugMonitor AND ((abs speed _veh) <= 2) ) then {
		_turretPath = [[-1], [0], [1], [0,0], [0,1], [1,0]];  // https://community.bistudio.com/wiki/Turret_Path
		{ systemChat format [">> DEBUG > Turret path %1 = %2", str _x, str (_veh weaponsTurret _x)]; sleep 2 } forEach _turretPath;
	};
	
	// Check if the turrets are not just a horn or other stuff in _notWeaponWords:
	if ( (count _driverWeapons) <= 1 ) then
	{
		if ( (count _driverWeapons) == 0 ) exitWith {_hasDriverNoWeapon = true};		
		{ _hasDriverNoWeapon = [_x, (_driverWeapons select 0), false] call BIS_fnc_inString; if ( _hasDriverNoWeapon ) exitWith {} } forEach _notWeaponWords;
	};

	if ( (count _gunnerWeapons) <= 1 ) then
	{
		if ( (count _gunnerWeapons) == 0 ) exitWith {_hasGunnerNoWeapon = true};		
		{ _hasGunnerNoWeapon = [_x, (_gunnerWeapons select 0), false] call BIS_fnc_inString; if ( _hasGunnerNoWeapon ) exitWith {} } forEach _notWeaponWords;
	};

	if ( (count _secGunnerWeapons) <= 1 ) then
	{
		if ( (count _secGunnerWeapons) == 0 ) exitWith {_hasSecGunnerNoWeapon = true};	
		{ _hasSecGunnerNoWeapon = [_x, (_secGunnerWeapons select 0), false] call BIS_fnc_inString; if ( _hasSecGunnerNoWeapon ) exitWith {} } forEach _notWeaponWords;
	};

	// Exit if the vehicle has NO weaponry for gunner and for driver:
	if ( _hasDriverNoWeapon AND _hasGunnerNoWeapon AND _hasSecGunnerNoWeapon ) exitWith {if (VO_debugMonitor) then {systemChat format [">> DEBUG > %1 has NO weaponry, then rearm IS NOT needed.", typeOf _veh]; sleep 15}; _isRearmNeeded /* Returning */};
	
	_vehMagsStr = magazinesDetail _veh;  // "120mm (2/20)[id/cr:10000011/0]".

	if ( (count _vehMagsStr) > 0 ) then 
	{
		{
			_vehMagDetail = _x splitString "([]/:)";  // ["120mm", "2", "20", "id", "cr", "10000011", "0"]
			_ammoName = _vehMagDetail select 0;
			reverse _vehMagDetail;  // ["0", "10000011", "cr", "id", "20", "2", "120mm"] coz the current ammo and ammo capacity don't change their index when reversed.
			//systemChat str _vehMagDetail;  // Extra debug: checking the index of mag details.
			_ammoInMag = parseNumber (_vehMagDetail select 5);  // string "2" convert to number 2.
			_capacityMag = parseNumber (_vehMagDetail select 4);  // string "20" convert to number 20.
	
			// Checking if rearm is needed:
			if ( _ammoInMag < (_capacityMag / 2) ) exitWith 
			{ 
				if ( VO_debugMonitor ) then {systemChat format [">> DEBUG > Magazine [%1]: %2 ammo of %3 capacity. Rearm is needed!", _ammoName, _ammoInMag, _capacityMag]; sleep 3};
				_isRearmNeeded = true;
			};
	
			//if ( VO_debugMonitor ) then {systemChat format [">> DEBUG > Magazine [%1]: %2 ammo of %3 capacity. Rearm NOT needed.", _ammoName, _ammoInMag, _capacityMag]; sleep 3};
			
		} forEach _vehMagsStr;

	} else {

		// When the armed-vehicle has NO ammo-capacity (0% ammunition in its attributes) it will force the vehicle to rearm:
		_isRearmNeeded = true;
	};
	
	_isRearmNeeded // Returning...
};


THY_fnc_VO_serviceCanceled = {
	// This function displays a message if the service process is broken.
	// Returns nothing.

	params [["_player", objNull], ["_veh", objNull], ["_stat", objNull], ["_txtServ", "The service"], ["_case", 0]];
	private ["_msgPrefix","_msg"];

	_msgPrefix = format ["%1 has been canceled!", _txtServ];

	switch (_case) do 
	{
		case 0: {_msg = format [">> %1", _msgPrefix]};
		case 1: {_msg = format [">> %1 Keep the %2 engine OFF at station.", _msgPrefix, typeOf _veh]};
		case 2: {_msg = format [">> %1 The station needs to be closer to the ground.", _msgPrefix]};
		case 3: {_msg = format [">> %1 Keep your %2 on the ground.", _msgPrefix, typeOf _veh]};
		case 4: {_msg = format [">> The station %1 doesn't meet the conditions to rearm the %2 yet!", typeOf _stat, typeOf _veh]};
		//case 5: {_msg = format [">> To rearm, someone in control of a vehicle weapon is required (gunner or commander seat)."]};
		case 6: {_msg = format [">> %1 Careful, the %2 has NO ammo. Try to rearm!", _msgPrefix, typeOf _veh]};
	};
	// Finally it prints out feedback message:
	if ( _player in _veh ) then 
	{
		format ["%1", _msg] remoteExec ["systemChat", crew _veh];

	} else {

		format ["%1", _msg] remoteExec ["systemChat", _player];
	};

	sleep 10;  // punishment fixed cooldown.

	true
};


THY_fnc_VO_busyService = {
	// This function prints a message out when some service station's busy.
	// Returns nothing.

	params [["_player", objNull], ["_stat", objNull]];

	sleep 2;
	if ( _player in (vehicle _player) ) then 
	{
		format [">> Someone is using the service at %1. Hold...", typeOf _stat] remoteExec ["systemChat", crew (vehicle _player)];

	} else {

		format [">> %1, someone is using the service at %2. Hold...", name _player, typeOf _stat] remoteExec ["systemChat", _player];
	};

	true
};


THY_fnc_VO_preparingService = {
	// This function tells to the player some service will starts.
	// returns _isServProgrs bool;

	params [["_player", objNull], ["_stat", objNull], ["_veh", objNull], ["_currentRng", 20], ["_servCoolDown", 10], ["_isRearm", false], ["_isDroneConnected", false]];
	private ["_isServProgrs", "_waitTxt"];

	_isServProgrs = false;

	// Fist check if the vehicle is on ground or water surface:
	if ( !([_veh] call THY_fnc_VO_isOnSurface) ) exitWith {_isServProgrs /* Returning */};
	
	sleep 2;

	if ( (alive _player) AND (alive _stat) AND (alive _veh) ) then 
	{
		if ( (_isDroneConnected) OR ((_player distance _stat) <= _currentRng) ) then 
		{
			_waitTxt = "";
			if ( _servCoolDown >= 5 ) then { _waitTxt = format ["Wait %1 secs...", _servCoolDown] };

			if ( _player in _veh ) then
			{
				format [">> Preparing a service to %1 at station... %2", typeOf _veh, _waitTxt] remoteExec ["systemChat", crew _veh];

			} else {

				format [">> Preparing a service to %1 at station... %2", typeOf _veh, _waitTxt] remoteExec ["systemChat", _player];
			};

			sleep _servCoolDown;
		};
	};

	// Checks again if preparation of rearming the player's veh is on ground or water:
	if ( _isRearm AND !([_veh] call THY_fnc_VO_isOnSurface) ) exitWith 
	{
		[_player, _veh, _stat, "The service", 3] call THY_fnc_VO_serviceCanceled;

		_isServProgrs  // Returning.
	};

	// Checks if preparation of repairing or refueling the player keeps the vehicle's engine off:
	if ( (!_isRearm AND isEngineOn _veh) OR !alive _player OR !alive _stat OR !alive _veh OR (!_isDroneConnected AND ((_player distance _stat) > _currentRng)) ) exitWith 
	{
		[_player, _veh, _stat, "The service", 0] call THY_fnc_VO_serviceCanceled;
		
		_isServProgrs  // Returning.
	};

	_isServProgrs = true; 

	_isServProgrs  // Returning.
};


THY_fnc_VO_checkingMsg = {
	// This function tells to the player some service is running.
	// Returns nothing.

	params [["_player", objNull], ["_stat", objNull], ["_veh", objNull], ["_resource", "resource"], ["_isNautic", false]];

	if ( VO_feedbackMsgs ) then 
	{ 
		if ( _player in _veh ) then 
		{
			format [">> Checking the %1 of %2...", _resource, typeOf _veh] remoteExec ["systemChat", crew _veh];

		} else {

			format [">> Checking the %1 of %2...", _resource, typeOf _veh] remoteExec ["systemChat", _player];
		};
	};

	true
};


THY_fnc_VO_servRearm = {
	// This function: provides the rearming functionality for the armed vehicles parked at station.
	// Returns nothing.

	params [["_player", objNull], ["_veh", objNull], ["_serv", false], ["_servRng", 20], ["_isServProgrs", false], ["_statAssets", []], ["_cooldown", 10], ["_isNautic", false], ["_hasRngChanger", false]];
	private ["_isBadAdvCond", "_isRearmNeeded", "_isDroneConnected"];
	
	if ( !_serv ) exitWith {};

	{ // forEach of _statAssets starts...

		// checking the basic station (_x) conditions:
		if ( (alive _x) AND ((_veh distance _x) <= _servRng) AND (_veh != _x) ) then 
		{
			_isRearmNeeded = [_veh] call THY_fnc_VO_isRearmNeeded;

			// checking the player's vehicle:
			if ( (alive _veh) AND (abs speed _veh < 2) AND (!underwater _veh) AND _isRearmNeeded ) then
			{

				// checking if the station is NOT busy:
				if ( !_isServProgrs ) then 
				{
					_isDroneConnected = [_player] call THY_fnc_VO_isDroneConnected;
					
					_isServProgrs = [_player, _x, _veh, _servRng, _cooldown, true, _isDroneConnected] call THY_fnc_VO_preparingService;

					if ( _isServProgrs ) then 
					{
						[_player, _x, _veh, "ammunition", _isNautic] call THY_fnc_VO_checkingMsg;
						
						// before rearming, last check if the player's vehicle and station still on conditions:
						[_player, _x, _veh, "rea", _servRng, false, _isNautic, _isDroneConnected, "rearmed", "Rearming"] call THY_fnc_VO_serviceExecution;

						_isServProgrs = false;  // station is free for the next service!
					};
				
				} else { [_player, _x] call THY_fnc_VO_busyService };
			};
		};
	
	} forEach _statAssets;

	true
};


THY_fnc_VO_serviceExecution = {
	// This function: before the service execution, it makes a last check if the player's vehicle and station still on conditions to get the service.
	// Returns nothing.
	
	params [["_player", objNull], ["_stat", objNull], ["_veh", objNull], ["_service", ""], ["_currentRng", 20], ["_isStatRngChanger", false], ["_isNautic", false], ["_isDroneConnected", false], ["_txtServ1", "fixed"], ["_txtServ2", "The service"]];
	private ["_vehCrew", "_vehType", "_isObjOnSurface", "_isRepaired", "_isRefueled", "_isRearmed", "_vehMags", "_magsRemoved", "_magsLoopChecker", "_mag"];

	_vehCrew = crew _veh;
	_vehType = typeOf _veh;

	sleep 3;

	// checks the station and vehicle current conditions:
	if ( (_isStatRngChanger OR !underwater _stat) AND (alive _stat) AND (alive _veh) AND (!underwater _veh) AND (speed _stat < 1) AND (speed _veh < 1) AND ((_veh distance _stat) <= _currentRng) ) then  // important: if the station is a range-changer, it's crucial considere large ship assets can be a bit under the water, that's why that "OR".
	{
		// Checks if player's vehicle is touching some surface:
		_isObjOnSurface = [_veh] call THY_fnc_VO_isOnSurface;
		if ( !_isObjOnSurface ) exitWith { [_player, _veh, _stat, _txtServ2, 3] call THY_fnc_VO_serviceCanceled };  // checking vehicle.
		
		// Checks if the station is touching some surface (ignore it for nautical stations):
		if ( !_isNautic ) then
		{
			_isObjOnSurface = [_stat] call THY_fnc_VO_isOnSurface;
			if ( !_isStatRngChanger AND !_isObjOnSurface ) exitWith { [_player, _veh, _stat, _txtServ2, 2] call THY_fnc_VO_serviceCanceled };  // checking station.
		};

		// Initial services status values:
		_isRepaired = false;
		_isRefueled = false;
		_isRearmed = false;

		// Executes the service requested:
		if ( (alive _player) AND (alive _stat) AND (alive _veh) AND (_isDroneConnected OR ((_player distance _stat) <= _currentRng)) ) then 
		{
			switch ( _service ) do
			{				
				case "rea":  // REARMING
				{
					
					if ( _veh isKindOf "Plane" OR _veh isKindOf "Helicopter" ) then 
					{
						// Specific solution for vehicles with pylons (air) to simplify the rearming as they work differently to turrets:
						[_veh, 1] remoteExec ["setVehicleAmmo", _veh];

						// Effects:
						playSound3D ["a3\sounds_f\sfx\ui\vehicles\vehicle_rearm.wss", _veh];
						[[1, 6, 3]] remoteExec ["addCamShake", _vehCrew];
						
						sleep 3;
						_isRearmed = true;

					} else {
					
						// Mapping all vehicle mags capacity:
						_vehMags = magazinesAllTurrets _veh;  // list of all magazines (include the empty ones) and its additional data.
						_magsRemoved = [];
						_magsLoopChecker = true;
							
						{  // Looping for remove each mag from the vehicle:
							_mag = _x select 0;  // selecting only the magazine's classname;
							
							// Removing the mag:
							_veh removeMagazineTurret [_mag, [0]];  // [magazineClassname, [turretPath]] https://community.bistudio.com/wiki/Turret_Path
							_magsRemoved pushBack _mag;

						} forEach _vehMags;
						
						{  // Looping for add again each mapped mags:
							// Check service condition before each mag reload:
							if ( ((abs speed _veh) > 1) OR ((abs speed _stat) > 1) OR (!alive _stat) OR ( (!_isDroneConnected) AND ((_player distance _stat) > _currentRng) ) ) exitWith
							{ 
								{_veh removeMagazinesTurret [_x, [0]]} forEach _magsRemoved;  // Removes the all mags, including the loaded one to avoid automatic ammo repacking;
								{_veh addMagazineTurret [_x, [0], 1]} forEach _magsRemoved;  // Forces to add again all mags but with 1 ammo only as punishment. Wirhout this line, the code wont reload again when the vehicle return to rearm because it would have all its magazines to rearm.

								[_player, _veh, _stat, "Rearming", 6] call THY_fnc_VO_serviceCanceled;

								_magsLoopChecker = false;
							};
							
							// Adding a new mag:
							_veh addMagazineTurret [_x, [0]];
							if ( VO_feedbackMsgs ) then 
							{ 
								if ( _player in _veh ) then 
								{
									format [">> Ammo added: [%1]...", _x] remoteExec ["systemChat", _vehCrew];

								} else {

									format [">> Ammo added: [%1]...", _x] remoteExec ["systemChat", _player];
								};
							};

							// Effects:
							playSound3D ["a3\sounds_f\sfx\ui\vehicles\vehicle_rearm.wss", _veh];
							[[1, 3, 3]] remoteExec ["addCamShake", _vehCrew];
							sleep 1.5;

						} forEach _magsRemoved;

						// This (setVehicleAmmo) will force the rearming for all ammo-capacity of the vehicle:
						if ( _magsLoopChecker ) then { [_veh, 1] remoteExec ["setVehicleAmmo", _veh]; _isRearmed = true };
					};
				};
			};

		} else { [_player, _veh, _stat, _txtServ2, 0] call THY_fnc_VO_serviceCanceled };
	
		sleep 3;
		
		// Service successfully complete message:
		if ( alive _veh AND (_isRepaired OR _isRefueled OR _isRearmed) ) then 
		{ 
			if ( _player in _veh ) then 
			{
				format [">> The %1 has been %2!", _vehType, toUpperANSI _txtServ1] remoteExec ["systemChat", _vehCrew];

			} else {

				format [">> The %1 has been %2!", _vehType, toUpperANSI _txtServ1] remoteExec ["systemChat", _player];
			}; 
		};
		
		sleep 3;

	} else { [_player, _veh, _stat, _txtServ2, 0] call THY_fnc_VO_serviceCanceled };

	true
};

 

 

fn_VO_coreGrd.sqf

Spoiler

// Only on the server, you dont want all players checking all players:
if ( !isServer ) exitWith {};

// GROUND SERVICES CORE / BE CAREFUL BELOW:
[] spawn {

	private ["_fullAssets","_reaAssets","_fullAndReaAssets","_allAssets","_isServProgrs","_players","_eachPlayer","_playerVehList","_currentPlayerVehList","_connected","_eachVeh"];

	sleep 1;  // avoid messages during briefing screen.
	
	// Arrays that will be populated only with the objects found out more below:
	_fullAssets = [];
	_reaAssets = [];
	_fullAndReaAssets = [];
	_allAssets = [];
	
	// If the services are allowed, find out only the assets listed (fn_VO_parameters.sqf) and present in the mission:
	if ( VO_grdServFull ) then { { _fullAssets = _fullAssets + allMissionObjects _x } forEach VO_grdFullAssets };	
	if ( VO_grdServRearm ) then { { _reaAssets = _reaAssets + allMissionObjects _x } forEach VO_grdRearmAssets };
	// Loading the main station's array without duplicated content:
	{_fullAndReaAssets pushBackUnique _x} forEach _reaAssets + _fullAssets;
	{_allAssets pushBackUnique _x} forEach _fullAndReaAssets;
	
	// Compatibility checking: 
	[_fullAssets, _reaAssets] call THY_fnc_VO_compatibility;
	
	// Initial ground work values:
	_isServProgrs = false; 
	
	while { true } do
	{
		_players = call THY_fnc_VO_playersAlive;
		
		{ // _players forEach starts...
			_eachPlayer = _x;
			
			_playerVehList = [_x, VO_grdVehicleTypes] call THY_fnc_VO_playerVehicles;

			_currentPlayerVehList = [_x, "grd", _playerVehList] call THY_fnc_VO_addConnectedDrone;
			
			{ // forEach of _currentPlayerVehList starts...
				_eachVeh = _x;
				
				[	// GROUND REARM
					_eachPlayer, _eachVeh, VO_grdServRearm, VO_grdServiceRange, _isServProgrs, _fullAndReaAssets, VO_grdCooldown, false, false
				] call THY_fnc_VO_servRearm;

			} forEach _currentPlayerVehList;
			
		} forEach _players;
		
		sleep 5;
		
		// debug:
		if ( VO_debugMonitor ) then { call THY_fnc_VO_debugMonitor; VO_grdCyclesDone = (VO_grdCyclesDone + 1) };

	};  // while-looping ends.
};  // spawn ends.

 

 

Download the current solution:

https://drive.google.com/file/d/1Ls2ZYb3ibb8mRZYJ7u4p_KBZwwGt04Hx/view?usp=sharing 

Share this post


Link to post
Share on other sites

--- my first topic message has been edited ---

Share this post


Link to post
Share on other sites

Was it @Grumpy Old Man that had a script for (re)loading pylons?

Apologies if not though, I swear I saw the GOM tag!

Share this post


Link to post
Share on other sites
On 9/23/2022 at 11:16 PM, Maff said:

Was it @Grumpy Old Man that had a script for (re)loading pylons?

 

No, I am not using GOM script here. 
 

 

Share this post


Link to post
Share on other sites

Hello thy. I have a very simple script that refuse rearms repairs vehicle. Its in a trigger area. If any vehicle player or AI enters the trigger. I have place a large fuel tank a repair pod and ammo crates in this area. Yes vehicles can use them but the code in the trigger areas works the best. AI units will move to the trigger area if low in resources most of the time. AI behavior for rearming refueling and repairing is still very sketchy at times. But it works during a  mission. If you want I can drop the code for you. It meets all my needs for mission design.

Share this post


Link to post
Share on other sites

Oi, @avibird 1 @avibird 1 , I hope your code can bring ideas or, at least, help those who are looking for a simpler solution. Yes, please.

Share this post


Link to post
Share on other sites

@thy_

hey here is the simple code it gets the job done!!!!. I am sure there is a more sophisticated and sexy way to do this put it checks off all the needs I need in a mission. a way for AI units and players to repair refuel and rearm.

 

call{{_x setDamage 0} Foreach thislist;}; call{{_x  setFuel 1} Foreach thislist;}; call{{_x setVehicleAmmo 1} Foreach thislist;hint "you are are in the Auto services sector.Your Vehicle will be Restored. Your can still take damage and will use up Ammo and fuel in the sector."}  

 

place a trigger down pick your size of the trigger areas and shape

 

Type none

activation any player

activation type present

repeatable

server only

condition call (this)

interval .05

on activation  please code above in box

 

trigger timer

timer type timeout

timer valves 1 1 1

trigger effects  SFX debug this give a beeping noise when in the trigger area.

 

I am using messing around in the editor  

AVIBIRD PC stop by anytime.

 

Share this post


Link to post
Share on other sites

Btw, thanks, @avibird 1.

 

Good fellas, the first topic message has been edited with my "final" solution for u to evaluate.

 

Just letting you know, this rearm solution is part of my Vehicles Overhauling Script:

 

  • Like 1

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

×