Jump to content
Sign in to follow this  
spamurai

setWaypointStatements Command

Recommended Posts

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">[_transportgroup, 1] setWaypointStatements ["true", "_helo FlyInHeight 4"];

The above line is intended to get a helicopter named helo to execute "FlyInHeight 4" when his first waypoint is done after spawning into the world. Normally I would just add the line to the waypoint On Act(ivate) field of the waypoint dialogue inside the mission editor, but since I have to script it in, it causes the engine to report an error.

Local Variable found in Global Environment.

I can see why it caused the error. So, what I need to figure out is how to refer to Helo in a manor ArmA can accept. How do I name or reference Helo without using _helo?

Share this post


Link to post
Share on other sites

[transportgroup, 1] setWaypointStatements ["true", "helo FlyInHeight 4"]

transportgroup = name of the transportgroup

helo = name of the helicopter unit as given in the editor.

unless Im mistaken about how to use this command.

_names can only be used within scripts.

You set those up from waypoints and triggers as such.

[transportgroup,helo] exec "lowaltitude.sqs"

in the script it will read at the top:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_transportgroup = _this select 0

_helo = _this select 1

Note that the first item is select 0 and not one. This can cause confusion to newcomers to scripting and this framework exists in other programming areas/scripting languages incidentally.

Share this post


Link to post
Share on other sites

My confusion is that the script this line is in, also generated the Helicopter it refers too... I didn't place helo into the game using the Mission Editor so, I havn't technically named the Helicopter helo in any code yet.

I can't pass the names Transportgroup or Helo in an array to the script because... the units they refer too don't technically exist until after the script runs(?)

How can I officially name the Helicopter "Helo" after it's created so ArmA can identify it outside the confines of this script? EI: In a global environment.

I'm probably being a complete N00b here, but could it be as easy as simply initializing the helicopter variable using just plain helo for everything instead of _helo?

I sense yet another trial and error experiment in the offering...

Share this post


Link to post
Share on other sites

There is a command: setVehicleVarName that will assign a global variable name to your script created vehicle.

You will have to add this line into the script.

Do this right below the line where the chopper is created.

_helo setvehicleVarname helo

Now your chopper will be accessable from a global waypoint command. The transport groupname may be a problem unless you can post the script so I can see I cant confirm that transportgroup part will work.

p.s. There are cases when a "_x" value can be used in global space but that is in specific cases and its allways within strings AFAIK.

Share this post


Link to post
Share on other sites

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">; Declare Variables

_target = getMarkerPos "helotarget";

_spawnpoint = getMarkerPos "helospawn";

_spawnX = getMarkerPos "helospawn" select 0;

_spawnY = getMarkerPos "helospawn" select 1;

_targetX = getMarkerPos "targetspawn" select 0;

_tagertY = getMarkerPos "targetspawn" select 1;

_eastGroup = createGroup East;

_transportGroup = createGroup East;

; Generate Helicopter Transport

_helo = createVehicle ["MI17_MG",_spawnpoint,[], 0, "FLY"];

_helo setVehicleVarName "helo";

_helo setPos [_spawnX, _spawnY, 30];

_helo FlyInHeight 15;

; Generate crew for the Helicopter

_pilot = _transportGroup createUnit ["SoldierEPilot",_spawnpoint,[], 0, "NONE"]; _pilot moveInDriver _helo; _pilot assignAsdriver _helo;

_copilot = _transportGroup createUnit ["SoldierEPilot",_spawnpoint,[], 0, "NONE"]; _copilot moveInCargo _helo; _copilot assignAsCargo _helo;

_gunner1 = _transportGroup createUnit ["SoldierEPilot",_spawnpoint,[], 0, "NONE"]; _gunner1 moveInGunner _helo; _gunner1 assignAsGunner _helo;

; Generate the Assault Squad

_a1a = _eastGroup createUnit ["SquadLeaderE", _spawnpoint, [], 0, "NONE"]; _a1a moveInCargo _helo; _a1a assignAsCargo _helo; _a1a setRank "COLONEL";

_a1b = _eastGroup createUnit ["SoldierEAT", _spawnpoint, [], 0, "NONE"]; _a1b moveInCargo _helo; _a1b assignAsCargo _helo;

_a1c = _eastGroup createUnit ["SoldierEB", _spawnpoint, [], 0, "NONE"]; _a1c moveInCargo _helo; _a1c assignAsCargo _helo;

_a1d = _eastGroup createUnit ["SoldierEB", _spawnpoint, [], 0, "NONE"]; _a1d moveInCargo _helo; _a1d assignAsCargo _helo;

_a1e = _eastGroup createUnit ["SoldierEMG", _spawnpoint, [], 0, "NONE"]; _a1e moveInCargo _helo; _a1e assignAsCargo _helo;

_a1f = _eastGroup createUnit ["SoldierEG", _spawnpoint, [], 0, "NONE"]; _a1f moveInCargo _helo; _a1f assignAsCargo _helo;

