Jump to content
Sign in to follow this  
jkhaaja

Making a chopper circle around you endlessly

Recommended Posts

Hey everyone,

im relatively new to scripting and arma mission editing. I have done some simple scripts and im familiar with the editor, triggers etc. I have been trying to do a script that would make a helicopter circle around the player at lets say for example 1 km radius. I have been trying to achieve this by using the waypoint setWPPos position command. First I created a waypoint at a marker on the map for the chopper and then tried to move it around the players position. For some reason the chopper only wants to move to the original point where the waypoint was first placed.

Is there a better way to do this?

In the end I would want to do this so that I have an AI flying an apache around a ground team with the apache set to careless and never fire. Then a player will be manning the gunners seat and providing air support.

wp0 = test addWaypoint [markerpos "temp",1];

hint "waypoint added, moving position";

while {true} do {

wp0 setWPPos [(getpos player select 0) + 50, (getpos player select 1) + 50];

wp0 setWaypointType "MOVE";

wp0 setWaypointSpeed "FULL";

sleep 5;

wp0 setWPPos [(getpos player select 0) + 50, (getpos player select 1) -50];

wp0 setWaypointType "MOVE";

wp0 setWaypointSpeed "FULL";

sleep 5;

wp0 setWPPos [(getpos player select 0) - 50, (getpos player select 1) - 50];

wp0 setWaypointType "MOVE";

wp0 setWaypointSpeed "FULL";

sleep 5;

wp0 setWPPos [(getpos player select 0) - 50, (getpos player select 1) + 50];

wp0 setWaypointType "MOVE";

wp0 setWaypointSpeed "FULL";

sleep 5;

};

Edited by jkhaaja

Share this post


Link to post
Share on other sites

Hi,

Place the Functions module on editor:

while { alive _chopper } do
{
private ["_center", "_radius""_pos"];
_center = getPos player;
_radius = 100;
_pos = [_center, _radius, (random 360)] call BIS_fnc_relPos;
_chopper doMove _pos;
waitUntil { !alive _chopper || unitReady _chopper };
};

_neo_

Share this post


Link to post
Share on other sites

Hi Neo,

Thanks for the tip I have to try that. Is it possible to incorporate the careless and never fire modes with this approach? I tried your code and for some reason the chopper again only flies to the first position and then just idles around. I guess the unit doesnt finish the first order for some reason and is therefore not ready and the loop doesn continue.

I tested it a bit further and it seems that if I delete the functions module the script still works in the same exact way so maybe the call for the BIS_fnc_relPos is wrong?

Edited by jkhaaja

Share this post


Link to post
Share on other sites
Hi Neo,

Thanks for the tip I have to try that. Is it possible to incorporate the careless and never fire modes with this approach? I tried your code and for some reason the chopper again only flies to the first position and then just idles around. I guess the unit doesnt finish the first order for some reason and is therefore not ready and the loop doesn continue.

I tested it a bit further and it seems that if I delete the functions module the script still works in the same exact way so maybe the call for the BIS_fnc_relPos is wrong?

Hey,

Im sorry mate, I havent tested the code (and did not let you know).

Here is a tested and working example:

private ["_chopper", "_radius"];
_chopper = _this select 0;
_radius = 100;

while { alive _chopper } do
{
private ["_center", "_pos"];
_center = getPos player;
_pos = [_center, _radius, (random 360)] call BIS_fnc_relPos;

_chopper doMove _pos;
waitUntil { !alive _chopper || unitReady _chopper };
};

Call is with:

_nic = [chopper] execVM "cas.sqf";

Again, this is just an example on how to do it.

_neo_

Share this post


Link to post
Share on other sites

Thanks for the code Neo. I think this will be very helpful. I didnt get the setBehaviour etc to work before while testing the previous code. But I think I will get around to it. Thanks again!

Share this post


Link to post
Share on other sites
Is it possible to incorporate the careless and never fire modes with this approach?

yes, but you have to setBehaviour and setCombatMode after the domove command, because domove resets all previous behaviour back to default aware yellow.

