Home   Help Search Login Register  

Author Topic: Helo moves to random locations during flight  (Read 6427 times)

0 Members and 1 Guest are viewing this topic.

Offline trinec

  • Members
  • *
  • I'm a llama!
Helo moves to random locations during flight
« on: 11 Apr 2008, 03:38:09 »
Was wondering how to make a helo fly to random locations and activate another script that I have that makes the helicopter go down in flight.  So you really never know were your going to go down at.  I have some code to make the chopper wait at base until a whole group has boarded.


Thanks

GI-Trinec

Offline The-Architect

  • Former Staff
  • ****
  • Bite my shiny metal...
    • Bob's Un-official Flashpoint Page
Re: Helo moves to random locations during flight
« Reply #1 on: 11 Apr 2008, 04:36:22 »
You could have a series of game logis in places around the map. Then tell the chopper to randomly choose from one of them with a script.
Better still might be invisible helipads to aid the landing.

I know it's not really as random as you want it but it would work.
James Andrew Wilkinson 1977 - 2005 R.I.P.
"If it ain't the friggin' incoming it's the friggin' outgoing. Only difference is who gets the friggin' grease, and that ain't no friggin' difference at all."

Offline trinec

  • Members
  • *
  • I'm a llama!
Re: Helo moves to random locations during flight
« Reply #2 on: 11 Apr 2008, 04:59:39 »
ya I'm using this code in the init.sqf right now to have the helo wait for the group to join.

Code: [Select]
{_x assignAsCargo uh1} forEach units group gfldr;
units group gfldr orderGetIn true;
waitUntil {{_x in uh1} count units group gfldr == count units group gfldr};

I found this bit of code in the forums here but not sure how to make it work with the above.

Code: [Select]
[group pilots, 1] setWPPos getMarkerPos (["move_1", "move_2", "move_3", "move_4"] Select (floor(random 4)));
I tried putting the helo in the group pilots using
Code: [Select]
pilots = group this but it errors out must be object but if I use the helo's name it says it must be a group.  I created markers move_1 thru 4.



Offline Rommel92

  • Members
  • *
Re: Helo moves to random locations during flight
« Reply #3 on: 11 Apr 2008, 06:38:56 »
Don't use "group pilots", just use "pilots"

Code: [Select]

[pilots, 1] setWPPos getMarkerPos (["move_1", "move_2", "move_3", "move_4"] Select (floor(random 4)));


Offline Sparticus76

  • Members
  • *
Re: Helo moves to random locations during flight
« Reply #4 on: 12 Apr 2008, 04:26:39 »
what you could do is create an invisible H pad and chose a random location on the map that's terrain is checked as not being water or trees etc, setpos the H pad at that point and have the helo move to that point.

Offline trinec

  • Members
  • *
  • I'm a llama!
Re: Helo moves to random locations during flight
« Reply #5 on: 12 Apr 2008, 22:44:25 »
Not sure how to get this part to execute after the waitUntil code line

Code: [Select]
[pilots, 1] setWPPos getMarkerPos (["move_1", "move_2", "move_3", "move_4"] Select (floor(random 4)));
I figure it would be that you had to say something like if all units are aboard then run the above line of code.  I'm just not sure on how to do this.

Ok I have this figured out now basicly you have to create a waypoint for the helicopter in the script to get it to move after this line of code

Code: [Select]
waitUntil {{_x in uh1} count units group gfldr == count units group gfldr};

If you give the helicopter a waypoint in the editor it will start up and fly to a certain elevation then come back down.  Which I don't want. Thats why I created one in the script after the checking of the group boarding the helicopter.  I'm no scripting guru and it's probably better to create a different script file then using it in the init.sqf.  If anyone has a better way of starting this script at the start of the mission let me know. 

Here is the whole code

Code: [Select]
_uh1 = uh1;
_pilots = pilots;

{_x assignAsCargo uh1} forEach units group gfldr;
units group gfldr orderGetIn true;

waitUntil {{_x in uh1} count units group gfldr == count units group gfldr};

hint "all aboard";
_wp114 = _pilots addWaypoint [getMarkerPos "uh1pos", 0];
_wp114 setWaypointType "MOVE";
_wp114 setWayPointStatements ["true", "[pilots, 1] setWPPos getMarkerPos ([""move_1"", ""move_2"", ""move_3"", ""move_4""] Select (floor(random 4)));"];


Now if anyone has an idea on how to have a seperate script run randomly from the different areas on the map without them always being from the marker positions. Just randomly activates while the helicopter is flying betweens its random marker positions.

Thanks everyone for their help thus far.

GITrinec
« Last Edit: 13 Apr 2008, 02:01:22 by trinec »

Offline trinec

  • Members
  • *
  • I'm a llama!
