OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: bedges on 30 Jul 2005, 16:20:20
-
i've just checked the function library and note with interest that there's nothing that will return an object of any type, without specifying what to look for.
am i right in thinking i need to create an array containing each and every single kind of object and search through it to find out what the closest 'thing' to the player is?
-
_object = nearestObject [(position player select 0)+1*sin(direction player),(position player select 1)+1*cos(direction player),position player select 2]Returns every single object if they are within that 1 meter range in front of the player...
Actually, it returns the p3d model name but you can the check it's type with typeOf, or with something like
? "vehicleclassname" count [_object]>0: hint "vehicleclassname found!"
Note that trees, bushes rocks etc have no classnames...
And yes, no guarantees on any of the syntaxes, as usual.. ::)
-
now see, that's why i need ofpec online. my offline comref here says nearestobject requires a 'type' parameter...
many thanks my friend, my secret weapon now works a treat 8)
-
Oh no, what did I help to unleash upon unsuspecting OFP community... :(
:P :-*
-
How would I call on this code? ;D
-
Put it in some script which you then execute from the player's init, or from the init.sqs or from a trigger etc...
-
; *****************************************************
; ** nearestObjects.sqs
; HaterKint
; Fount at OFPEC
; 30 July 2005
;
; Returns every single object if they are within that 1 meter range in front of the player...
; Actually, it returns the p3d model name....
; Note that trees, bushes rocks etc have no classnames...
;
; *****************************************************
_object = nearestObject [(position player select 0)+1*sin(direction player),(position player select 1)+1*cos(direction player),position player select 2]
? "vehicleclassname" count [_object]>0: hint "vehicleclassname found!"
Now, I've tried variations on this exec "nearestObject.sqs" in the player's init. I set a trigger to TRUE and put this... or [] exec "....."
...I'm sorry. Would you hold my hand on this one. ::)
-
Instead of "vehicleclassname" use a real class of some vehicle, like "T-80", and walk to a T-80 and execute the script...
Just remember that you need to be closer than one meter of the vehicle...
Classes can be found in the config.. Not sure if there's a list somewhere on BIS vehicles...
And that's just an example code, if you really would like it to return objects you would need to write it as a function (.sqf), maybe give the function user a possibility to set the distance from the player on which spot the search is to be done etc, and forget about that count stuff... ;)
-
Instead of "vehicleclassname" use a real class of some vehicle, like "T-80"....
And that's just an example code, if you really would like it to return objects you would need to write it as a function (.sqf), maybe give the function user a possibility to set the distance from the player on which spot the search is to be done etc, and forget about that count stuff... ;)
So, using your suggestion to write it as a function, I will be able to detect and return the nearest object? :o
-
Yes...
That's what the nearestObject does anyway, this syntax just gives you the ability to give the 'spot' of search...
And surely, I'm not the only one who has had/used this idea... ::)