simply add the desired lines after the domove line.

Also i would recomend dividing _chopper up in vehicle and driver and group instead of using the chopper name if placed NOT EMPTY in editor.

Not sure if it matters at all, but i think name in name box in a preplaced heli in editor with crew is treated as both vehicle and group, unsure.

anyhow, easier to divide them up and you get better overview if you keep adding to the script.

Edited by Demonized

Share this post


Link to post
Share on other sites

Is it at all possible to merge waypoints? By this I mean to create a series of waypoints in the shape of a circle (for example). And then sort of 'combine' the first WP with the last? So the heli (for example) will follow WP's in the circle pattern, then when it gets to the last WP, it travels to the first and repeats the process? This all guesswork ofcourse, but I have been wondering this for awhile. Anyone?

Share this post


Link to post
Share on other sites

A "CYCLE" waypoint causes the unit to go next to its other waypoint nearest the "cycle" waypoint. Thus if you make a circle as you describe, placing a "CYCLE" waypoint as the last waypoint, right next to a waypoint at the beginning of the circle, the unit will go from one to the next and continue looping.

Share this post


Link to post
Share on other sites
A "CYCLE" waypoint causes the unit to go next to its other waypoint nearest the "cycle" waypoint. Thus if you make a circle as you describe, placing a "CYCLE" waypoint as the last waypoint, right next to a waypoint at the beginning of the circle, the unit will go from one to the next and continue looping.

Brilliant! Thanks for that, much appreciated. Would this solve this threads original problem, instead of all that scripting? Or have I read the original post wrong?

Also, any idea how to make vehicles e.g a humvee, not stop every time they hit another waypoint, like travelling down a twisting road obviously requires many waypoints (atleast as far as I know) and they stop for 1-2 seconds every time they hit the next one, help!? D:

Edited by SGT M

Share this post


Link to post
Share on other sites
Brilliant! Thanks for that, much appreciated. Would this solve this threads original problem, instead of all that scripting? Or have I read the original post wrong?

Also, any idea how to make vehicles e.g a humvee, not stop every time they hit another waypoint, like travelling down a twisting road obviously requires many waypoints (atleast as far as I know) and they stop for 1-2 seconds every time they hit the next one, help!? D:

instead of "all" this scripting you will need to script the wps and move them acording to player movement, so you will actually get longer script, but yeah using the wps would be fool proof and probably the best approach for a new scripter editor instead of domove.

you can place the wps for the heli in the editor aswell, but if player moves and heli should follow him, you still need to script the adjustment of the wps either in a trigger or a script.

For the cars stopping, no, they stop at each wp to calculate route to next, if route is easily found eg on a desert road close they will probably not stop only slow down a few micro secs, if route is through a tight city eg Zargabad and long they will use more time to calculate the route (find it).

PS: do a search for mr murrays editing guide deluxe, its a new missionmakers first bible, very detailed and big collection regarding almost all aspects of Arma2

Edited by Demonized

Share this post


Link to post
Share on other sites

I got a code similar to the one neo posted to work (I altered it so that the chopper goes on the circle rather than goign into a random position on it). Is there anyway to alter the accuracy of the doMove position (sometimes the chopper turns around to hit the spot perfectly)? Also that stopping at the domove points is a bit annoying but that can be dealt with by having fewer points on the circle.

Share this post


Link to post
Share on other sites
I got a code similar to the one neo posted to work (I altered it so that the chopper goes on the circle rather than goign into a random position on it). Is there anyway to alter the accuracy of the doMove position (sometimes the chopper turns around to hit the spot perfectly)? Also that stopping at the domove points is a bit annoying but that can be dealt with by having fewer points on the circle.

you can simply replace the unitready check with a distance check and issue a new doMove before the previous one is completed, voila, no stops :)

alter the accuracy of the distance check with random numbers or other ways.

Share this post


Link to post
Share on other sites

Right, good point! I will try this next.

---------- Post added at 04:25 PM ---------- Previous post was at 03:44 PM ----------

