Jump to content
Sign in to follow this  
scottb613

SCO SP Rearm and Smart Ammo Box Scripts

Recommended Posts

Hi Folks,

 

Put this together from several scripts I've been tinkering with for years. 

 

  • // Overview: Stock custom Ammo Boxes (crate or vehicle) with magazines from player's squad initial loadout.
  • // Overview: Provides on demand "Rearm" for Players Squad at Ammo Box. 

 

  • // Requires: "initAmmoCrate.sqf" in mission root folder.
  • // Requires: "Scripts\SCOammo.sqf" in root of mission folder.
  • // Requires: "Scripts\SCOrearm.sqf" in root of mission folder.
  • // Requires: Init Field Entry in desired Ammo Box ===>>> null = [this] execVM "initAmmoCrate.sqf"; 

 

  • // Note: Only tested in single player.

 

  • // Given: Ammo Box can be a crate or vehicle. 
  • // Given: Smart Ammo Box [SAB] - empties selected container - then stocks with magazines from players units. 
  • // Given: Ammo Box will have addAction [Srcoll Wheel] menus assigned to order players squad to resupply.
  • // Given: Player must walk up to Ammo Box to see the menus - 4 meters. 
  • // Given: Ammo Box addAction menus only appear when not in the vehicle.
  • // Given: Players Squad must be in the area of the ammo box - 30 meters to rearm.
  • // Given: Intended for SOG_AI as if you want to rearm by Team - only Red or Green supported - otherwise just choose your whole squad.
  • // Given: Explosive Destruct for actual crate - crate deleted during explosion.
  • // Given: Explosive Destruct on vehicle - any crew will abandon and vehicle will remain destroyed.
  • // Given: Supports multiple Ammo Boxes.
  • // Given: Ammo Boxes can be moved by whatever means you like and should still work fine.
  • // Given: Should work with any assets and mods - tested on SOG_PF and Vanilla.

 

Any real interest and I'll put together a download and share them somewhere. For now - just cut and paste your own copies following the (4) Requirements.

 

 

initAmmoCrate.sqf

//====================================//
// SCO Rearm Script w/ Smart Ammo Box //
//====================================//

// FILE: initAmmoCrate.sqf :FILE
// Author: scottb613


// Overview: Two basic functions - stock custom Ammo Boxes (crate or vehicle) with magazines from players squad.
// Overview: Provides on demand "Rearm" for Players Squad at Ammo Box. 

// Requires: initAmmoCrate.sqf in mission root folder.
// Requires: "Scripts\SCOammo.sqf" in root of mission folder.
// Requires: "Scripts\SCOrearm.sqf" in root of mission folder.
// Requires: Init Field Entry in Ammo Box ===>>> null = [this] execVM "initAmmoCrate.sqf"; 

// Note: Only tested in single player.

// Given: Ammo Box can be a crate or vehicle. 
// Given: Smart Ammo Box [SAB] - empties selected container - then stocks with magazines from players units. 
// Given: Ammo Box will have addAction [Scoll Wheel] menus assigned to order players squad to resupply.
// Given: Player must walk up to Ammo Box to see the menus - 4 meters. 
// Given: Ammo Box addAction menus only appear when not in the vehicle.
// Given: Players Squad must be in the area of the ammo box - 30 meters to rearm.
// Given: Intended for SOG_AI as if you want to rearm by Team - only Red or Green supported.
// Given: Explosive Destruct for actual crate - crate deleted during explosion.
// Given: Explosive Destruct on vehicle - any crew will abandon - and vehicle will remain destroyed.
// Given: Supports multiple Ammo Boxes.
// Given: Ammo Boxes can be moved by whatever means you like and should still work fine.

//=====================================================================================================================//
//=====================================================================================================================//

private _crate = _this select 0;
private _unitArr = units group player;

// Clear all existing cargo from the crate
clearMagazineCargoGlobal _crate;
clearWeaponCargoGlobal _crate;
clearItemCargoGlobal _crate;
clearBackpackCargoGlobal _crate;

// Loop through each unit in the group
{
    private _unit = _x;

    // Add all magazines (including grenades and smokes) from unit to crate
    {
        _crate addMagazineCargoGlobal [_x, 1];
    } forEach (magazines _unit);

    // Add 3 vanilla First Aid Kits per unit to the crate
    _crate addItemCargoGlobal ["FirstAidKit", 3];

} forEach _unitArr;