_a1g = _eastGroup createUnit ["SoldierEG", _spawnpoint, [], 0, "NONE"]; _a1g moveInCargo _helo; _a1g assignAsCargo _helo;

_a1h = _eastGroup createUnit ["SoldierEMG", _spawnpoint, [], 0, "NONE"]; _a1h moveInCargo _helo; _a1h assignAsCargo _helo;

_a1i = _eastGroup createUnit ["SoldierEMedic", _spawnpoint, [], 0, "NONE"]; _a1i moveInCargo _helo; _a1i assignAsCargo _helo;

_a1j = _eastGroup createUnit ["SoldierEAT", _spawnpoint, [], 0, "NONE"]; _a1j moveInCargo _helo; _a1j assignAsCargo _helo;

_a1k = _eastGroup createUnit ["SoldierEB", _spawnpoint, [], 0, "NONE"]; _a1k moveInCargo _helo; _a1k assignAsCargo _helo;

; Make sure the Assault Squad is all in one group and set the group in formation and combat mode.

[_a1a, _a1b, _a1c, _a1d, _a1e, _a1f, _a1g, _a1h, _a1i, _a1j, _a1k] join _eastgroup;

_eastGroup setformation "LINE";

_eastGroup setBehaviour "COMBAT";

_eastGroup setSpeedMode "NORMAL";

; Assign Waypoints to the Helicopter

_transportGroup addWaypoint [_target, 1]; [_transportGroupt, 1] setWaypointStatements ["true", "helo FlyInHeight 4;"]

;Assaign Waypoints to the Assault Squad.

_eastGroup addWaypoint [_target, 1];

This is the code that I wrote by hand. So, it may be long winded and lack certain logical shortcuts in wirting it, but that's the point of the learning process I guess.

The object of this script is that when a trigger is activated, a helicopter carrying an infantry squad is spawned into the world and proceeds to the designated area via a marker placed on the map. The end goal being that helicopter will eventually be scripted to land/hover so the squad can disembark and engage their enemies.

So far the script is mostly running as intended, but while no errors are reported, the intended effect isn't 100% as planned.

The helicopter generally spawns into the world at 30m's, descends to 15m's and fly's towards the first marker as planned. However, 1 of 2 things generally occurs;

A) The Helicopter stops on his MOVE waypoint (as planned), but does not adjust his height to 4m's (FlyInHeight 4).

B) He flies through his first Waypoint and just keeps on going. Sometimes he stops (several hundred meters away) and sometimes he just keeps going.

In the case B), it seems to be a habit of how the helicopter reacts to detecting an enemy player. It seems the Helicopter AI overrides it's navigation and waypoint FSM with it's combat FSM (?). The Helicopter seems to reliably perform A) when it doesn't see any enemies.

If I planned this all out in the Mission Editor, using the Editor dialogues, I can sequence a helicopter to fly in, hover and disembark infantry and then fly away.

Share this post


Link to post
Share on other sites

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_helo setbehaviour "careless"

_helo setcombatmode "BLUE"

_helo disableAI "target"

This should keep the helo from acting up when it finds a target.

Put these in right after you create and load the helo. Even though the _helo is an empty vehicle it should act as one unit once crewed. If not simply use driver _helo to force the commands right to the pilot.

driver _helo disableAI "target"

I think you should be ok the first way though.

Since you've come this far with scripting you may want to ditch waypoints and use the domove command. It works just as well unless you are sending the chopper very far distances in which case you have to make a chain of domoves but only very long distances like 10000 I believe

from Airlift:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_Transport domove _Lzpos

_timestart = _time + 100

@ _transport distance _lzpos < 200 OR _time >= _timestart

_transport flyInHeight 1

_transport land "get in"

_transport flyinheight 1

dostop (driver _transport)

_timestart2 = _time + 100

@ (getpos _transport select 2) < 5 OR _time >= _timestart2

? _time >= _timestart2: hint "landing sequence has failed!"

? _time >= _timestart2: exit

put logics where youre waypoints go in the editor and name them whatever you want. You are passing them into local variables in your script but you dont have to in this case.

The _timestart stuff is faliure code incase something goes wrong the script wont hang up in memory.

By the way you dont need vehiclevarname after all you could just remove the _ before the createvehicle code and those values will be globals but its good to learn new commands and it would work in either case.

Also you can create a unit and give it a group name and waypoints in the editor and actually deletevehicle the unit. IF you then createvehicle a unit and add it to that group they will inherit the waypoints once they are spawned.

So if you did it this way you could put the flyinheight code in the waypoint onActivation:

this flyinheight 4

and it should work.

Let me know if any of this isnt clear.

Youre on the right track, but I would ditch the waypoint code and use domove since your allready inside a script and Ive ben through all this allready so you can benefit from my experience.

Share this post


Link to post
Share on other sites

The doMove code is working pretty good and the Helicopter reacts pretty reliably even without disableAI.

So, I think I'm getting the hang of that.... mostly...

Next challenge is writing up a check for the Infantry squad so they know when it's safe to jump out (IE, jump out when the Helo is 3m's off the ground, not 30m's).

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  

×