Home   Help Search Login Register  

Author Topic: Need help scripting helicopter DoMove's over 3000m?  (Read 2213 times)

0 Members and 1 Guest are viewing this topic.

Offline harold5187

  • Members
  • *
Need help scripting helicopter DoMove's over 3000m?
« on: 29 Mar 2012, 01:26:32 »
Question

I know how to create a local marker, at a
given _pos.  But I do not know how to define
_pos.  This is what I need...

.sqs format only.
(1) check if (_Heli distance _Obj1) > 3000
(2)   if true, create a local marker 2,500m from the current pos of _Heli towards _Obj1
(3)   _pos = getmarkerpos (local marker)
(4)   #SrtLoop _Heli domove _pos; (_Heli distance (local marker) < 200)
(5)   if true, delete local marker and perform steps (1) through (4)

To create a localmarker here is the code...

Code: [Select]
  deleteMarkerLocal "Wpt";
  createMarkerLocal ["Wpt",_pos];
  "Wpt" setMarkerShapeLocal "ICON";
  "Wpt" setMarkerColorLocal "ColorGreen";
  "Wpt" setMarkerTypeLocal "DOT";
  "Wpt" setMarkerSizeLocal[0.5,0.5];
  "Wpt" setMarkerTextLocal "Wpt";

Program execution will not exit #StepLoop until _Heli distance _Obj1 < 3000

Code fragment of E1EvacRTB.sqs
;Execute StepLoop until distance to _Obj1 < 3000

#StepLoop


  ;Need code here to cause _Heli to fly towards _Obj1
  ;until condition is met, at which time the rest of
  ;the script will take charge to ensure _Heli lands
  ;at base.


  ;Error checking routine has already been added along
  ;with exit-loop conditions.
  ? ((!(_Pilot in _Heli))||(!(alive _Heli))||(!(alive _Pilot))||(!(canmove _Heli))): goto "Cont";
  Hint Format["Dist > %1 ETA %2",_CDist,(_Heli distance _Obj1)];
  ? ((_Heli distance _Obj1) < 3000): goto "Restart1";

goto "StepLoop";

E1EvacRTB.sqs
Code: [Select]
Private ["_Unit","_Heli","_Pilot","_Mkr1","_Mkr2","_Obj1","_Obj2","_CFlyIn","_CSpeed","_CDist"];

_Unit = _this select 1;
_Heli = _this select 0;
_Pilot= driver _Heli;

;"E1LZMkr"
_Mkr1 = (_this select 3) select 0;
;"E1EvacRTB"
_Mkr2 = (_this select 3) select 1;
;E1LZ
_Obj1 = (_this select 3) select 2;
;E1AirLnd
_Obj2 = (_this select 3) select 3;

_CFlyIn   = 150;
_CSpeed   = "NORMAL";
_CDist    = 2000;
_CDistFlg = 0;

titleText[">>> Order confirmed!  Chopper RTB! <<<", "PLAIN DOWN"];

#RestartErr2
_Mkr1 setmarkerpos getmarkerpos _Mkr2;
_Obj1 setdir getdir _Obj2;
_Obj1 setpos getmarkerpos _Mkr1;

~2

;Skip StepLoop if destination between _Heli and _Obj1 < 3000 initially
? ((_Heli distance _Obj1)<3000): goto "Restart1";

;Execute StepLoop until distance to _Obj1 < 3000
#StepLoop
  ;Need code here to cause _Heli to fly towards _Obj1
  ;until condition is met, at which time the rest of
  ;the script will take charge to ensure _Heli lands
  ;at base.
 

  ;Error checking routine has already been added along
  ;with exit-loop conditions.
  ? ((!(_Pilot in _Heli))||(!(alive _Heli))||(!(alive _Pilot))||(!(canmove _Heli))): goto "Cont";
  Hint Format["Dist > %1 ETA %2",_CDist,(_Heli distance _Obj1)];
  ? ((_Heli distance _Obj1) < 3000): goto "Restart1";
goto "StepLoop";

#Restart1
_Heli flyinheight _CFlyIn;
_Pilot setspeedmode _CSpeed;

? (_CDistFlg == 0): _Heli doMove (position _Obj1);
? (_CDistFlg == 1): _Heli Land "Get Out";
? (_CDistFlg == 2): _Heli Land "LAND";

? ((!(_Pilot in _Heli))||(!(alive _Heli))||(!(alive _Pilot))||(!(canmove _Heli))): goto "Cont";
Hint Format["Dist > %1 ETA %2",_CDist,(_Heli distance _Obj1)];
? ((_Heli distance _Obj1) > _CDist): goto "Restart1";
? (_CDist == 2000): goto "CDistRtn1";
? (_CDist == 1000): goto "CDistRtn2";
? (_CDist ==  600): goto "CDistRtn3";
? (_CDist ==  300): goto "CDistRtn4";
? (_CDist ==  150): goto "CDistRtn5";
? (_CDist ==   25): goto "CDistRtn6";