That worked like a charm with the distance check. Im still having one problem though, for some reason the setSpeedMode = "LIMITED" is not working. The setBehaviour etc work. The chopper keeps flying at 260 speed which is a bit too much for doing cannon CAS. Any other methods to limit the speed of the chopper to for example 60?

Share this post


Link to post
Share on other sites

use a loop of limitspeed

example:

iAmStrafingNow = true;
[objectName] spawn {
  objectName = _this select 0;
  while {iAmStrafingNow} do {
     // objectName limitSpeed speedInKm_hour;
     objectName limitSpeed 60;
     sleep 0.1;
     if (!iAmStrafingNow) then {
        waitUntil {iAmStrafingNow};
     };
  };
};

Now as long as iAmStrafingNow is true it will limit speed to whatever km/hour you specify, when iAmStrafingNow is false it will resume normal speed and wait for iAmStrafingNow to be true again (on/off)

Edited by Demonized
corrected a error ] to } in the while line...

Share this post


Link to post
Share on other sites

Yeah I also tried limitSpeed alone inside the first loop which has the doMove but that didnt seem to work. It should have worked in that loop aswell if it was goint to work in the first place? Just tried it again with your code, for some reason the chopper wants to ignore the limitSpeed command. The object name is the chopper name right? I also tried forceSpeed and taht didnt seem to work either.

Edited by jkhaaja

Share this post


Link to post
Share on other sites

yes objectname is vehicle name (chopper) but as mentioned before if placing a unit in editor with ful crew (not empty vehicle) then name is not correct i think.

try using

_vehicle = (vehicle (leader namefromEditor));

I confirm limitspeed works as i use it myself in another script.

but you need to have a short sleep like 0.1 having 1 will not work.

NOTE: limitspeed needs to be repeated very often to have an effect, thats why i used a spawn so it would run next to the org script not stopping it or slowing it down.

Edited by Demonized
added note to explain more.

Share this post


Link to post
Share on other sites

I tried it with placing the empty chopper (called test in this case) into the editor and then placing a pilot and a gunner and moving them into the respective slots in the chopper. I called the script with nul = [test] execVM "limitspeed.sqf" and it doesnt seem to work.

Is there any chance that placing the player as the gunner in the chopper would screw it up? (Ofcourse when doing this the chopper is circling a marker and not the player)

Edited by jkhaaja

Share this post


Link to post
Share on other sites

OK thanks I will check that out and see what I'm missing!

EDIT:

Yeah I got it to work! I think I had a problem with the variable name of the chopper in the script (didnt have the _vehicle, just had it as Objectname). Thanks for everyone who contributed to the topic. Here is the final codes to make a CAS chopper that circles around a player or marker or whatever.

cas.sqf

private ["_chopper", "_radius", "_angle"];

_chopper = _this select 0;

_radius = 1000;

_angle = 1;

while { alive _chopper } do

{

hint "moving to waypoint";

private ["_center", "_pos"];

_center = getMarkerPos "marker";

_pos = [_center, _radius, _angle] call BIS_fnc_relPos;

_chopper doMove _pos;

_chopper flyInHeight 200;

group _chopper setBehaviour "CARELESS";

group _chopper setCombatMode "BLUE";

_angle = _angle + 60;

waitUntil { !alive _chopper || _chopper distance _pos < 800};

};

The careless and blue modes are set so that the chopper will keep going in the circle even if it sees the enemy. This ofcourse requires a player gunner or the chopper will never fire.

The distance check 800 was for an apache moving at full speed. With the limitspeed a lower value should be ok, with full speed it required above 700 to get a smooth circle without stops.

and the limitspeed.sqf

_vehicle = _this select 0;

iAmStrafingNow = true;

[_vehicle] spawn {

_vehicle = _this select 0;

while {iAmStrafingNow} do {

// objectName limitSpeed speedInKm_hour;

_vehicle limitSpeed 60;

hint format["speed is %1",(speed _vehicle)];

sleep 0.1;

if (!iAmStrafingNow) then {

waitUntil {iAmStrafingNow};

};

};

};

Edited by jkhaaja

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  

×