OFPEC Forum

Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: laggy on 10 Feb 2009, 20:49:06

Title: Quick nearestObject question
Post by: laggy on 10 Feb 2009, 20:49:06
Hi,

Does anyone have an idea how to check this without the myUnit caring about "itself"?

myUnit knowsabout nearestObject [myUnit, "Man"] == 4

You see this activates even when the unit is alone, but I want to the solution to be that the unit checks for anyone BUT itself. How can you make a unit neglect itself with this command if the unit is the same type as given?

The reason I want "Man" is that I want to avoid listing ALL the different models, "soldierWB" and so on, in the script.

Laggy

Title: Re: Quick nearestObject question
Post by: Mandoble on 10 Feb 2009, 21:08:26
Your init.sqf
Code: [Select]
mydetectfunc =
{
   // detect.sqf
   private["_myUnit", "_objects", "_result"];
   _myUnit = _this select 0;
   _objects = nearestObjects [_myUnit, ["Man"], 50];
   _result = false;
   if (count _objects > 1) then
   {
      if ((_myUnit knowsAbout (_objects select 1)) == 4) then
      {
         _result = true;
      };
   };
   _result;
};

Then in your trigger condition:
Code: [Select]
[myUnit] call mydetectfunc
Title: Re: Quick nearestObject question
Post by: laggy on 10 Feb 2009, 21:12:20
Ahh,

So the select 1 is the key?
Counting the array where itself would be select 0?

Thanks alot,

Laggy
Title: Re: Quick nearestObject question
Post by: Mandoble on 10 Feb 2009, 21:14:56
You have another option:
Code: [Select]
   if (count _objects > 1) then
   {
      {
         if (_x != _myUnit) then
         {
            if ((_myUnit knowsAbout _x) == 4) then
            {
               _result = true;
            };
         };
      } forEach _objects;
   };
Title: Re: Quick nearestObject question
Post by: Worldeater on 10 Feb 2009, 21:41:35
So the select 1 is the key?
Counting the array where itself would be select 0?

Yes, because Mandoble used nearestObjects (note the trailing "s"). That command returns an array of objects (sorted by distance, closest first). Since the man closest to a soldier is always the soldier himself, the second closest has to be checked (if there is one).

nearestObject (without the trailing "s") returns a single object. So in your case it always returned myUnit.