OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: Axo 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:
_Near = nearestobject [_Obj,""]Returns _Obj always
And
_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)
-
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 (http://www.concept-5.com/ofp/tutorials/CMREFv103.htm#NearestObject) for mor info
-
Thanks!. IÂ've realized that if you specify a position as a parameter, it returns the nearest object of any kind to the pos... ::)
-
Uhm... i might be new, but when i try to do
_nearest = nearestobject [_obj,""]
the parser flips out and wants 3 arguments
-
The use is
_nearest = nearestobject [_x,_z,_y]
-
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