Jump to content
Sign in to follow this  
Meatball0311

decreasing altitude a few meters at a time every few seconds question...

Recommended Posts

I am making a helo extract script and I have everything so far working fine except the landing. The helicopter will fly to the position which is designated via onMapSingleClick and the group that is getting picked up orders all units OrderGetIn true, just fine. However when the helo is coming in for the landing it slams into the ground causing damage to the helicopter. I am thinking that I need to have the helicopter decrease altitude a few meters every few seconds to make a soft landing so the units can board the vehicle and the helicopter can move on to the next position.

I am using plain vanilla ArmA 2 to test this out. How would I script in sqf format a slow decend helo landing?

Here is the script I am working on:

//////////////////////////////////////////////////////////////////

// Made by Meatball0311

//////////////////////////////////////////////////////////////////

private ["_outboundpos", "_inboundpos", "_uhlz1", "_approach", "_pos", "_posx", "_posy", "_posz", "_ang1", "_ang2", "_ang3", "_avgang"];

// create Outbound marker

_outboundpos = createMarker["OUTBOUNDmarker",getPos OUTobject];

_outboundpos setMarkerShape "ICON";

"Outboundmarker" setMarkerType "waypoint";

"Outboundmarker" setMarkerSize [.3, .3];

"Outboundmarker" setMarkerColor "ColorGreen";

"Outboundmarker" setMarkerText "OUTBOUND FLIGHT PATH";

//creating Inbound marker

_inboundpos = createMarker["INBOUNDmarker",getPos INobject];

_inboundpos setMarkerShape "ICON";

"Inboundmarker" setMarkerType "waypoint";

"Inboundmarker" setMarkerSize [.3, .3];

"Inboundmarker" setMarkerColor "ColorRed";

"Inboundmarker" setMarkerText "INBOUND FLIGHT PATH";

// creating UHLZ1 marker

_uhlz1 = createMarker["UHLZ1marker",getPos UH1home];

_uhlz1 setMarkerShape "ICON";

"UHLZ1marker" setMarkerType "mil_triangle";

"UHLZ1marker" setMarkerSize [.3, .3];

"UHLZ1marker" setMarkerColor "ColorOrange";

"UHLZ1marker" setMarkerText "1";

// creating UHApproach marker

_approach = createMarker["APPROACHmarker",getPos UH1home];

_approach setMarkerShape "ICON";

"APPROACHmarker" setMarkerType "Pickup";

"APPROACHmarker" setMarkerSize [.3, .3];

"APPROACHmarker" setMarkerColor "ColorGreen";

// Radio trasmission REQUESTING HELO EXTRACT

PLT1_CMD sideChat "CARNAGE this is RHINO actual, over";

setfire=true;

CARNAGE_RO sideChat "RHINO actual we read you loud and clear, send your traffic, over";

PLT1_CMD sideChat "Roger, requesting helo extract, stand by for grid....";

CARNAGE_RO sideChat "Roger, standing by...";

titleText ["CLICK ON MAP TO SET HELO EXTRACT GRID","plain down"];

// set extaction pos (UHLZ1)

onMapSingleClick "UHLZ1 setPosATL _pos; setfire=false; onMapSingleClick ''; true";

waitUntil {!setfire};

Sleep 1;

// set H (invisible) objects in Y formation

_pos = position UHLZ1;

_posx = _pos select 0;

_posy = _pos select 1;

_posz = _pos select 2;

_ang1 = -((wind select 0) atan2 (wind select 1));

Sleep 0.01;

_ang2 = -((wind select 0) atan2 (wind select 1));

Sleep 0.01;

_ang3 = -((wind select 0) atan2 (wind select 1));

Sleep 0.01;

_avgang = (_ang1 + _ang2 + _ang3) / 3;

// Having objects face direction of wind (_avgang)

UHLZ1 setDir _avgang;

UHAPPROACH setPosATL [_posx + sin(_avgang)* 0,_posy + cos(_avgang)* - 500,0];

