kerbo_

lootHoover.sqf

Apr 2nd, 2024 (edited)
3,958
1
Never
4
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 6.19 KB | None | 1 0
  1. // get all the lootz and put it in a crate
  2. // For use with Antistasi when you just can't be bothered
  3. // Twitter: @Kerbo_
  4. private _maxDistance = 20000;
  5. private _flagClass = "FlagMarker_01_F";
  6. private _placeFlag = false;
  7. private _lootCrateClass = "Box_IND_Wps_F";
  8. private _magicBoxClass = "Box_IND_Support_F";
  9. // private _magicBoxClass = "Box_IND_Wps_F";
  10. private _magicBox = nearestObject [player, _magicBoxClass];
  11. if (_magicBox == objNull or typeOf _magicBox == "") then {
  12.     // create empty crate  
  13.     _magicBox = createVehicle[_magicBoxClass, position player, [], 0, "NONE"];
  14.     _magicBox allowDamage false;
  15.     clearWeaponCargoGlobal _magicBox;
  16.     clearMagazineCargoGlobal _magicBox;
  17.     clearItemCargoGlobal _magicBox;
  18.     clearBackpackCargoGlobal _magicBox;
  19.     _magicBox call A3A_Logistics_fnc_addLoadAction;
  20.     _magicBox addAction [localize "STR_A3A_fn_base_flagaction_asset_move", A3A_fnc_carryItem, nil, 1.5, false, true, "", "!(call A3A_fnc_isCarrying)", 4];
  21. };
  22. private _targets = nearestObjects [getPosATL _magicBox, ["Man"], _maxDistance];
  23. private _weaponHolders = nearestObjects [getPosATL _magicBox, ["WeaponHolder", "WeaponHolderSimulated", _lootCrateClass], _maxDistance];
  24. private _countBodies = 0;
  25. private _countContainers = 0;
  26.  
  27. private _lootWeapons = {
  28.     params ["_weaponItemsArray", "_container"];
  29.     _container addWeaponWithAttachmentsCargoGlobal [_weaponItemsArray, 1];
  30. };
  31.  
  32. private _lootBodies = {
  33.     params ["_lootable", "_container"];
  34.  
  35.     if (_lootable isKindOf "CAManBase") then {
  36.         // get HashMap of target loadout  
  37.         private _loadout = getUnitLoadout _lootable;
  38.         _loadout = createHashMapFromArray [["primaryWeapon", _loadout select 0],
  39.             ["secondaryWeapon", _loadout select 1],
  40.             ["handgunWeapon", _loadout select 2],
  41.             ["uniform", _loadout select 3],
  42.             ["vest", _loadout select 4],
  43.             ["backpack", _loadout select 5],
  44.             ["helmet", _loadout select 6],
  45.             ["faceWear", _loadout select 7],
  46.             ["binoculars", _loadout select 8],
  47.         ["items", _loadout select 9]];
  48.         {
  49.             // systemChat format ["Processing %1: %2", _x, _y];  
  50.             if (_y isNotEqualTo []) then {
  51.                 switch (_x) do
  52.                 {
  53.                     case "binoculars";
  54.                     case "primaryWeapon";
  55.                     case "secondaryWeapon";
  56.                     case "handgunWeapon":
  57.                     {
  58.                         [_y, _container] call _lootWeapons;
  59.                         _loadout set [_x, []];
  60.                     };
  61.                       // break out items from these containers  
  62.                     case "uniform";
  63.                     case "vest";
  64.                     case "backpack":
  65.                     {
  66.                         {
  67.                             switch (count _x) do
  68.                             {
  69.                                 case 2:
  70.                                 {
  71.                                     _container addItemCargoGlobal _x;
  72.                                 };
  73.                                 case 3:
  74.                                 {
  75.                                     _container addMagazineAmmoCargo _x;
  76.                                 };
  77.                                 default
  78.                                 {
  79.                                     systemChat format ["ERROR: not sure how to handle %1", _x];
  80.                                 };
  81.                             };
  82.                         } forEach (_y select 1);
  83.                         if (_x isEqualTo "vest") then {
  84.                             _container addItemCargoGlobal [_y select 0, 1];
  85.                         };
  86.                         if (_x isEqualTo "backpack") then {
  87.                             _container addBackpackCargoGlobal [_y select 0, 1];
  88.                         };
  89.                         if (_x isEqualTo "uniform") then {
  90.                             // Don't take the uniform  
  91.                              // Keep your pants on, my guy  
  92.                             _loadout set [_x, [_y select 0, []]];
  93.                         } else {
  94.                             _loadout set [_x, []];
  95.                         };
  96.                     };
  97.                     case "helmet":
  98.                     {
  99.                         _container addItemCargoGlobal [_y, 1];
  100.                         _loadout set [_x, ""];
  101.                     };
  102.                     case "faceWear":
  103.                     {
  104.                         // Do nothing, because we don't want to loot faceWear
  105.                     };
  106.                     case "items":
  107.                     {
  108.                         {
  109.                             if !(_x isEqualTo "") then
  110.                             {
  111.                                 _container addItemCargoGlobal [_x, 1];
  112.                             };
  113.                         } forEach (_y);
  114.                         _loadout set [_x, ["", "", "", "", "", ""]];
  115.                     };
  116.                     default
  117.                     {
  118.                         // All the cases should be handled, but just in case  
  119.                         systemChat format ["ERROR: Not sure how to handle %1", _x];
  120.                     };
  121.                 };
  122.             } else {
  123.                 // Empty slot, so nothing to do here
  124.             };
  125.         } forEach _loadout;
  126.  
  127.           // Push the fleeced loadout back to the unit  
  128.           // Has to be a Unit Loadout Array, yuck  
  129.         _loadout = [_loadout get "primaryWeapon",
  130.             _loadout get "secondaryWeapon",
  131.             _loadout get "handgunWeapon",
  132.             _loadout get "uniform",
  133.             _loadout get "vest",
  134.             _loadout get "backpack",
  135.             _loadout get "helmet",
  136.             _loadout get "facewear",
  137.             _loadout get "binoculars",
  138.         _loadout get "items"];
  139.         _lootable setUnitLoadout _loadout;
  140.         private _looted = _lootable getVariable ["LootTaken", false];
  141.         if (!_looted) then {
  142.             _countBodies = _countBodies + 1;
  143.             _lootable setVariable ["LootTaken", true, true];
  144.             if (_placeFlag) then {
  145.                 createVehicle[_flagClass, position _lootable, [], 0, "NONE"];
  146.             };
  147.         };
  148.     } else {
  149.         // Loot containers in container  
  150.         {
  151.             private _subContainer = _x select 1;
  152.             {
  153.                 [_x, _container] call _lootWeapons;
  154.             } forEach weaponsItemsCargo _subContainer;
  155.             {
  156.                 _container addItemCargoGlobal [_x, 1];
  157.             } forEach itemCargo _subContainer;
  158.             {
  159.                 _container addMagazineAmmoCargo [_x select 0, 1, _x select 1];
  160.             } forEach magazinesAmmoCargo _subContainer;
  161.         } forEach everyContainer _lootable;
  162.         {
  163.             [_x, _container] call _lootWeapons;
  164.         } forEach weaponsItemsCargo _lootable;
  165.           // items include other containers like uniforms and vests  
  166.         {
  167.             _container addItemCargoGlobal [_x, 1];
  168.         } forEach itemCargo _lootable;
  169.           // Backpacks aren't considered itemCargo; add them now  
  170.         {
  171.             _container addBackpackCargoGlobal [_x, 1];
  172.         } forEach backpackCargo _lootable;
  173.         {
  174.             _container addMagazineAmmoCargo [_x select 0, 1, _x select 1];
  175.         } forEach magazinesAmmoCargo _lootable;
  176.  
  177.           // Cleanse the fleeced container  
  178.         clearWeaponCargoGlobal _lootable;
  179.         clearItemCargoGlobal _lootable;
  180.         clearBackpackCargoGlobal _lootable;
  181.         clearMagazineCargoGlobal _lootable;
  182.  
  183.         private _looted = _lootable getVariable ["LootTaken", false];
  184.         if (!_looted) then {
  185.             _countContainers = _countContainers + 1;
  186.             _lootable setVariable ["LootTaken", true, true];
  187.         };
  188.     };
  189. };
  190.  
  191. _targets = _targets select {
  192.     !alive _x
  193. };
  194. {
  195.     [_x, _magicBox] call _lootBodies
  196. } forEach _targets;
  197. {
  198.     [_x, _magicBox] call _lootBodies
  199. } forEach _weaponHolders;
  200. systemChat format ["Looted %1 bodies and %2 containers", _countBodies, _countContainers];
  201. _countBodies + _countContainers;
