Home   Help Search Login Register  

Author Topic: Nearestobject to any object, Can´t be done?  (Read 659 times)

0 Members and 1 Guest are viewing this topic.

Axo

  • Guest
Nearestobject to any object, Can´t be done?
« on: 31 Jan 2003, 17:51:23 »
IÂ'm trying to get the closest object (of any kind) to an object but I canÂ't figure how...
IÂ've tryed:

Code: [Select]
_Near = nearestobject [_Obj,""]Returns _Obj always
And
Code: [Select]
_Near = nearestobject [_Obj,"All"]Returns Null
etc...
(_Obj is an initialised object)

If can be done with vehicles, works for me :)
Another option is to repeat the line for every vehicle...
PD: Is there a way to know all the vehicles objects currently in a map (w/o triggers)

Trex2001

  • Guest
Re:Nearestobject to any object, Can´t be done?
« Reply #1 on: 03 Feb 2003, 13:12:57 »
you need to specify the type of the object u r looking for. I dont think u can use it to find all objects. Check out http://www.concept-5.com/ofp/tutorials/CMREFv103.htm#NearestObject for mor info

Axo

  • Guest
Re:Nearestobject to any object, Can´t be done?
« Reply #2 on: 04 Feb 2003, 00:00:28 »
Thanks!.  IÂ've realized that if you specify a position as a parameter, it returns the nearest object of any kind to the pos... ::)

Pointman

  • Guest
Re:Nearestobject to any object, Can´t be done?
« Reply #3 on: 05 Feb 2003, 04:40:06 »
Uhm... i might be new, but when i try to do

_nearest = nearestobject [_obj,""]

the parser flips out and wants 3 arguments

Axo

  • Guest
Re:Nearestobject to any object, Can´t be done?
« Reply #4 on: 05 Feb 2003, 19:27:19 »
The use is

_nearest = nearestobject [_x,_z,_y]


Pointman

  • Guest
Re:Nearestobject to any object, Can´t be done?
« Reply #5 on: 05 Feb 2003, 21:30:44 »
hm

i tried it and i was actually able to do this :

_nearest = NearestObject [ SOME_OBJECT, "<TYPE>"]

Where <TYPE> is the exact type of unit but WEIRD..if the nearest is a "soldier", and my Type=SoldierW... no go.. you have to use SoldierWB. "man" won't work either...

It's not like CountType where you get all the subcategories... if you have a Jeep nearby and pass in "Car" you will get null. you have to pass in "Jeep".

I guess the same goes for the original problem where you tried to use "All"

Maybe write a neat script/function that uses an array of all the possible objects, and searches Nearest for each of the types and returns the nearest of those.

like such:

ObjectArray = ["man","SoldierW","SoldierWMG","OfficerW","OfficerE","Car","Jeep" ....

_i = 0
_j = count ObjectArray
_nearest = SOME_REALLY_FAR_OBJECT_PLACEHOLDER
#loop
_found = NearestObject[ OBJECT, ObjectArray select _i]
? (_found Distance OBJECT) < (_nearest Distance OBJECT) : _nearest = _found
_i = _i + 1
?( _i < _j ) : goto #loop

;;_nearest is now the nearest object of _any_ type