UHAPPROACH setDir _avgang;

// moving LZ markers to H (invisible) positions

"UHLZ1marker" setmarkerpos getPos UHLZ1;

"APPROACHmarker" setmarkerpos getPos UHAPPROACH;

// setting markers to face _avgang (wind direction)

"UHLZ1marker" setMarkerDir _avgang;

"APPROACHmarker" setMarkerDir _avgang;

onMapSingleClick "";

titleText ["", "plain down"];

private ["_UH1spawn", "_aviator", "_nav", "_gunner1", "_gunner2", "_wp1", "_wp2", "_wp3", "_wp4", "_wp5", "_wp1inf", "_x"];

// setting spawning locations for pilots

_UH1spawn = getMarkerPos "UHcrewspawnpos";

// create pilots type createUnit [ position, group, init, skill, rank]

UH1group = createGroup WEST;

_aviator = "USMC_Soldier_Pilot" createUnit [_UH1spawn, UH1group, "P_1=this", 1, "MAJOR"];

_nav = "USMC_Soldier_Pilot" createUnit [_UH1spawn, UH1group, "N_1=this", 1, "LIEUTENANT"];

_gunner1 = "USMC_Soldier_Crew" createUnit [_UH1spawn, UH1group, "G_1=this", 1, "PRIVATE"];

_gunner2 = "USMC_Soldier_Crew" createUnit [_UH1spawn, UH1group, "G_2=this", 1, "PRIVATE"];

// setting UH1 crew faces

P_1 setFace "face12";

N_1 setFace "face54";

G_1 setFace "face13";

G_2 setFace "face14";

// putting UH1 crew into their positions aboard UH1

P_1 assignAsDriver UH1;

P_1 moveInDriver UH1;

N_1 assignAsGunner UH1;

N_1 moveInTurret [uH1, [2]];

G_1 assignAsGunner UH1;

G_1 moveInTurret [uH1,[0]];

G_2 assignAsGunner UH1;

G_2 moveInTurret [uH1,[1]];

Sleep 3;

// confirming CARNAGE_RO has received helo extract grid

CARNAGE_RO sideChat "We copy grid... Helo's on the way. Out";

P_1 flyInHeight 50;

Sleep 0.125;

// UH1group waypoint 1

_wp1 = UH1group addWaypoint [getPos OUTobject, 0];

[uH1group, 1] setWPPos getPos OUTobject;

[uH1group, 1] setWaypointType "MOVE";

[uH1group, 1] setWaypointSpeed "FULL";

waitUntil {P_1 distance OUTobject < 300};

Sleep 0.125;

// UH1group waypoint 2

_wp2 = UH1group addWaypoint [getPos UHApproach, 0];

[uH1group, 2] setWPPos getPos UHApproach;

[uH1group, 2] setWaypointType "MOVE";

[uH1group, 2] setWaypointSpeed "FULL";

waitUntil {P_1 distance UHApproach < 100};

Sleep 0.125;

// UH1group waypoint 3

_wp3 = UH1group addWaypoint [getPos UHLZ1, 0];

[uH1group, 3] setWPPos getPos UHLZ1;

[uH1group, 3] setWaypointType "LOAD";

[uH1group, 3] setWaypointSpeed "LIMITED";

waitUntil {P_1 distance UHLZ1 < 300};

// UH1group waypoint 4

_wp4 = UH1group addWaypoint [getPos INobject, 0];

[uH1group, 4] setWPPos getPos INobject;

[uH1group, 4] setWaypointType "MOVE";

[uH1group, 4] setWaypointSpeed "FULL";

// UH1group waypoint 5

_wp5 = UH1group addWaypoint [getPos UH1home, 0];

[uH1group, 5] setWPPos getPos UH1home;

[uH1group, 5] setWaypointType "GETOUT";

[uH1group, 5] setWaypointSpeed "FULL";

{_x assignAsCargo UH1} forEach units INFgroup;

