;improved and much more smaller position-script by Softegg, softegg.ofp@gmx.de
;
;inspired by Fishion, Jerommeke and toadlife
;
;syntax: [(x-coordinates),(y-coordinates)] exec "(scriptname)"

_obj = _this select 0
_xpos = _this select 1
_ypos = _this select 2

_letters = ["Aa","Ab","Ac","Ad","Ae","Af","Ag","Ah","Ai","Aj","Ba","Bb","Bc","Bd","Be","Bf","Bg","Bh","Bi","Bj","Ca","Cb","Cc","Cd","Ce","Cf","Cg","Ch","Ci","Cj","Da","Db","Dc","Dd","De","Df","Dg","Dh","Di","Dj","Ea","Eb","Ec","Ed","Ee","Ef","Eg","Eh","Ei","Ej","Fa","Fb","Fc","Fd","Fe","Ff","Fg","Fh","Fi","Fj","Ga","Gb","Gc","Gd","Ge","Gf","Gg","Gh","Gi","Gj","Ha","Hb","Hc","Hd","He","Hf","Hg","Hh","Hi","Hj","Ia","Ib","Ic","Id","Ie","If","Ig","Ih","Ii","Ij","Ja","Jb","Jc","Jd","Je","Jf","Jg","Jh","Ji","Jj"]
_numbers = ["99","98","97","96","95","94","93","92","91","90","89","88","87","86","85","84","83","82","81","80","79","78","77","76","75","74","73","72","71","70","69","68","67","66","65","64","63","62","61","60","59","58","57","56","55","54","53","52","51","50","49","48","47","46","45","44","43","42","41","40","39","38","37","36","35","34","33","32","31","30","29","28","27","26","25","24","23","22","21","20","19","18","17","16","15","14","13","12","11","10","09","08","07","06","05","04","03","02","01","00"]

?_xpos<0 or _xpos>12800:_xcoor="??";goto "Ycoor"

_xcoor = _letters select ((_xpos-64)/128)

#Ycoor

?_ypos<0 or _ypos>12800:_ycoor="??";goto "ShowXYcoor"

_ycoor = _numbers select ((_ypos-64)/128)

#ShowXYcoor

_obj sidechat format ["This is %1, requesting aerial pickup in %2 %3!",_obj,_xcoor,_ycoor]

#aff
~5
whq1 sidechat format ["This is air traffic control, affirmative %1, air rescue team is inbound to your current position.",_obj]

?!(local server): exit

_waircrft = "UH60" createVehicle getmarkerpos "wtnkpool"

"SoldierWB" createUnit [getMarkerPos "wtnkpool", grouprescue, "TMP1=this"]

_crew1 = TMP1

_crew1 assignasdriver _waircrft
_crew1 moveindriver _waircrft

_coordx = getpos _obj select 0
_coordy = getpos _obj select 1

[grouprescue, 1] setWPPos [_coordx,_coordy]
[_crew1] CommandMove [_coordx,_coordy]

#distance
~1
?!(alive _waircrft): whq1 sidechat format ["%1, sorry, the rescue helicopter went down. You'll need to move to a less hostile area for pickup.",_obj] and goto "deletecraft"
[_crew1] CommandMove [_coordx,_coordy]
?(_waircrft distance _obj <= 100): goto "continue"
goto "distance"

#continue
_crew1 sidechat "Ok we see you, hop on!"
_waircrft land "GET IN"

#chk2
~0.001
?!(alive _waircrft): whq1 sidechat "%1, sorry, the rescue helicopter went down. You'll need to move to a less hostile area for pickup." and goto "deletecraft"
_posres = getpos _waircrft select 2
?(_posres <= 5): _waircrft setfuel 0 and goto "chkcraft"
goto "chk2"

#chkcraft
~1
?!(alive _waircrft): whq1 sidechat "%1, sorry, the rescue helicopter went down. You'll need to move to a less hostile area for pickup." and goto "deletecraft"
?(_obj in _waircrft):_waircrft setfuel 1 and goto "rtb"
goto "chkcraft"

#rtb
_crew1 sidechat "Everyone aboard? We're heading back to base."
[grouprescue, 1] setWPPos getmarkerpos "farp1"
[_crew1] CommandMove getmarkerpos "farp1"

#distance2
~0.001
?!(alive _waircrft): whq1 sidechat "%1, sorry, the rescue helicopter went down. You'll need to move to a less hostile area for pickup." and goto "deletecraft"
?(_waircrft distance farp1 <= 100): goto "continue2"
goto "distance2"

#continue2
_crew1 sidechat "Ok, we're back at FARP1, hop on out sir!"
_waircrft land "GET OUT"

#wait1
~0.0001
?!(alive _waircrft): whq1 sidechat "%1, sorry, the rescue helicopter went down. You'll need to move to a less hostile area for pickup." and goto "deletecraft"
?!(_obj in _waircrft): goto "deletecraft"
_posres = getpos _waircrft select 2
?(_posres <= 2): _obj action ["GETOUT",vehicle _waircrft]
?(pilot2 in _waircrft and _posres <=2): pilot2 action ["GETOUT",vehicle _waircrft]
?(pilot3 in _waircrft and _posres <=2): pilot3 action ["GETOUT",vehicle _waircrft]
?(pilot4 in _waircrft and _posres <=2): pilot4 action ["GETOUT",vehicle _waircrft]
goto "wait1"

#deletecraft
[_crew1] CommandMove [85,12698]
~30
deletevehicle _waircrft
deletevehicle _crew1

exit
