Jump to content
Sign in to follow this  
avibird 1

New Release- Realistic Unlimited Ammo script for Infanty only UNITS players and or AI units (mags and launcher rounds).

Recommended Posts

Hello my ARMA family happy new year to all. Here is a  Unlimited Ammo script that works with all mags and rocket rounds editor placed and or spawn in units. This is unlike most of the scripts and codes that gives you a continuous spray of rounds with launchers. You can control if its only for players and AI use. OFP/AMMO has always been a pain in the ass with AI management especially rearming. if you are like me who plays with a lot of AI teammates you know my pain with micromanagement of this.

 

XxanimusxX back with ARMA2 help me develop  (well my idea) but all his scripting!!! This will allow a unit one magazine of the primary and secondary weapons that is in the player or AI hands. Basically you use up all of your ammo in your inventory until the last one and when that is used one additional mag/round will be added back into the inventory . Especially useful when your squad comes across an armor vehicle and has no launcher ammo left game over. Now you can have a fighting chance. XxanimusxX updated the script for me when ARMA3  came out. Unfortunately like all things ARMA (scripting) things will get broken with ARMA updates. This script was getting a message error that was killing performance and given a message error in the debug screen in the editor that would not go away. When playing a mission not from the editor no message but definitely draining overall performance. XxanimusxX has not been on the forums since 2016.

 

Thanks to @Harzach for suggesting to change the way the script should be called and for @opusfmspol for correcting the script and getting rid of the message error. Here is the script for anyone who would like it. A few people asked me if they could have it.  ARMA is all about sharing with the community. 

 

 

in Init.sqf

Spoiler

//Unlimited Ammo**********
grantUnlimitedAmmo2 = compile preprocessFileLineNumbers "grantUnlimitedAmmo2.sqf";

 

 

In grantUnlimitedAmmo2.sqf:

Spoiler

//Unlimited Ammo Script by XxanimusxX and updated by opusfmspol 12/28/21.

 

params
[
["_unit",objNull,[objNull]],
["_ammoCount",1,[1]]
];

if (isNull _unit) exitWith {/* null _unit was passed in */};

Private _primeWpn = "";
Private _prevWpn = "";
Private _magazineType = "";
Private _magazineArray = [];
Private _foundMags = 0;

ScopeName "End";

while {alive _unit} do
{
waitUntil {
Sleep 0.5;

if !(alive _unit) then {BreakTo "End"};

_primeWpn = currentWeapon _unit;
sleep 0.01;
(_primeWpn != "")
};

_magazineType = "";
_magazineArray = getArray(configFile >> "cfgWeapons" >> _primeWpn >> "magazines");

if (count _magazineArray > 0) then {_magazineType = _magazineArray select 0};

if (_magazineType != "") then
{
_foundMags = 0;

{if (_x == _magazineType) then {_foundMags = _foundMags + 1};} forEach (magazines _unit);

if (_foundMags < _ammoCount) then
{
// Handle JIP players: addMagazine must be run where _unit is local; with JIP,
// ownership changes but until _unit dies, the original owner is who runs the script.
for "_i" from 1 to (_ammoCount - _foundMags) do
{
if (Local _unit) then {
_unit addMagazine _magazineType;
} else {
[_unit,_magazineType] RemoteExec ["addMagazine",_unit];
};
};
};
};

sleep 1;
};

 

in InitServer.sqf

 

Spoiler

//Unlimited Ammo**********
UA_Handle = [] spawn
{
 if (isNil "UNLAMMO_ARR") then {UNLAMMO_ARR = []};

 // Wait until mission fully starts.
 WaitUntil {time > 0};

 while {true} do {
  {
   if (alive _x && !(_x in UNLAMMO_ARR)) then {
    [_x,1] RemoteExec ["grantUnlimitedAmmo2",_x];
    UNLAMMO_ARR = UNLAMMO_ARR + [_x];
   };
  } foreach allUnits;

  UNLAMMO_ARR = UNLAMMO_ARR - [objNull];
  _arrayTemp = +(UNLAMMO_ARR);

  {
   if !(alive _x) then {UNLAMMO_ARR = UNLAMMO_ARR - [_x]};
  } foreach _arrayTemp;

  sleep 1;
 };
};

 

 

This community has gave me so much help with my desire to under stand and lean scripting for ARMA. I appreciate all the help.  Happy new year to all! Avibird.

  • Like 5

Share this post


Link to post
Share on other sites
1 hour ago, avibird 1 said:

XxanimusxX

 

Ah, now there's a name I haven't seen in a long time. 

 

Congrats!

  • Like 1

Share this post


Link to post
Share on other sites

After test playing in a real mission not just in  the editor setup getting a new message error line 20 in the ammo script  - true or false expected line 20

 

 

{
 waitUntil {
  Sleep 0.5;

 // if !(alive _unit) ExitWith {};                                 this is line 20 

  _primeWpn = currentWeapon _unit;
  sleep 0.01;
  (_primeWpn != "")
 }; 

 

just // LINE 20 for now. I did notice a little dip in performance with FPS ect. but not a game killer. I will try to get this all worked out!!!

 

very frustration

Share this post


Link to post
Share on other sites

Might help to post your .rpt file (wrap in spoiler tag to avoid infinite scrolling).

  • Like 2

Share this post


Link to post
Share on other sites

grantUnlimitedAmmo2.sqf: Updated first post no more message error better overall performance with script yay.

  • 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
Sign in to follow this  

×