Home   Help Search Login Register  

Author Topic: grid locations  (Read 2821 times)

0 Members and 1 Guest are viewing this topic.

Offline majorjustice

  • Members
  • *
grid locations
« on: 05 Aug 2009, 18:35:05 »
hi im having a problem with a mission

i am trying to make a randomly placed invisible H (heli pad) give its grid location to the player through the side chat .. for exsample "base: lz is at grid loction 006029"

i have tryed using getpos but have no idea how to convert what is returned into a grid coordinate

any help is much appreciated  :)



Offline Trapper

  • Honoured Contributor
  • ***
  • I'm a llama!
Re: grid locations
« Reply #1 on: 05 Aug 2009, 22:44:38 »
Maybe there are old scripts in the Editors Depot or the boards doing this for the previous games. You would have to edit them.
Also I've read in the news ArmA2 includes many functions. Who knows, maybe that's included now.

On the other hand it's just math. Find out the size of a single map grid and relate this by dividing to the getpos result which should inherit from the bottom left of the map. Then count the grids and give an output.

hint format ["base: lz is at grid loction %1",GRIDRESULT]

Offline majorjustice

  • Members
  • *
Re: grid locations
« Reply #2 on: 05 Aug 2009, 23:50:37 »
hey thanks for the reply and i have found some old scripts for arma tht would do it but they use the old grid refrence using letters aswell as numbers and now its all numbers (6 figure grid refrence) and i dont have the know how to change it :(  also im not quite sure how to do what your talking about if u could break it down slightly i wud grateful :) and also here is the old sricpt if u have any idea on wat to do

Code: [Select]
private ["_result","_GrandeLettre","_PetiteLettre","_Chiffre", "_Chiffrestring","_Pos","_ArrayMajuscForGrid","_ArrayMinusForGrid " ];

_ArrayMajuscForGrid = ["A","B","C","D","E","F","G","H","I","J"];
_ArrayMinusForGrid = ["a","b","c","d","e","f","g","h","i","j"];

_Pos = _This select 0;
_Chiffrestring ="";
_result = "";
_GrandeLettre = (((_Pos select 0) - ((_Pos select 0) Mod 1280))/1280);                             
_PetiteLettre =((((_Pos select 0) Mod 1280)- (((_Pos select 0) Mod 1280)Mod 128))/128);   
_Chiffre = (99 - ((_Pos select 1) - ((_Pos select 1) Mod 128))/128);         
_Chiffrestring = Format["%1",_Chiffre];
If (_Chiffre < 10) then  {_Chiffrestring = "0" + _Chiffrestring };
_result = ((_ArrayMajuscForGrid select _GrandeLettre) + ( _ArrayMinusForGrid select _PetiteLettre) +_Chiffrestring);

_result

Offline jones

  • Members
  • *
Re: grid locations
« Reply #3 on: 06 Aug 2009, 04:44:31 »
This is the function used from the game. I know it works for Chenarus not sure about any other maps


Code: [Select]
private ["_x","_y","_xgrid","_ygrid","_xcoord","_ycoord","_result"];

_x = (_this select 0) select 0;
_y = (_this select 0) select 1;


_xgrid = floor (_x / 100);
_ygrid = floor ((15360 - _y) / 100);

_xcoord =
if (_xgrid >= 100) then {
str _xgrid;
} else {
if (_xgrid >= 10) then {
"0" + str _xgrid;
} else {
"00" + str _xgrid;
};
};

_ycoord =
if (_ygrid >= 100) then {
str _ygrid;
} else {
if (_ygrid >= 10) then {
"0" + str _ygrid;
} else {
"00" + str _ygrid;
};
};

_result = [_xcoord,_ycoord];
_result

I just tested it on utes and I had to rewrite the code this works on both islands

Code: [Select]
private ["_x","_y","_xgrid","_ygrid","_xcoord","_ycoord","_result"];

_x = (_this select 0) select 0;
_y = (_this select 0) select 1;

_cfg = configFile>>"CfgWorlds">>worldName;

Switch toLower (worldName) do{

case "utes": {_ygrid = floor ( (5120 - _y) / 100);};

case "chernarus": {_ygrid = floor ( (15360 - _y) / 100);};

default {_ygrid = floor ( (15360 - _y) / 100);};
};

_xgrid = floor (_x / 100);


_xcoord =
if (_xgrid >= 100) then {
str _xgrid;
} else {
if (_xgrid >= 10) then {
"0" + str _xgrid;
} else {
"00" + str _xgrid;
};
};

_ycoord =
if (_ygrid >= 100) then {
str _ygrid;
} else {
if (_ygrid >= 10) then {
"0" + str _ygrid;
} else {
"00" + str _ygrid;
};
};

_result = [_xcoord,_ycoord];
_result;
« Last Edit: 08 Aug 2009, 05:39:41 by jones »

Offline majorjustice

  • Members
  • *
Re: grid locations
« Reply #4 on: 06 Aug 2009, 21:33:18 »
thanks for the input :) now how wud i get the coordinate to come up on the global chat for exsample im really new to scripting  :no:

Offline jones

  • Members
  • *
Re: grid locations
« Reply #5 on: 07 Aug 2009, 00:19:31 »
try out the script in the file I attached.


Offline majorjustice

  • Members
  • *
Re: grid locations
« Reply #6 on: 12 Aug 2009, 17:24:57 »
wow thanks so much jones thts a massive help just wat i wanted :)

Offline jones

  • Members
  • *
Re: grid locations
« Reply #7 on: 12 Aug 2009, 21:45:43 »
The sample mission is different than the script I posted I had changed it a bit so that it would work on both islands. Just copy and past the code fromt he post obve into the pos2grid .sqf