Jump to content
thy_

How to detect if the veh has weaponry positions and needs to rearm? [SOLVED]

Recommended Posts

How to know if the vehicle has or not (true or false) weaponry? I mean, turret position or driver with this ability (as Air vehicles)?

 

// NOT WORKING
if ( {_vehPlayer weaponsTurret} count > 0 ) then
{
	hint "Your veh has guns like someone from Texas..."
  
} else 
{
	hint "This veh's kind of Brithish policeman..."
};

 

 

 

 

 

Share this post


Link to post
Share on other sites
if (count (allTurrets [_vehPlayer, false]) > 0) then

*edit* - Ah, that's not it, an optics turret (like in the unarmed Strider) will return as "armed".

 

Hmm.

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
12 minutes ago, thy_ said:

BIS_fnc_allTurrets

 

Yup, does the same as allTurrets but takes a classname instead of an object.

Share this post


Link to post
Share on other sites

I have an issue with when to rearm a vehicle. 

if ( (configFile >> "CfgMagazines" >> _playerVeh select 0 >> "count") != _x select 1} count (magazinesAmmo _x)) > 0 ) ) then 
{
	_playerVeh setVehicleAmmo 1;
	systemChat "Your vehicle is rearmed!";
};

 

In the example above, it works fine until the vehicle is completely out of ammo. In this case, the setVehicleAmmo never happens. In the first look, just change that "> 0" to ">= 0" and everything looks fine, but no.

If we do that, all vehicles even those ones with no weaponry will print that systemChat.

 

EDIT: And if the vehicle has an external gun like those technical trucks, unfortunately, my code's rearming just ONE magazine in not 3 when that is full of ammo. 😞

 

Share this post


Link to post
Share on other sites
On 2/25/2022 at 4:44 PM, thy_ said:

I have an issue with when to rearm a vehicle. 

 

When do you want to rearm a vehicle? Because with ">0" it will be whenever the vehicle has at least some magazines and with ">=0" it will be always. You are essentially just checking for the existence of the vehicle.

 

I guess if you just want to avoid rearming a vehicle that has nothing to rearm, then try something like:

_allMags = []; 
_magsArray = magazinesAllTurrets _playerVeh; 
{
	_mag = _x select 0; 
	_allMags pushBack _mag;
} forEach _magsArray; 

if (count _allMags > 0) then {
	hint "REARMING NOW";
	setVehicleAmmo 1;
} else {
	hint "NO REARMING REQUIRED";
};

 

  • Like 1

Share this post


Link to post
Share on other sites
On 2/26/2022 at 11:42 PM, Harzach said:

When do you want to rearm a vehicle?

 

When the vehicle is around the Rearm Station, the player along with it, and the vehicle has already spent one bullet of its ammunition at least.

 

On 2/26/2022 at 11:42 PM, Harzach said:

I guess if you just want to avoid rearming a vehicle that has nothing to rearm, then try something like:


_allMags = []; 
_magsArray = magazinesAllTurrets _playerVeh; 
{
	_mag = _x select 0; 
	_allMags pushBack _mag;
} forEach _magsArray; 

if (count _allMags > 0) then {
	hint "REARMING NOW";
	setVehicleAmmo 1;
} else {
	hint "NO REARMING REQUIRED";
};

 

 

Here above we're verifying if the vehicle has mags only. 

 

I am trying to rearm vehicles with weaponry available, yep, but if the vehicle has weaponry, I would like to rearm as full as possible. Today the rearming of the vehicle with weaponry never ends and just one mag is rearmed, even when we have other 3 mags slots available.

 

This is my current code of that section:

// code...
// _eachPlayerVeh = _x;
// code of if veh is close enough to rearm station, then... 

	if ( (alive _x) AND (speed _x < 2) ) then 
	{
		_allMags = [];
		_magsArray = magazinesAllTurrets _x; 							
		{ 
			_mag = _x select 0;
			_allMags pushBack _mag;							
		} forEach _magsArray;
								
		if (count _allMags > 0) then     // missing to identify if ammo was spent...
		{
			// code...
			
			[_x, 1] remoteExec ["setVehicleAmmo", _x];
			
			// code...
			
			systemChat "Rearmed.";	
			
			// code...			
		}
		else
		{
			// code...
			
			systemChat "No rearming required.";
        };
	};
	
// code...

 

 

Share this post


Link to post
Share on other sites

Untested, just trying to think through it logically.

Spoiler

param[ "_vehicle" ];

//Some vars to store info
//As magazinesAllTurrets can return multiple mags for a turret make sure we only update a turret once
_doneTurrets = [];

//As setVehicleAmmo replenishes all ammo for all turrets that are local where executed
//Only do a client once
_turretClients = [];

{
	_x params[ "_magClass", "_turretPath", "_remainingAmmoCount" ];
	
	if !( _turretPath in _doneTurrets ) then {
		//Get magazines full ammo count
		_magFullAmmoCount = getNumber( configFile >> "CfgMagazines" >> _magClass >> "count" );
		
		if ( _remainingAmmoCount < _magFullAmmoCount ) then {
			_doneTurrets pushBackUnique _turretPath;
			
			_client = if !( _vehicle turretLocal _turretPath ) then {
				_vehicle turretUnit _turretPath;
			}else{
				if ( isServer && isDedicated ) then { 2 } else { clientOwner };
			};
			_turretClients pushBackUnique _client;
		};
	};
}forEach magazinesAllTurrets _vehicle;

if ( _turretClients isNotEqualTo [] ) then {
	[ "Turret ammo replenished" ] remoteExec[ "hint", _turretClients ];
	[ 1 ] remoteExec[ "setVehicleAmmo", _turretClients ];
};

 

 

Share this post


Link to post
Share on other sites

@Larrow, not sure if I am implementing correctly but here is nothing besides an error that I even can describe accurately. Much easier I show you what is going on. It's the same example that I show you on another topic (about isTouchingGround - btw that is fixed already). 

 

I don't know why, but truck-technicals with fixed .50 turret have 3 mags capacity, but if we spent some OR all of them, the rearming has an odd behavior, rearming just one mag or, if we spent all bullets, it doesn't rearm at all (because I don't know how to code to fill all mags capacity). 

 

VR map: https://drive.google.com/file/d/1yDAiZ6hquSdTCFzFs7qb5ov2_9czitJp/view?usp=sharing

 

This is the last error I got before releasing a cool script to the community. Thanks for your usual support. 

Share this post


Link to post
Share on other sites

After some months, here is my solution (v2.0) for rearming:

 

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

×