Jump to content
Sign in to follow this  
q_phreak

My helicopter landing script

Recommended Posts

For the past months I've been working on this script and I thought I'd share it. I love missions that are dynamic and I rely on scripts rather than waypoints to move my units.

The way it works:

I use a hidden h somewhere on the map and using the setpos function move it close to the player (x + 10 offset, y + 10 offset). I've found without the H the helo will land and then bounce back up.

I then tell the helo to move towards the hidden h and when it gets within a close enough range i use the setpos function on the helo to control it's movements and guide it down onto the helipad. At this stage I have to thank Boomerang (boomerang333@rogers.com) for his HeloCargoTransport script which I butchered and use to learn the setpos and x,y,z grid functionality.

To run:

Create a helo name it "helo1"

Create a unit, player, name it "sas1"

Create a hidden H, name it "lz1"

Create a trigger, Activation: Radio Alpha, Name: Extract, Text: Extract, on Activation:[helo1,sas1,lz1] exec "extract.sqs"

The code:

I set up a radio trigger for say extraction which comprises of three scripts:

Extract.sqs:

; _helo is the name of the helo to be flown in

; _leader is the name of the player requesting the extraction

; _landzone is the name of the hidden h to be moved near the player

;helolanded,tmphelolanded,troopsloaded are global variables set to false initially

_helo=_this select 1

_leader=_this select 2

_landzone=_this select 3

?!(alive _helo): hint "Extraction Helo down. Make way to secondary extraction point."; exit

hint "Helo - inbound for extraction"

helolanded=false

tmphelolanded=false

troopsloaded=false

;get the position of the player to be extracted and offset x and y coords by 10

_landzonex = (getPos _leader select 0) + 10

_landzoney = (getPos _leader select 1) + 10

_landzonez = getPos _leader select 2

;move the hidden h to that position

_landzone setpos [_landzonex,_landzoney,_landzonez]

;fly in the helo

_helo flyinheight 30

_helo domove getpos _landzone

;execute generic land script to land at extraction

[_helo,_landzone,true,true] exec "heloland.sqs"

;wait until helo has landed

@tmphelolanded

;execute load check - checks to see if all group members are in helo

[_helo,_leader] exec "heloloadwait.sqs"

;wait until all troops loaded

@troopsloaded

;return to base

_waypoint=h1

tmphelolanded=false

_helo domove getpos _waypoint

;land at base

[_helo,_waypoint,false,false] exec "heloland.sqs"

@tmphelolanded

hint "helo - landed, on standby"

;set the global var indicating helo has landed

helolanded=true

exit

Heloland.sqs:

;_helo is the helo to land

;_waypoint is the landing zone (lz)

;_distmessageflag is a boolean to whether display helo distance to lz

;_flareflag is a boolean to whether set smoke and flare when helo close to lz

_helo = _this select 0

_waypoint = _this select 1

_distmessageflag = _this select 2

_flareflag = _this select 3

_waypointx = getpos _waypoint select 0

_waypointy = getpos _waypoint select 1

_waypointz = getpos _waypoint select 2

_messagecount=0

; move to waypoint

_helo domove getpos _waypoint

;if the helo is already close to the lz by pass the slow down etc

?(_helo distance _waypoint) <= 200: goto "movecloser1"

;slow down

#moveloop1

?(_helo distance _waypoint) <= 600: _helo setSpeedMode "LIMITED"; goto "mark"

~1

?(_messagecount==10 && _distmessageflag): hint format["Inbound helo is %1m away", (_helo distance _waypoint)]; _messagecount=0

_messagecount=_messagecount+1

goto "moveloop1"

#mark

?!(_flareflag): goto "moveloop2"

_flare1 = "flarered" camCreate [_waypointx,_waypointy,_waypointz]

_smoke1 = "SmokeShellRed" camCreate [_waypointx,_waypointy,_waypointz]

;wait for the helo to get close to the lz

#moveloop2

?(_helo distance _waypoint) <= 200: goto "movecloser1"

~0.1

goto "moveloop2"

#movecloser1

_helox = getpos _helo select 0

_heloy = getpos _helo select 1

_heloz = getpos _helo select 2

;determine how far in total to the x and y position of lz and divide it into 300 segments

_movex = (_helox - _waypointx)/300

_movey = (_heloy - _waypointy)/300

_counter=0

;this loop takes over the positioning of the helo on x + y coords and moves it over the lz by each 1/300th segment

#moveloop3

_thismovex = _helox - (_movex * _counter)

_thismovey = _heloy - (_movey * _counter)

_helo setpos [_thismovex,_thismovey,_heloz]

_counter = _counter + 1

?(_counter==300):goto "movefinalise1"

~0.01

goto "moveloop3"

;if the helo is still moving around, ie second distance to lz is more than first distance redo positioning from "movecloser1"

#movefinalise1

_dist1 = (_helo distance _waypoint)

~0.1

_dist2 = (_helo distance _waypoint)

?((_dist2-_dist1)>5): goto "movecloser1"

;determine how far in total to the z position of lz and divide it into 300 segments. issue a land command for helo which will land the helo, but the script will guide it down onto the lz.

#movecloser2

_helo land "LAND"

_helox = getpos _helo select 0

_heloy = getpos _helo select 1

_heloz = getpos _helo select 2

_movez = (_heloz - _waypointz)/300

_counter=0

;start lowering the helo

#landloop1

_thismovez = _heloz - (_movez * _counter)

_helo setpos [_helox,_heloy,_thismovez]

_counter = _counter + 1

?(_counter==300):goto "movefinalise2"

~0.01

goto "landloop1"

;check whether it has bounced

#movefinalise2

_dist1 = (_helo distance _waypoint)

~0.1

_dist2 = (_helo distance _waypoint)

?(((_dist2-_dist1)<=5) || (((getpos _helo select 2) - _waypointz) >2)): goto "successland"

_retry=2

;uneven land - helicopter bounced

#trycloser

_retry=_retry+2

_helo land "LAND"

_helox = getpos _helo select 0

_heloy = getpos _helo select 1

_heloz = getpos _helo select 2

_movez = (_heloz - _waypointz)/300

_counter=_retry

#landloop2

_thismovez = _heloz - (_movez * _counter)

_helo setpos [_helox,_heloy,_thismovez]

_counter = _counter + 1

?(_counter==300):goto "movefinalise3"

~0.01

goto "landloop2"

#movefinalise3

_dist1 = (_helo distance _waypoint)

~2

_dist2 = (_helo distance _waypoint)

?((_dist2-_dist1)<=(5+_retry)): goto "successland"

?(_retry>10): hint "Helo can't land, try another more even location."; goto "failedland"

goto "trycloser"

#failedland

tmphelolanded=false

exit

#successland

tmphelolanded=true

exit

Heloloadwait.sqs:

;_helo is the helo being loaded

;_leader is the group leader

_helo = _this select 0

_leader = _this select 1

;get all the units in the group

_leaderArray = units group _leader

;count all the units in the group

_numunits = count _leaderArray

#loop1

~0.5

_incount = 0

_tmp = 0

;loop until all units are inside the helo

#loop2

? vehicle (_leaderArray select _tmp) == _helo : _incount = _incount + 1

? _tmp < (_numunits - 1) : _tmp = _tmp + 1; goto "loop2"

? _incount != _numunits : goto "loop1"

;set the global var indicating all troops loaded

troopsloaded=true

exit

That's it. The only problem is when time compression is on the helicopter movement isn't sped up. Any comments or ideas how to make it better appreciated.

Q

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×