(units INFgroup) orderGetIn true;

waituntil {{_x in UH1} count units INFgroup == count units INFgroup};

Share this post


Link to post
Share on other sites

Try the land command. I don't see why you would need to script the helo moving down....

http://community.bistudio.com/wiki/land

Also, there seems to be a lot of redundant or unnecessary things in your script. Maybe I'm just not understanding though. For example:

private ["_outboundpos", "_inboundpos", "_uhlz1", "_approach", "_pos", "_posx", "_posy", "_posz", "_ang1", "_ang2", "_ang3", "_avgang"];

From what I understand about private, the way you have used it doesn't really have any effect. http://community.bistudio.com/wiki/private

// set H (invisible) objects in Y formation
_pos = position UHLZ1;
_posx = _pos select 0;
_posy = _pos select 1;
_posz = _pos select 2;
_ang1 = -((wind select 0) atan2 (wind select 1));
Sleep 0.01;
_ang2 = -((wind select 0) atan2 (wind select 1));
Sleep 0.01;
_ang3 = -((wind select 0) atan2 (wind select 1));
Sleep 0.01;
_avgang = (_ang1 + _ang2 + _ang3) / 3;
// Having objects face direction of wind (_avgang)
UHLZ1 setDir _avgang;
UHAPPROACH setPosATL [_posx + sin(_avgang)* 0,_posy + cos(_avgang)* - 500,0];
UHAPPROACH setDir _avgang;

I don't understand why you're needing H objects to face the wind. It seems like a lot of unnecessary code, it could make for easier debugging if you didn't have to do this.

You have a lot of sleep statements. Do you really need the

Sleep 0.125;

After each waypoint? Also your waypoints have waitUntil statements between them. Why do you need this? You should be able to just add all the waypoints. If you are waiting for waypoints to complete before adding new ones, it has the potention to make your script more intensive, since it has to sit in the waitUntil loops for a long time.

http://community.bistudio.com/wiki/setWaypointStatements

You might consider using waypoint statements (just like adding conditions / onActivation stuff in the editor)

It's hard to tell exactly what is going wrong in your script. That's why I pointed out some things that I think may be contributing to the odd behavior. I think you should try using set waypoint statements to tell the helicopter to land once it reaches a move waypoint close to the H's. Once it's landed and all units are inside, then you can tell it to move somewhere else, it should automatically do a lot of these things.

If you have an example mission I could try playing around with it, cause honestly this is something I've been wanting to make too.

Share this post


Link to post
Share on other sites

thanks for the pointers! here is a test mission, I am just using vanilla arma2 so not addons are required. Please check it out and I think that it is possible to actually make this script work.

http://www.filefront.com/15438909/test.utes.zip/

---------- Post added at 05:07 PM ---------- Previous post was at 05:05 PM ----------

the wind factor would be adding realism to it, as helo's land facing with the wind. But I will take that out until I get this working properly

---------- Post added at 05:37 PM ---------- Previous post was at 05:07 PM ----------

I think there is a bug because this is what I did and the same thing happened and I dont know any other way....

I tried everything including flyInHeight 2.... Please no one even suggest me using SOM

//////////////////////////////////////////////////////////////////

// Made by Meatball0311

//////////////////////////////////////////////////////////////////

private ["_outboundpos", "_inboundpos", "_uhlz1", "_approach", "_pos", "_posx", "_posy", "_posz", "_ang1", "_ang2", "_ang3", "_avgang"];

// create Outbound marker

_outboundpos = createMarker["OUTBOUNDmarker",getPos OUTobject];

_outboundpos setMarkerShape "ICON";

"Outboundmarker" setMarkerType "waypoint";

"Outboundmarker" setMarkerSize [.3, .3];

"Outboundmarker" setMarkerColor "ColorGreen";

"Outboundmarker" setMarkerText "OUTBOUND FLIGHT PATH";

//creating Inbound marker