Re: Helo moves to random locations during flight
« Reply #6 on: 13 Apr 2008, 19:54:53 »
Is there a way to get an array of already created in the editor marker positions that are part of the areas that the helo flys too and compare that with the helos position and if in a the markers position within a radius create a trigger that launches a script.  I know you can use createtrigger in a script to create the triggers.

GiTrinec

Offline Rommel92

  • Members
  • *
Re: Helo moves to random locations during flight
« Reply #7 on: 13 Apr 2008, 21:59:59 »
Code: [Select]
_uh1 = uh1;
_pilots = pilots;
_array = [""move_1"", ""move_2"", ""move_3"", ""move_4""];
_i = 0;

for [{_i=0}, {_i < count _array}, {_i=_i+1}] do
{
      If ((getPos _uh1) distance (_array select _i) > 200) then
      {
            //TRIGGER, SCRIPT, CODE Here
      };
};

Offline trinec

  • Members
  • *
  • I'm a llama!
Re: Helo moves to random locations during flight
« Reply #8 on: 14 Apr 2008, 00:07:43 »
When I run the mission it gives me error missing ] at line 3 which is the _array line.  Also does > 200  mean when the helo is greater then 200 meters away the script or trigger activates?

Thanks

Offline Rommel92

  • Members
  • *
Re: Helo moves to random locations during flight
« Reply #9 on: 14 Apr 2008, 01:05:31 »
Code: [Select]
If ((getPos _uh1) distance (getMarkerpos (_array select _i)) > 200) then
{
//TRIGGER, SCRIPT, CODE Here
};

That should fix it, sorry for the inconvience, forgot  ;).
Also try with non-double comma's if it still doesn't work.

Code: [Select]
_array = ["move_1", "move_2", "move_3", "move_4"];
« Last Edit: 14 Apr 2008, 01:07:48 by Rommel92 »

Offline trinec

  • Members
  • *
  • I'm a llama!
Re: Helo moves to random locations during flight
« Reply #10 on: 14 Apr 2008, 06:27:10 »
well basicly my helo flys to the points randomly as usual but nothing will activate inside the trigger, script, code area even just a hint "say anything"; doesnt activate.  Does >200 mean when uh1 is greater then 200 meters from the marker then activate?

If ((getPos _uh1) distance (getMarkerpos (_array select _i)) > 200) then
{
//TRIGGER, SCRIPT, CODE Here
hint "say anything";
};

Offline Rommel92

  • Members
  • *
Re: Helo moves to random locations during flight
« Reply #11 on: 14 Apr 2008, 07:18:58 »
Code: [Select]
If ((getPos _uh1) distance (getMarkerpos (_array select _i)) < 200) then
{
};
I used > to test if it would work on my PC originally, sorry my mistake for leaving it there.

If you could just use this and see what it returns, and perhaps debug it yourself:
Code: [Select]
hint format ["%1",(getPos _uh1) distance (getMarkerPos (_array select _i))];
Outside of the If statement, inside the For loop.

Offline trinec

  • Members
  • *
  • I'm a llama!
Re: Helo moves to random locations during flight
« Reply #12 on: 15 Apr 2008, 08:05:34 »
It seems that the If statement is not being evaluated inside the for loop the
Code: [Select]
hint "do something"; does not ever appear.  I do get the distance to the marker using the hint format command that you gave me using it outside of the if statement.

Thanks 

Offline Rommel92

  • Members
  • *
Re: Helo moves to random locations during flight
« Reply #13 on: 15 Apr 2008, 08:19:30 »
Code: [Select]
_uh1 = uh1;
_pilots = pilots;
_array = ["move_1", "move_2", "move_3", "move_4"];
_i = 0;

for [{_i=0}, {_i < count _array}, {_i=_i+1}] do
{
If ((getPos _uh1) distance (getMarkerpos (_array select _i)) < 200) then
{
hint format ["Near Marker: %1 (%2m)",_array select _i,(getPos _uh1) distance (getMarkerpos (_array select _i))];
}
else
{
hint format ["Marker: %1 (%2m) is to far away.",_array select _i,(getPos _uh1) distance (getMarkerpos (_array select _i))];
};
sleep 1.0;
};

Tested and works, don't know where your going wrong, heres my version if its necessary:
« Last Edit: 15 Apr 2008, 08:25:50 by Rommel92 »

Offline trinec

  • Members
  • *
  • I'm a llama!
Re: Helo moves to random locations during flight
« Reply #14 on: 17 Apr 2008, 05:29:39 »
It does appear to work from the radio call while I'm flying. but I can't seem to get it to work by adding the script into the init.sqf or even calling it from init.sqf using the call command.  It does run the script and tell me that the locations are too far away and the distance.  However when I get closer to the markers at < 200 the hint does not display saying that I am close enough.  It appears that the for statement runs once in the script and doesnt loop.    I wonder if the helo flying around on it's random markers positions is causing a problem for some reason.