Home   Help Search Login Register  

Author Topic: Finding a location of a unit  (Read 1194 times)

0 Members and 1 Guest are viewing this topic.

SgtSlick

  • Guest
Finding a location of a unit
« on: 02 Jun 2006, 23:37:07 »
this may be easy, I've see somewhere a topic about using trigonometry... too confusing for me.

Picture this:

Your out in the field holding a hill waiting for a counter-attack. you look off to your left flank where another squad is supposed to be holding another hill. you can't tell if they're there or not but no movement has been spotted since you took up positions, so... you crawl over to your RTO and ask over the radio to the other squad "where are you?"


Outcome 1:
the other squad replies "Right here, where we're supposed to be" (location found matches a check through the script and puts this message instead of...)

Outcome 2:
the other squad replies "We're at (location)"

Outcome 3:
(no reply/error)


What i plan on doing is using an invisible unit (like an invisible "H") to mark where the squad is supposed to hold. when they are within so many meters they would reply the 1st outcome. but if they aren't... how do i find their location in grid reference?

and/or

if your not where your supposed to be they will give their coordinates and a hint box appears showing distance and direction of where they are.

ex. the hint says "They are at 210 DEG and 200m away from your position"


Problem For Me

I don't know how to:
1) Find a location of a unit
2) Find a relative heading

if anyone can help me out on those two problems, please, don't be shy; post and help. The scripting part i can do, but its those two sections i can't do.

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Finding a location of a unit
« Reply #1 on: 02 Jun 2006, 23:47:54 »
Find the location of a unit: position  = getPos unit
This does not give you grid coordinates, just location over map relative to [0,0,0] (lower, right corner of the map).

For angle relative between two units (angle from unit1 to unit2):
Code: [Select]
angle = ((getPos unit2 select 0)-(getPos unit1 select 0)) atan2 ((getPos unit2 select 1)-(getPos unit1 select 1))

Offline Garcia

  • Members
  • *
  • Leeds United is the best football team...EVER!
Re: Finding a location of a unit
« Reply #2 on: 03 Jun 2006, 00:28:17 »
There was a function in the editors depot to give you the grid, but since the editors depot is gone and all it's content with it, and since I don't have it, I can't give it to you :-\

Though I suppose you won't have to wait too long before someone who got it attaches it...

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Finding a location of a unit
« Reply #3 on: 03 Jun 2006, 01:14:53 »
To get location in format De-45:

Code: [Select]
;Darposicion.sqs by Mandoble
;
_unit = _this select 0
_letras1 = ["A","B","C","D","E","F","G","H","I","J"]
_letras2 = ["a","b","c","d","e","f","g","h","i","j"]
_numeros1 = ["9","8","7","6","5","4","3","2","1","0"]
_numeros2 = ["9","8","7","6","5","4","3","2","1","0"]
_maxx1 = 12800
_maxx2 = 1280
_maxy1 = 12800
_maxy2 = 1280
_xu = getPos _unit select 0
_yu = getPos _unit select 1

_l1 = 10 * _xu / _maxx1
_l1 = _l1 - (_l1 mod 1)
_n1 = 10 * _yu / _maxy1
_n1 = _n1 - (_n1 mod 1)

_xu = _xu - _l1*_maxx2
_l2 = 10 * _xu / _maxx2
_l2 = _l2 - (_l2 mod 1)

_yu = _yu - _n1*_maxy2
_n2 = 10 * _yu / _maxy2
_n2 = _n2 - (_n2 mod 1)
_coordstr = format["%1%2-%3%4", _letras1 select _l1, _letras2 select _l2, _numeros1 select _n1, _numeros2 select _n2]
cutText[_coordstr, "PLAIN DOWN"]
exit

SgtSlick

  • Guest
Re: Finding a location of a unit
« Reply #4 on: 04 Jun 2006, 20:09:42 »
thanks for the help! Now that i have this info i'm going to maximize on the script and add the above features.