// Add actions to the crate for rearming and destructing
_crate addAction ["<t color='#98FB98'>Rearm Squad</t>", "Scripts\SCOrearm.sqf", ["ALL", _crate], 1.5, true, true, "", "vehicle player == player", 4];
_crate addAction ["<t color='#98FB98'>Rearm Team Red</t>", "Scripts\SCOrearm.sqf", ["RED", _crate], 1.5, true, true, "", "vehicle player == player", 4];
_crate addAction ["<t color='#98FB98'>Rearm Team Green</t>", "Scripts\SCOrearm.sqf", ["GREEN", _crate], 1.5, true, true, "", "vehicle player == player", 4];
_crate addAction ["<t color='#FF0000'>AMMO_BOX Destruct</t>", "Scripts\SCOrearm.sqf", ["DESTRUCT", _crate], 1.5, true, true, "", "vehicle player == player", 4];

// Detect the classname of the ammo crate and display it as a hint
hint "AMMO_CRATE stocked";

 

 

 

Scripts\SCOammo.sqf

//====================================//
// SCO Rearm Script w/ Smart Ammo Box //
//====================================//

// FILE: SCOammo.sqf :FILE
// Author: scottb613

// Overview: Two basic functions - stock custom Ammo Boxes (crate or vehicle) with magazines from players squad.
// Overview: Provides on demand "Rearm" for Players Squad at Ammo Box. 

// Requires: initAmmoCrate.sqf in mission root folder.
// Requires: "Scripts\SCOammo.sqf" in root of mission folder.
// Requires: "Scripts\SCOrearm.sqf" in root of mission folder.
// Requires: Init Field Entry in Ammo Box ===>>> null = [this] execVM "initAmmoCrate.sqf"; 

// Note: Only tested in single player.

// Given: Ammo Box can be a crate or vehicle. 
// Given: Smart Ammo Box [SAB] - empties selected container - then stocks with magazines from players units. 
// Given: Ammo Box will have addAction [Scoll Wheel] menus assigned to order players squad to resupply.
// Given: Player must walk up to Ammo Box to see the menus - 4 meters. 
// Given: Ammo Box addAction menus only appear when not in the vehicle.
// Given: Players Squad must be in the area of the ammo box - 30 meters to rearm.
// Given: Intended for SOG_AI as if you want to rearm by Team - only Red or Green supported.
// Given: Explosive Destruct for actual crate - crate deleted during explosion.
// Given: Explosive Destruct on vehicle - any crew will abandon - and vehicle will remain destroyed.
// Given: Supports multiple Ammo Boxes.
// Given: Ammo Boxes can be moved by whatever means you like and should still work fine.

//=====================================================================================================================//
//=====================================================================================================================//

// Capture an array of units selected via Function Key
private _unitArr = groupSelectedUnits player;
private _ammoBox = _this select 3; // Ammo Container
private _ammoRun = 1;
hint "REARM Script";