_Pilot action ["EngineOff",(vehicle _Pilot)];
 
Hint "Landed!";
goto "ContEnd";

#Cont
? ((!(alive _Heli))||(!(alive _Pilot))): goto "ContErr1";
? (((alive _Pilot)&&(_Pilot in _Heli))&&(!(canmove _Heli))): goto "ContErr2";
? ((!(alive _Pilot))&&(canmove _Heli)||(!(canmove _Heli))): goto "ContErr3";
? (!(_Pilot in _Heli)): goto "ContErr4";
goto "ContEnd";

#ContErr1
  Hint "RTB Failure: Chopper and crew destroyed!";
goto "ContEnd";

#ContErr2
  _Heli setdammage 0;
  _Heli setfuel 1;

  Hint "RTB Warning: Making repairs and attempting to continue mission!";
goto "RestartErr2";

#ContErr3
  Hint "RTB Failure: Pilot Killed!  Destroying chopper (10 Secs)!";
  ~10
  _Heli Setdammage 1;
goto "ContEnd";

#ContErr4
  Hint "MAYDAY!!!  MAYDAY!!!  Going Down!  I'm bailing and need rescue!";
goto "ContEnd";

#CDistRtn1
  _CDist  = 2000;
  _CFlyIn = 150;
  _CSpeed = "NORMAL";
goto "Restart1";
#CDistRtn2
  _CDist  = 1000;
  _CFlyIn = 105;
  _CSpeed = "LIMITED";
goto "Restart1";
#CDistRtn3
  _CDist  = 600;
  _CFlyIn = 90;
  _CSpeed = "LIMITED";
goto "Restart1";
#CDistRtn4
  _CDist  = 300;
  _CFlyIn = 70;
  _CSpeed = "LIMITED";
goto "Restart1";
#CDistRtn5
  _CDist    = 150;
  ;_CFlyIn   = 25;
  _CSpeed   = "LIMITED";
  _CDistFlg = 1; 
goto "Restart1";
#CDistRtn6
  _CDist    = 25;
  _CFlyIn   = 15;
  _CSpeed   = "LIMITED";
  _CDistFlg = 0; 
goto "Restart1";
#CDistRtn7
  _CDist    = 15;
  ;_CFlyIn   = 15;
  _CSpeed   = "LIMITED";
  _CDistFlg = 2; 
goto "Restart1";

#ContEnd

exit


Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re: Need help scripting helicopter DoMove's over 3000m?
« Reply #1 on: 30 Mar 2012, 09:51:34 »
I moved this here as it looks more like a scripting problem, and sqs says "OFP" to me.

Secondly, while I understand the satisfaction one can get from scripting something yourself, this problem has already been solved by Mandoble, for OFP, ArmA and for Arma2.

Reinventing the wheel can be fun, but it does waste a lot of time.  :good:

Offline harold5187

  • Members
  • *
Re: Need help scripting helicopter DoMove's over 3000m?
« Reply #2 on: 30 Mar 2012, 17:28:55 »
Hi, sorry if I put it in the wrong place...  But, Arma 1 does support .sqs, and I no longer have Operation Flashpoint installed.  This was part of a project created for Arma, using Arma, and while I am slowly in the process of converting as much of my sqs into sqf format, I havn't quite reached a level of expertise, such as
Mando...  In fact, I've been trying to contact him, regarding his solution, but I fear I may not hear from
him, and I must come up with whatever workaround I can.  His work is awesome, but he doesn't really
explain much in terms of how to break down is SOLUTION so that it can be used by people such as myself
looking for answers to old problems.

This code is not a port from Flashpoint either.

  :yes: :dunno:

Offline savedbygrace

  • Intel Depot
  • Administrator
  • *****
  • Be swift to hear...slow to speak...slow to wrath.
Re: Need help scripting helicopter DoMove's over 3000m?
« Reply #3 on: 14 Sep 2012, 15:56:16 »
What exactly is the problem? Your thread title fails to indicate whether you are submitting a resource or asking a question?

Is it just one question?
Quote
But I do not know how to define
_pos.

Or are there other concerns?
To grab the coordinates of a position, use the getpos command with the global variable(name) of the marker or object. Or just execute a distance check on that variable. It doesn't matter if the variable is local or global, so long as you access it correctly.

If this is a CAS script, a startpos marker(or even assigning a local variable to the starting pos of the helo within your looping script will identify the RTB pos. You can then use onmapsingleclick for player interaction with the helo, or player pos, or waypoint pos, or create a new waypoint for the unit and helo and synch them.

To have that helo move toward the object/marker/player, use distance checks with domove getpos or move newpos(newpos = predefined coordinates). You can also use object id's nearest the pos to perform distance checks. The simplest way is to insert a game logig or marker and have the helo continually move to that object. Just setpos the object wherever you need it.

Sorry if this is not helpful