Home   Help Search Login Register  

Author Topic: Nearest Object sqf and high ground  (Read 539 times)

0 Members and 1 Guest are viewing this topic.

Offline dmakatra

  • Members
  • *
  • Better known as Armsty
Nearest Object sqf and high ground
« on: 24 Jun 2004, 09:35:35 »
Hello all, thought this might fit in the guru advance section.

I'm using the NearestObj function (http://www.ofpec.com/editors/funcref.php?filter_func=43) along with the OnMapSingleClick command to detect the closest object. Works like a charm except that it doesn't work on some areas. I'm not sure but I suspect it doesn't work on higher ground. This is a real shame since my mission is on a hill :-\ .

This is a little script I started. I've checked so that the script activates. It does, but it just won't work.

Code: [Select]
_targets = ["HeliH","HeliHEmpty"]

closest = ([GL7, _targets] call nearestobj)

? (GL7 distance closest) <= 50 : GL7 setpos getpos closest
? (GL7 distance closest) > 50 : hint "Error! Max distance in function is 50 meters. How the hell did you activate this?"; exit

exit

What this script do is that it checks if a unit is within GL7, a setpossed GL to an OnMapSingleClick, and if it is, the closest unit in that area becomes 'closest'. Another script that I got looped recognize that the specific unit is closest and the show will go on. It just won't work on high ground!! :-\

Cheers for any reply.

:beat: *Gets Shot* :beat:

Bluelikeu

  • Guest
Re:Nearest Object sqf and high ground
« Reply #1 on: 24 Jun 2004, 12:03:28 »
The problem could be with the NearestObject function, but I blelieve that your problem is in the ?GL7 (Distance _Closest) <= 50 condition.

My computer gets some problems when using, it, as 50 doesn't always mean 50. If i have an object that is 1000m away from some point. and I write ?_Unit Distance GetMarkerPos _Marker  < 2000 : _Unit Setdammage 1.0. The unit doesn't always die. But if i increase 2000 to 4000, it kills the unit. My solution to your problem, would be to use the distance formula directly into your script.
Something like this
?(((Getpos _Unit Select 0) - (GetPos _Pos Select 0))^2 + ((GetPos _Unit Select 1) - (GetPos _Pos Select 1))^2 + ((GetPos _Unit Select 2) - (Getpos _Pos Select 2))^2)^(1/2) >= 50 : Exec "MyScript.sqs"

May be a bit lengthy, but it will also get the distance of height above the ground.

« Last Edit: 24 Jun 2004, 12:06:03 by Bluelikeu »

Offline dmakatra

  • Members
  • *
  • Better known as Armsty
Re:Nearest Object sqf and high ground
« Reply #2 on: 24 Jun 2004, 14:52:07 »
I still have to know which is the nearest object. :-\

:beat: *Gets Shot* :beat:

Unnamed

  • Guest
Re:Nearest Object sqf and high ground
« Reply #3 on: 24 Jun 2004, 17:58:01 »
You did'nt say what does not work. Is it the NearestObj function or the distance check thats failing?

If it's distance then try using the distancePos function in the editing centre. This will just get the distance in 2D, so height is not an issue.

Offline dmakatra

  • Members
  • *
  • Better known as Armsty
Re:Nearest Object sqf and high ground
« Reply #4 on: 24 Jun 2004, 18:44:14 »
I fixed it myself. I put all the units in an array and did a check which was the closest but cheers anyway Unnamed and Bluelikeu. :cheers:

:beat: *Gets Solved* :beat: