Home   Help Search Login Register  

Author Topic: Quick nearestObject question  (Read 1204 times)

0 Members and 1 Guest are viewing this topic.

Offline laggy

  • Members
  • *
  • "Behold a pale horse"
Quick nearestObject question
« 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

And I looked and beheld a pale horse and his name that sat on him was Death and Hell followed with him.

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Quick nearestObject question
« Reply #1 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

Offline laggy

  • Members
  • *
  • "Behold a pale horse"
Re: Quick nearestObject question
« Reply #2 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
And I looked and beheld a pale horse and his name that sat on him was Death and Hell followed with him.

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Quick nearestObject question
« Reply #3 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;
   };

Offline Worldeater

  • Former Staff
  • ****
  • Suum cuique
Re: Quick nearestObject question
« Reply #4 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.


try { return true; } finally { return false; }