_inboundpos = createMarker["INBOUNDmarker",getPos INobject];

_inboundpos setMarkerShape "ICON";

"Inboundmarker" setMarkerType "waypoint";

"Inboundmarker" setMarkerSize [.3, .3];

"Inboundmarker" setMarkerColor "ColorRed";

"Inboundmarker" setMarkerText "INBOUND FLIGHT PATH";

// creating UHLZ1 marker

_uhlz1 = createMarker["UHLZ1marker",getPos UH1home];

_uhlz1 setMarkerShape "ICON";

"UHLZ1marker" setMarkerType "mil_triangle";

"UHLZ1marker" setMarkerSize [.3, .3];

"UHLZ1marker" setMarkerColor "ColorOrange";

"UHLZ1marker" setMarkerText "1";

// creating UHApproach marker

// Radio trasmission REQUESTING HELO EXTRACT

PLT1_CMD sideChat "CARNAGE this is RHINO actual, over";

setfire=true;

CARNAGE_RO sideChat "RHINO actual we read you loud and clear, send your traffic, over";

PLT1_CMD sideChat "Roger, requesting helo extract, stand by for grid....";

CARNAGE_RO sideChat "Roger, standing by...";

titleText ["CLICK ON MAP TO SET HELO EXTRACT GRID","plain down"];

// set extaction pos (UHLZ1)

onMapSingleClick "UHLZ1 setPosATL _pos; setfire=false; onMapSingleClick ''; true";

waitUntil {!setfire};

Sleep 1;

// set H (invisible) objects in Y formation

_pos = position UHLZ1;

_posx = _pos select 0;

_posy = _pos select 1;

_posz = _pos select 2;

// moving LZ markers to H (invisible) positions

"UHLZ1marker" setmarkerpos getPos UHLZ1;

// setting markers to face _avgang (wind direction)

onMapSingleClick "";

titleText ["", "plain down"];

// setting spawning locations for pilots

// confirming CARNAGE_RO has received helo extract grid

CARNAGE_RO sideChat "We copy grid... Helo's on the way. Out";

private ["_INFgroup"];

// UH1group waypoint 1

UH1 doMove getPos OUTobject;

waitUntil {UH1 distance OUTobject < 100};

UH1 doMove getPos UHLZ1;

waitUntil {UH1 distance UHLZ1 < 200};

UH1 land "GET IN";

{_x assignAsCargo UH1} forEach units INFgroup;

(units INFgroup) orderGetIn true;

waituntil {{_x in UH1} count units INFgroup == count units INFgroup};

Edited by Meatball0311

Share this post


Link to post
Share on other sites

I would actually spawn one waypoint and then wait untill it reached it alive and okay before spawning the next waypoint. Its true that waituntill is bad here because of the high speed of the loop being wasteful on resources so set up a while do loop and use sleep. Then check if the chopper and pilot are ok somehow with getdamage and !alive checks. Theres no guarantee the chopper is going to make it there. If so the script should exit out so it doesnt loop with waituntill the whole rest of the mission.

I like the wind thing, I didnt realize the heli lines up to the H like that! Actually the invisi H is a good thing to have as the chopper should dedicate itself to that location instead of landing 100 meters off the Marker pos. This is used with:

heli Land "get in"

which worked OK in ARMA combined with

Setbehaviour "CARELESS"

disableAI "AUTOTARGET"/"TARGET"

In Arma2 1.05 though it may be different. Though the last two commands should allways be used for transport heli. Otherwise it flies off mission.

I would think the land and get in/out waypoints should work ok but make sure by testing in a hot LZ and see if the AI pilot does anything unexpected. If the waypoint or land "get in" doesnt work then you may need a manual method after all.

You could try:

heliname setvelocity [0,0,-x]

where the -x is a push down of a certain factor. Obviously too much will send the thing smashing into the ground to its fiery death, which is great for laughs the first time but is not what we are going for.

