Jump to content
thy_

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

Recommended Posts

Folks, I'm running around without a perfect solution to rearm vehicles with turrets and vehicles with pylons. 

 

Simplifying many things, here is an example of my solution so far (and definitely not good enough for players who want to see each magazine get its pylon in those cases).

Issue 1) Conditional:
How to know if only X% (50%, for example) of the vehicle's mag capacity is available? I wanna check it to decide if the vehicle needs to rearm;

// I found it, but I don't got what exactly is happening:
({getNumber (configFile >> "CfgMagazines" >> _x select 0 >> "count") == _x select 1} count magazinesAmmo _veh) == 0)

 

Issue 2) Rearmament Execution:

I already coded a solution to check and change the magazines in a turret, but I'm in trouble around pylons in planes and helicopters.

 

 

Current solution:

// File: veh_rearming.sqf

private ["_veh", "_vehType", "_vehMags", "_magsRemoved", "_mag"];

while {true} do 
{
	_veh = vehicle player; // I'm using "player" just to simplify the example. For multiplayer missions, it doesn't work well and you must check each player in mission.

	if ( (count weapons _veh > 0) AND (speed _veh == 0) AND (({getNumber (configFile >> "CfgMagazines" >> _x select 0 >> "count") == _x select 1} count magazinesAmmo _veh) == 0) ) then 
	{
		_vehType = typeOf _veh;
		_vehMags = compatibleMagazines _vehType;  // figuring out all mags types are default for the vehicle.
						
		if ( _veh isKindOf "Plane" OR _veh isKindOf "Helicopter" ) then 
		{
			// Specific and lazy solution for vehicles with pylons (planes and helicopters) to simplify the rearming as they work differently to turrets:
			[_veh, 1] remoteExec ["setVehicleAmmo", _veh];
			playSound3D ["a3\sounds_f\sfx\ui\vehicles\vehicle_rearm.wss", _veh];
			sleep 3;
			format [">> The %1 has been REARMED!", typeOf (vehicle player)] remoteExec ["systemChat", player];

		} else {
		
			_vehMags = magazinesAllTurrets _veh;  // list of all magazines (include the empty ones) and its data as projectiles left, etc.

			_magsRemoved = [];
				
			for "_i" from 0 to ((count _vehMags) - 1) do  // building the removing mag looping from the amout of vehicle magazine capacity.
			{
				_mag = (_vehMags select _i) select 0;  // selecting only the magazine classname;
				_veh removeMagazines _mag;
				_magsRemoved pushBack _mag;
			};

			{  // forEach for add new mags based on those ones already removed:
				_veh addMagazine _x;
				format [">> Ammo %1 on board...", _x] remoteExec ["systemChat", player];
				playSound3D ["a3\sounds_f\sfx\ui\vehicles\vehicle_rearm.wss", _veh];
				sleep 3;

			} forEach _magsRemoved;

			// if something goes wrong with reloading, this will help to fix as vehicle smoke granades sometimes don't reload:
			[_veh, 1] remoteExec ["setVehicleAmmo", _veh];
			format [">> The %1 has been REARMED!", typeOf (vehicle player)] remoteExec ["systemChat", player];
		};

	} else {
		
		sleep 3;
	};
};

 

Inconsistencies of the solution above:

  • If the vehicle is configured by Editor to spawn with NO AMMO, if you try to rearm that vehicle, it will never have this original number of magazines loaded;
  • Vehicles with pylons are no working as other vehicles with turrets that each ammo is loaded individually (on its pylon in planes and helicopters);

 

P.S.: No worries regarding drone vehicles.

 

The download of my problematic example:

https://drive.google.com/file/d/14vjjl3HsImEDfhybzbt_0YkJptuNYJru/view?usp=sharing

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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×