Jump to content
ohmletus

Find container and pull item from it

Recommended Posts

For some time I am browsing forum and trying to make script for mission. So far I was unable to make it right. Perhaps someone will find time and help me out.
My problem is: after the fight there is a lot of bodys. AI unit need to:
1. find specific item in nearest container.
2. aproach this container.
3. pull item from container and equip it (or add to equipement)

 

It is possible to order your AI group member to F2/6/2 in order to make AI go for backpack on the ground and equip it. The same must be possible from the script.
 

1. Specific item - yes however not just a magazine or weapon, but any item, including uniform or binokulars for example.
2. I do not have problem with this. :D

3. In case of containers whitin containers (backpack or uniform) ai should take item with all stuff already in it.

 

Working on it for long time and so far I was unable to make it right. Any help? Please...

Share this post


Link to post
Share on other sites

Make it simple as possible.

There is no "specific" item in containers, just a list of item with "data" like picture,display name, count... but no object.

So, you could create a weaponholder containing your "specific item" at death of one unit. This way, you can identify this container (weaponholder) then the unique item you need.

Share this post


Link to post
Share on other sites

You can find supplies with nearSupplies but inventory lacks a lot of commands working with container items. For example if you want to transfer just 1 item, you need to empty container and fill it up again -1 item, then create this item new and put in AI inventory. In short this is doable but with great pain and suffering.

Share this post


Link to post
Share on other sites

Yes. I do realize this. This is my problem. Let me explain a little bit more what I am trying to achive...
I am creating survival mission/system. The same rules for AI apply to player. Simple place your character on map and put execVM "main.sqf" and world getting alive. All in SP mode. So far I did create entire system to make 2 (or 3 sides) sides fight and conquer buildings/towns.
Tons of hours in developement/testing so far. Yet still one thing that bother me from the begining is lack of realism.

Its easy to fill up any unit with enything and let it go. Yet even best unit has limitation - resources. It will be alive as long as given resources permits. Human can do it. And I am trying the best to make AI do it as well. And my limitations is flat learning curve :D

Btw. You created superb ARMA 3 blog killzone_kid. I have lerned a lot from it.

Anyway. I need my random survival soldier to gather food, better weapon, NV and anything according to list of needs if condition permit. It means if there are resources avaliable.

I am asking for help because without it, I am going to spend another year or 2 trying to figure out how to solve this problem.

_list = (_myUnit nearSupplies 50); is obvious. weaponholder for items on the ground - yes, nearSupplies  is the answer.

Yet. If just _now_ my unit need med kit - it need to browse all nearSupplies  finding this particular item, then getPosASL supply box/body/placeholder in order to get waypoint and send my AI to get there.

Then it need to (yes your right KK) dig thru all stuff often in container whitin container in order to retrive this one med kit.

I found myself struggling badly when dealing with containers... :(

Its why I posted my plea for help.

Share this post


Link to post
Share on other sites

Here is a little code to find the nearest item you want (here "itemGPS") on any crate, vehicle, alive or dead unit, even in bacpack inside these "containers", or simply lying on ground.

I idn't tested in all situation. I limited the search inside a trigger area but it's easy to change this 2 param entry.

 

I sorted the result for marking with a cyan 3D arrow, the nearest GPS from player (not owned by him of course).


 

0 = [thisTrigger,"itemGPS"] spawn {
  params ["_area","_item","_pos","_allStuff","_allSupplies","_container","_c",["_arrow",objNull]];
  while {true} do {
    sleep 0.5;
    _allStuff = [];
    _allSupplies = (_area nearSupplies (triggerArea _area select 0)) - allPlayers;
    {
      _container = _x;
      if (_container isKindOf "CAManBase" && !alive _container) then {
        {if (_x == _item) then {_allStuff pushBack [player distance _container,_container]};nil} count (items _container + magazines _container + weapons _container + [backpack _container] + assignedItems _container)
      } else {
        _rab = if (_container isKindOf "CAManBase") then [{assignedItems _container},{[]}];
        {if (_x == _item) then {_allStuff pushBack [player distance _container,_container]},nil} count (itemCargo _container + magazineCargo _container + weaponCargo _container +backpackCargo _container + _rab);
      };
      if (_container isKindOf "WeaponHolder") then {
        {
          _c = _x select 1;
          {
            if (_x == _item) then {_allStuff pushBack [player distance _container, _container]};
            nil
          } count (itemCargo _c + magazineCargo _c + weaponCargo _c);
          nil
        } count everyContainer _container;
      };
      nil
    } count _allSupplies;
    _allStuff sort true;
    _nearestItem = (_allStuff select 0 select 1);
    if (isnull _arrow) then {
      _arrow = "Sign_Arrow_Cyan_F" createVehicle [0,0,0];
    };
    _arrow setpos (getpos _nearestItem vectorAdd [0,0,1.5]);
    copyToClipboard str _allStuff;
  }; 
};

 

  • Like 2

Share this post


Link to post
Share on other sites

Pierremgi! This is great stuff. This will be scanning constantly area around player and all items will be sorted by distance and stored in clipboard.
I do admire your skills :)

This giving me insight how can I write it. However this need to work on 50-150 AI's. So you understand - CPU consumption.
But Thanks a lot.

I am working almost constantly on this script and I got some progress. Your code help me to deal with deferent sort of objects like weaponholders and containers. (I manage only dead body's at the moment.)
Sorting array using distance! I have to use this method! Very handy.

My progress so far:

1. Detecting dead units, serching them looking for specific things.

2. Moving AI to interested location from above.

3. Moving (some) things from dead units to AI.

So far works uniforms, vests, small (unassigned) items like med kit.

Strugling with weapon - ofc.

Some problems with mags.

I am going to work on your code tomorrow. Well actually today, but later...

Thanks again.

  • Like 1

Share this post


Link to post
Share on other sites

After some modification your code works perfect, exept for finding containers itself like uniforms, vests (I suppose backpacks as well).
ATM for uniform and the like I am just pointing to my old crappy function.

 

Quote

fDoFindItem = {
  params["_myUnit", "_item"];
  _allStuff = [];
  _nearestItem = objNull;
  _allSupplies = (_myUnit nearSupplies 3000) - allUnits;
  if (( _arrMustHave find _item) == -1 ) then {
  {
    _container = _x;
    if (_container isKindOf "CAManBase" && !alive _container) then {
      {if (_x == _item) then {_allStuff pushBack [_myUnit distance _container,_container]};nil} count (items _container + magazines _container + weapons _container + [backpack _container] + assignedItems _container)
    } else {
      _rab = if (_container isKindOf "CAManBase") then [{assignedItems _container},{[]}];
      {if (_x == _item) then {_allStuff pushBack [_myUnit distance _container,_container]},nil} count (itemCargo _container + magazineCargo _container + weaponCargo _container +backpackCargo _container + _rab);
    };
    if (_container isKindOf "WeaponHolder") then {
      {
        _c = _x select 1;
        {
          if (_x == _item) then {_allStuff pushBack [_myUnit distance _container, _container]};
          nil
        } count (itemCargo _c + magazineCargo _c + weaponCargo _c);
        nil
      } count everyContainer _container;
    };
    nil
  } count _allSupplies;
  _allStuff sort true;
  _nearestItem = (_allStuff select 0 select 1);
  } else {_nearestItem = [_myUnit, _item] call fDoFindItem2;};
  _nearestItem;
};

Now I am struggling with adding weapon/magazines to _myUnit and removing them from "nearSupplies".

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

×