A loop with the setvelocity code and probably disableAI "Move", so the heli doesnt react to being pushed around, in a regular loop would gently lower the chopper. Then check the distance to ground each pass and stop when the heli is either on the ground or perhaps, yes, has been killed before it had a chance to land.

You could try setpos method but it will look choppy. But would be more mathematically precise and with a fast enough loop and tweaking could look smooth enough. I have made loops that rotate the chopper in same fashion with setdir and it seemed to work ok. No CTD's but in general definately dont use waituntil or @ unless you need very high speed check like tracking a bullet untill its dead. Always set up manual timed loops for most things so you can controll the cpu use of your code.

Once its down you decide how to handle the disembarking/waitperiod and take off rules. For my scripts I would count the passenger group and the pilot group and then check if the count of crew vehicle was equal to pilot crew count. Then chopper takes off and it worked well for me and people who used it.

I like to put sleep values (or ~ in .sqs) into variables in the init so I can reuse the variable in scripts where appropriate and then change the one variable value to "tune" the timing of many sleeps easily. Just a tip.

Share this post


Link to post
Share on other sites
I would actually spawn one waypoint and then wait untill it reached it alive and okay before spawning the next waypoint. Its true that waituntill is bad here because of the high speed of the loop being wasteful on resources so set up a while do loop and use sleep. Then check if the chopper and pilot are ok somehow with getdamage and !alive checks. Theres no guarantee the chopper is going to make it there. If so the script should exit out so it doesnt loop with waituntill the whole rest of the mission.

I like the wind thing, I didnt realize the heli lines up to the H like that! Actually the invisi H is a good thing to have as the chopper should dedicate itself to that location instead of landing 100 meters off the Marker pos. This is used with:

heli Land "get in"

which worked OK in ARMA combined with

Setbehaviour "CARELESS"

disableAI "AUTOTARGET"/"TARGET"

In Arma2 1.05 though it may be different. Though the last two commands should allways be used for transport heli. Otherwise it flies off mission.

I would think the land and get in/out waypoints should work ok but make sure by testing in a hot LZ and see if the AI pilot does anything unexpected. If the waypoint or land "get in" doesnt work then you may need a manual method after all.

You could try:

heliname setvelocity [0,0,-x]

where the -x is a push down of a certain factor. Obviously too much will send the thing smashing into the ground to its fiery death, which is great for laughs the first time but is not what we are going for.

A loop with the setvelocity code and probably disableAI "Move", so the heli doesnt react to being pushed around, in a regular loop would gently lower the chopper. Then check the distance to ground each pass and stop when the heli is either on the ground or perhaps, yes, has been killed before it had a chance to land.

You could try setpos method but it will look choppy. But would be more mathematically precise and with a fast enough loop and tweaking could look smooth enough. I have made loops that rotate the chopper in same fashion with setdir and it seemed to work ok. No CTD's but in general definately dont use waituntil or @ unless you need very high speed check like tracking a bullet untill its dead. Always set up manual timed loops for most things so you can controll the cpu use of your code.

Once its down you decide how to handle the disembarking/waitperiod and take off rules. For my scripts I would count the passenger group and the pilot group and then check if the count of crew vehicle was equal to pilot crew count. Then chopper takes off and it worked well for me and people who used it.

I like to put sleep values (or ~ in .sqs) into variables in the init so I can reuse the variable in scripts where appropriate and then change the one variable value to "tune" the timing of many sleeps easily. Just a tip.

Wow! I will have to re-read this several times before I understand it, but I am sure it is going to teach me a lot. Thanks.

I will have to take this in steps as my script writing skills are slowly developing.

First step would be is to start over figuratively speaking, lets take the first major part that I should re-write and that is the spawning of the first waypoint and checking to see if the helo crew or helo is still alive. So it will look something like.. this?

_pilot = driver UH1;

?(alive _pilot) then

{

UH1 doMove getPos UHLZ1;

}

else