Advertisement
Comments
  • deltafrost22
    2 years
    # text 0.19 KB | 0 0
    1. Pardon my ignorance, but how do I go about implementing this into my Antistasi gameplay? Do I just type it into the debug menu or do I need to create the sqf file and drop it in a folder somewhere?
    • kerbo_
      2 years
      # text 0.22 KB | 2 0
      1. Yes, you would paste it into the debug console like any other code you want to run. I use this mod which gives more options for editing, saving, running code: https://steamcommunity.com/sharedfiles/filedetails/?id=2369477168
  • SabreCodes
    318 days (edited)
    # text 1.73 KB | 0 0
    1. Hey,
    2.  
    3. So I have been playing around with this script and have noticed that if you run the hoover, then run it again, it just deletes everything from the first collection? I am certain that the last time I used it, it grabbed everything from the first box and didn't just delete it?
    4.  
    5. It seems to be grabbing the same box (if it can find it near the player?) so I am guessing it is clearing that box of its contents before the find loot part actually runs? Is there anyway to make it spawn and fill a new one each time? That way it would grab out of the first loot hoover box and put it in the second.
    6.  
    7. Also if you're interested:
    8.  
    9. // WORLD WIDE LOOT HOOVER:
    10. // Tweaked by: SabreCodes
    11. // Twitter: @Kerbo_
    12.  
    13. private _maxDistance = 20000;
    14. private _flagClass = "FlagMarker_01_F";
    15. private _placeFlag = false;
    16. private _lootCrateClass = "Box_IND_Wps_F";
    17. // private _magicBoxClass = "Box_IND_Support_F";
    18. private _magicBoxClass = "Box_IND_Wps_F";
    19. private _magicBox = nearestObject [player, _magicBoxClass];
    20.  
    21. if (_magicBox == objNull or typeOf _magicBox == "") then {
    22.  
    23. // create empty crate
    24. _magicBox call A3A_fnc_initObject;
    25. _magicBox call A3a_fnc_;
    26. _magicBox = createVehicle[_magicBoxClass, position player, [], 0, "NONE"];
    27. _magicBox allowDamage false;
    28. clearWeaponCargoGlobal _magicBox;
    29. clearMagazineCargoGlobal _magicBox;
    30. clearItemCargoGlobal _magicBox;
    31. clearBackpackCargoGlobal _magicBox;
    32. };
    33.  
    34. Small change I made that makes it the normal Antistasi Loot Crate (Weapons box) with the same, carry, load loot to crate, load loot to vehicle, and load into vehicle. So you can use it to quickly gather all of the loot (I play solo so major time-saver!) but still have a box to potentially loose transporting it home!
    • kerbo_
      318 days
      # text 0.35 KB | 0 0
      1. Hello,
      2. I don't see that behavior on my end using the script as is. In the edit you show you're using the same class for the hoover as the loot boxes. That will cause the behavior you're seeing. The main loop will treat the created hoover box as just another loot box. I specifically use another class for the hoover box so it doesn't get collected.
      3. -Kerbo
Add Comment
Please, Sign In to add comment