Jump to content
scottb613

Simple Rearm Script

Recommended Posts

Hi Folks,

 

Working on a simple "Rearm" script using the vanilla "Rearm Action" - as it's obvious the default menu "Rearm" actions are really unusable. The "Rearm" action is intended to be initiated from an Ammo Crate Action Menu. You can select "Rearm" by Player Squad or Team. There is a self-destruct mechanism included to destroy any ammo not taken - to prevent it falling into enemy hands.

 

Question [SCOammo.sqf]:  I get the yellow "out of ammo" indications on the HUD for the unit - it doesn't clear after they rearm - is there a way to force the HUD Indicator back to normal?

 

Question [SCOammo.sqf]:  Is there a way to detect the end of a reload animation of a unit - like [waitUntil]? The reload times vary greatly between weapon/unit.

 

Question [SCOdestruct.sqf]:  When I [attachTo] the charge to the pallet - the relative positioning doesn't seem to work. I can never see the charge - no matter the values (assumed buried in object). Shouldn't I be able to move the charge around on the object (ammo pallet) using the position array?

 

Question [SCOdestruct.sqf]:  If I use the "scripted charges" this works - however - I originally wanted to place a SOG incendiary grenade on the pallet (better effect) - but that doesn't work using the classname - ideas?

 

 

//SCOinitAmmoCrate.sqf
//Insert into Init Field of Desired Ammo Crate.

this addAction ["Rearm Squad","SCOammo.sqf","ALL",1.5,true,true,"","true",5];
this addAction ["Rearm Team_W","SCOammo.sqf","MAIN",1.5,true,true,"","true",5];
this addAction ["Rearm Team_R","SCOammo.sqf","RED",1.5,true,true,"","true",5];
this addAction ["Rearm Team_G","SCOammo.sqf","GREEN",1.5,true,true,"","true",5];
this addAction ["Rearm Team_Y","SCOammo.sqf","YELLOW",1.5,true,true,"","true",5];
this addAction ["Rearm Team_B","SCOammo.sqf","BLUE",1.5,true,true,"","true",5];
this addAction ["<t color='#FF0000'>Destruct</t>","SCOdestruct.sqf","nil",1.5,true,true,"","true",5];

 

//SCOammo.sqf
//Need Classname of desired Ammo Crate on line 4.
private _choseTeam = _this select 3;
private _logger = format ["Rearm %1", _choseTeam];
hint _logger;
sleep 3;

//Check Ammo Box Range
private _ammoBox = nearestObject [player, "vn_b_ammobox_supply_01"];
private _ammoRun = 1;
if (isNull _ammoBox) then
{
	hint "No Ammo in Range";
	sleep 5;
	hint "";
	_ammoRun = 0;
};

while { _ammoRun == 1 } do
{
	private _ammoPos = getpos _ammoBox;
	private _unitArr = units player;
	_unitArr deleteAt 0;
	
	{
		// Unit Info and Team Membership
		private _unit = _x;
		if (!alive _unit) then {continue};
		private _priWeap = primaryWeapon _unit;
		private _unitMagArr = magazines _unit;
		private _compMagArr = compatibleMagazines _priWeap;
		private _totCnt = 0;
		private _assTeam = assignedTeam _unit;
		if (_choseTeam == "ALL") then {_assTeam = "ALL"};
		if (_choseTeam != _assTeam) then {continue};	
		
		// Count Primary Weapon Magazines
		{
			private _compMag = _x;
			{
				private _unitMag = _x;
				if (_compMag == _unitMag) then {_totCnt = _totCnt + 1};	
			} foreach _unitMagArr;
		} foreach _compMagArr;
		
		// If Unit Above Threshold - Continue
		if (_totCnt > 4) then 
		{
			_logger = format ["%1 - I'm good.", _unit];
			hint _logger;
			sleep 1;
			continue;
		};
		
		// Get Ammo
		_unitPos = getpos _unit;
		_logger = format ["Rearm %1",_unit];
		hint _logger;
		_unit doMove _ammoPos;
		waitUntil {sleep 1; (_unit distance _ammoBox) < 5};
		_unit action ["rearm", _ammoBox];
		_unit doMove _unitPos;
		
	} foreach _unitArr;
	
	_ammoRun = 0;
};
hint "";

 