while { _ammoRun == 1 } do
{
    private _ammoPos = getPos _ammoBox;
    {
        // Unit Info and Team Membership
        private _unit = _x;
        if (!alive _unit) then { continueWith { hint format ["%1 - Skipped (Dead)", _unit]; }; }; // Skip dead units
        
        // Check if the unit is within 50 meters of the ammo container
        if ((_unit distance _ammoPos) > 50) then { continueWith { hint format ["%1 - Skipped (Too far)", _unit]; }; };

        private _priWeap = primaryWeapon _unit;
        private _unitMagArr = magazines _unit;
        private _compMagArr = compatibleMagazines _priWeap;
        private _totCnt = 0;

        // 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 "";

 

 

Scripts\SCOrearm.sqf

//====================================//
// SCO Rearm Script w/ Smart Ammo Box //
//====================================//

// FILE: SCOrearm.sqf :FILE
// Author: scottb613

// Overview: Two basic functions - stock custom Ammo Boxes (crate or vehicle) with magazines from players squad.
// Overview: Provides on demand "Rearm" for Players Squad at Ammo Box. 

// Requires: initAmmoCrate.sqf in mission root folder.
// Requires: "Scripts\SCOammo.sqf" in root of mission folder.
// Requires: "Scripts\SCOrearm.sqf" in root of mission folder.
// Requires: Init Field Entry in desired Ammo Box ===>>> null = [this] execVM "initAmmoCrate.sqf"; 

// Note: Only tested in single player.

// Given: Ammo Box can be a crate or vehicle. 
// Given: Smart Ammo Box [SAB] - empties selected container - then stocks with magazines from players units. 
// Given: Ammo Box will have addAction [Scoll Wheel] menus assigned to order players squad to resupply.
// Given: Player must walk up to Ammo Box to see the menus - 4 meters. 
// Given: Ammo Box addAction menus only appear when not in the vehicle.
// Given: Players Squad must be in the area of the ammo box - 30 meters to rearm.
// Given: Intended for SOG_AI as if you want to rearm by Team - only Red or Green supported.
// Given: Explosive Destruct for actual crate - crate deleted during explosion.
// Given: Explosive Destruct on vehicle - any crew will abandon - and vehicle will remain destroyed.
// Given: Supports multiple Ammo Boxes.
// Given: Ammo Boxes can be moved by whatever means you like and should still work fine.

//=====================================================================================================================//
//=====================================================================================================================//

private _params = _this select 3;
private _choseTeam = _params select 0;
private _ammoCrate = _params select 1;
private _ammoCrateClassname = typeOf _ammoCrate;

if (_choseTeam == "DESTRUCT") then {
    // Destruct Code
    private _target = _ammoCrate;
    private _posit = getpos _target;
    // create and attach charge
    private _charge = "DemoCharge_Remote_Ammo_Scripted" createVehicle _posit;
    _charge attachTo [_target, [0,0,0]];
    // now detonate charge
    hint "----RUN---RUN---RUN----";
    
    // Check if the ammo box is a vehicle and make the crew exit and run away
    if (_ammoCrate isKindOf "LandVehicle") then {
        private _crew = crew _ammoCrate;
        private _newGroup = createGroup west; // Create a new group for the crew
        {
            unassignVehicle _x; // Unassign from vehicle
            _x action ["getOut", _ammoCrate];
            [_x] joinSilent _newGroup; // Join the new group
            _x doMove (getPos _x vectorAdd [100, 100, 0]); // Move 100 meters away
            _x setSpeedMode "FULL"; // Force sprint
        } forEach _crew;
    };
    
    sleep 5;
    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;
    
    // Destroy the vehicle or delete the crate
    if (_ammoCrate isKindOf "LandVehicle") then {
        _ammoCrate setDamage 1; // Destroy the vehicle
    } else {
        deleteVehicle _target; // Delete the crate
    };
};

private _logger = format ["Rearm %1", _choseTeam];
hint _logger;
sleep 3;

private _ammoBox = nearestObject [player, _ammoCrateClassname];

while {true} do
{
    private _ammoPos = getpos _ammoBox;
    private _unitArr = units group player;
    _unitArr deleteAt 0; // Exclude the player
    
    {
        // Unit Info and Team Membership
        private _unit = _x;
        if (!alive _unit) then {continue};
        private _assTeam = assignedTeam _unit;
        if (_choseTeam != "ALL" && _choseTeam != _assTeam) then {continue};
        if (_unit distance _ammoBox > 25) then {
            _logger = format ["%1 - UNABLE - Ammo Too Far", _unit];
            hint _logger;
            sleep 1;
            continue;
        };
        private _priWeap = primaryWeapon _unit;
        private _unitMagArr = magazines _unit;
        private _compMagArr = compatibleMagazines _priWeap;
        private _totCnt = 0;
        
        // 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;
    
    break;
};

 

Regards,
Scott

  • Like 2

Share this post


Link to post
Share on other sites

Hi Folks,

 

Added a working DEMO mission all setup and ready to go with the scripts. Requirements: Vanilla - plus CBA - plus ACE. Simply copy to your mission's folder and launch.

 

Includes Ammo Box Crate and Ammo Box Vehicle examples.

 

Download:

SCO Rearm Test - Vanilla

 

2 Radio Triggers included in mission:

  • Strips the units of all magazines.
  • Kills all units so you can check their inventory.

 

3 Questions:

  • When I strip magazines the HUD indicator turn yellow for each unit - indicating low ammo - however - it never clears when rearmed. What are the requirements to clear the yellow low ammo indicator?
  • I tried adding a custom sound file to the "Destruct" script (it's in the download) - it doesn't work - anyone know why?
  • Instead of using a custom sound - what's the name of a vanilla Arma file that give me a beep for a timer? I know I've seen it before - but I don't know how to find it. 

 

How I'm trying to call my first custom sound file:

    playSound3D ["Sounds\SCOtimeBeep.ogg", _ammoCrate, false, getPosASL _ammoCrate, 1, 1, 50];
    sleep 2;
    hint "";

 

Thanks.

 

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

×