Home   Help Search Login Register  

Author Topic: nearestobject [player,"any"]  (Read 1576 times)

0 Members and 1 Guest are viewing this topic.

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
nearestobject [player,"any"]
« 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?

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:nearestobject [player,"any"]
« Reply #1 on: 30 Jul 2005, 16:29:40 »
Code: [Select]
_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
Code: [Select]
? "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.. ::)
« Last Edit: 01 Aug 2005, 16:32:53 by HateR_Kint »
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:nearestobject [player,"any"]
« Reply #2 on: 30 Jul 2005, 16:44:29 »
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)

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:nearestobject [player,"any"]
« Reply #3 on: 30 Jul 2005, 17:50:19 »
Oh no, what did I help to unleash upon unsuspecting OFP community... :(




:P  :-*
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Crassus

  • Guest
Re:nearestobject [player,"any"]
« Reply #4 on: 01 Aug 2005, 16:17:00 »
How would I call on this code?  ;D

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:nearestobject [player,"any"]
« Reply #5 on: 01 Aug 2005, 16:32:23 »
Put it in some script which you then execute from the player's init, or from the init.sqs or from a trigger etc...
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Crassus

  • Guest
Re:nearestobject [player,"any"]
« Reply #6 on: 01 Aug 2005, 20:34:13 »
Code: [Select]
; *****************************************************
; ** 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
Code: [Select]
this exec "nearestObject.sqs" in the player's init. I set a trigger to TRUE and put
Code: [Select]
this... or
Code: [Select]
[] exec "....."
...I'm sorry. Would you hold my hand on this one.  ::)

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:nearestobject [player,"any"]
« Reply #7 on: 02 Aug 2005, 15:53:54 »
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... ;)
« Last Edit: 02 Aug 2005, 15:54:47 by HateR_Kint »
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Crassus

  • Guest
Re:nearestobject [player,"any"]
« Reply #8 on: 02 Aug 2005, 16:21:23 »
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

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:nearestobject [player,"any"]
« Reply #9 on: 02 Aug 2005, 17:17:23 »
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... ::)
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.