//SCOdestruct.sqf
//Destroy Ammo Crate
private _target = _this;
private _posit = getposATL (_this select 0);
// create and attach charge
private _charge = "DemoCharge_Remote_Ammo_Scripted" createVehicle _posit;
_charge attachTo [_target, [1.0, 1.0, 1,0]];
// now detonate charge
sleep 2;
hint "----RUN---RUN---RUN----";
sleep 3;
hint "---------10";
sleep 1;
hint "--------9";
sleep 1;
hint "-------8";
sleep 1;
hint "------7";
sleep 1;
hint "-----6";
sleep 1;
hint "----5";
sleep 1;
hint "---4";
sleep 1;
hint "--3";
sleep 1;
hint "-2";
sleep 1;
hint "1";
sleep 2;
hint "";
_charge setDamage 1;

 

Thanks.

 

Regards,
Scott

Share this post


Link to post
Share on other sites

Hey @scottb613, a strategy I'm using in the new (and unpublished yet) version of the Vehicle Overhauling Script is to read with kind of ammo magazines the vehicles got, remove them with looping and, after that, add each new magazine again.

 

_object = _this;

_type = typeOf _object;

_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 addMagazine _x;
      
	} forEach _magazines;
};

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

if (_count > 0) then {
  
	for "_i" from 0 to (_count - 1) do {
      
		_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 addMagazine _x;
          
		} forEach _magazines;
      
		_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 addMagazine _x;
                  
				} forEach _magazines;
			};
		};
	};
};
_object setVehicleAmmo 1;	// Reload turrets / drivers magazine

 

Hope this piece of code brings ideas for you. 

 

  • Like 1

Share this post


Link to post
Share on other sites

Hi @thy_

 

Thanks - it always helps to see how others do it. Let me go over this and see if I can figure it out.

 

I've seen the following done before - but - I'm not exactly sure what it's doing. I assume it's reading some master config file for Arma. I'll look deeper into this as well.

 

Quote

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

 

Thank You!

😉

 

Regards,
Scott

Share this post


Link to post
Share on other sites

Hi Folks,

 

Consolidated a couple threads into this one - I'll keep post #1 up to date - scripts are updated with progress and functional.

 

I see from how @thy_ did it - I need to delete all magazines - from unit and ammo box - then replace with what I want after I update the quantities - respectively. I think I have it. I'll be working on implementing same.

 

I posted my remaining active questions in post #1.

 

Regards,
Scott

Share this post


Link to post
Share on other sites
On 9/14/2022 at 5:29 PM, thy_ said:

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

Don't use this as it does not account for magazine wells. Use BIS_fnc_compatibleMagazines instead.

 

On 9/13/2022 at 10:54 PM, scottb613 said:

Is there a way to detect the end of a reload animation of a unit

See eventHandler reloaded

 

On 9/13/2022 at 10:54 PM, scottb613 said:

I can never see the charge - no matter the values (assumed buried in object).

params[ "_target" ];
private _targetCenterTop = [ 0, 0, boundingBoxReal _target select 1 select 2 ];
// create and attach charge
private _charge = createVehicle[ "DemoCharge_Remote_Ammo_Scripted", getPosATL _target, [], 0, "CAN_COLLIDE" ];
_charge attachTo[ _target, _targetCenterTop ];

 

  • Like 2

Share this post


Link to post
Share on other sites
On 9/14/2022 at 12:54 AM, scottb613 said:

Question [SCOammo.sqf]:  Is there a way to detect the end of a reload animation of a unit - like [waitUntil]? The reload times vary greatly between weapon/unit.

weaponState.

  • Like 1

Share this post


Link to post
Share on other sites

Hi Folks,

 

Thanks - @Larrow and @Ibragim A really appreciate the help - I have much to play with. I'll post an update after I make some progress.

 

Regards,
Scott

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

×