{

exitwith ???????????? (I dont know how to do this part)

If someone could elaborate more on this I would appreciate it

Share this post


Link to post
Share on other sites

http://www.armaholic.com/page.php?id=8337

I don't wanna come off as an asshole but if it helps lawndartleo wrote a good script for my air support package (sendTrans.sqf) that does what your wanting. If you want you can look into it, copy it, steal it or just see how this script chooses to do it.

Share this post


Link to post
Share on other sites
http://www.armaholic.com/page.php?id=8337

I don't wanna come off as an asshole but if it helps lawndartleo wrote a good script for my air support package (sendTrans.sqf) that does what your wanting. If you want you can look into it, copy it, steal it or just see how this script chooses to do it.

Please dont think that you are being an asshole by suggesting something. That is that whole point of this thread, is that I need some direction and examples. I will definitely look at this and see what I can learn from it, thanks!

Share this post


Link to post
Share on other sites
Hi Meatball0311,

I don't know if this could be useful to you, but you could check a script called VFTCAS - Terrain Collision Avoidance System:

http://www.armaholic.com/page.php?id=8118

May be you can find some tips in it for yourproject. :D

Good luck! Best, Splicer.

Thanks for the tip, but I guess I would have to un-pbo that to get into the scripts for examples. Actually I have modified Drapers Air Support scripts and plan on releasing something soon. Of course credit is going to be given to all where it is due.

Share this post


Link to post
Share on other sites

a little update... ever since I started to play Bohemian Interactive games (OFP was the beginning), I always loved helo operations. I joined the Marine Corps as and Infantry Rifleman and God willing was placed in a Helo Infantry Company. Least to say I love helo's and have always been looking for a good helo insertion/extraction script. Well I found one in Drapers Air Support scripts. So I decided to take a look at them and opened up the scripts and something amazing happened..... I actually started to understand the amazing science of script writing!! After all of these years of attempting to write scripts, but always getting stuck on a "how do I do this....", I believe Draper and lawndartleo may have shined some light on some things. Some stuff I am still not grasping yet, so I have kept their work in some of my scripts, but I have added some things also that I hope people will enjoy and will also bring some more realism to this fascinating game called ArmA2. Hopefully in a few days (or possibly sooner) I will release these scripts to the public after I have tested these to the fullest I can. Once again thanks to all that are reading this and all that who have helped me!

Edited by Meatball0311

Share this post


Link to post
Share on other sites

Thank YOU Meatball0311.

Take care and be safe marine!

Best, Splicer.

Share this post


Link to post
Share on other sites

Thank you! A little update I had to do a system restore on my computer last night so I am doing a lot of downloading today. This weekend will be a busy one so I hope to have something released by Monday! Thanks for all of your patience

Share this post


Link to post
Share on other sites

Ouch! I hate it when it happens. My video card went bad and a replacement should arrive today any time now... I can hardly wait... This game is ADDICTIVE AND LOTS OF FUN! :D

Best, Splicer.

Share this post


Link to post
Share on other sites

Well a little update is I had some computer issues and I will resume my testing on the scripts probably later tonight after the super bowl. will try to get them out asap.

Share this post


Link to post
Share on other sites

OK. Super Bow is over (don't know if you're celebrating because NO won or the Colts lost).

In any case, have a few beers, enjoy the rest of the night, and post your breakthroughs soon. :D

Best, Splicer.

Share this post


Link to post
Share on other sites

Well I should be releasing some scripts that will be apart of my "Helo Operations package", later on today or (tonight) when I get some detailed README's written up. I do have to give a special big thanks to Draper and lawndartleo for allowing me to pull apart their work and add a little spicy meatball flavoring.

These scripts are going to hopefully serve as a basis for future improvements in helo operations (extract, transport, close air support). There are still much more that I would like to improve on, so I am always up to suggestions and comments.

When I am ready to post them, I will provide a link to the newly added thread that will be the appropriate place to discuss the testing process. Thanks to all who are following this and to all who will use my work. Thanks.

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  

×