Home   Help Search Login Register  

Author Topic: Getting a chopper to target and follow a Unit.  (Read 2829 times)

0 Members and 1 Guest are viewing this topic.

Olle Stolpe

  • Guest
Getting a chopper to target and follow a Unit.
« on: 26 Feb 2005, 22:46:19 »
When a trigger i started I want a chopper to start following a Unit (in this case p1)
But it won't work.
I tried this in script:

#loop
patrolchopper DoMove getpos p1
goto loop


But it only moves to the first position and stays there.. I tried

patrolchopper DoMove getpos p1
patrolchopper reveal p1


same result. The same when I tried

patrolchopper DoMove getpos p1
patrolchopper reveal p1
patrolchopper dotarget p1


I even tried

patrolchopper DoMove getpos p1
patrolchopper reveal p1
patrolchopper dotarget p1
patrolchopper dofollow p1
patrolchopper dofire


I aslo tried putting ~5 between every command.. nothing

It only works when I am in the middle of a field doing a jig with a big sign saying SHOOT ME!
Even if I use the command Reveal...

 ???


Help please...

Offline macguba

  • Former Staff
  • ****
    • macguba's operation flashpoint page
Re:Getting a chopper to target and follow a Unit.
« Reply #1 on: 26 Feb 2005, 22:57:30 »
Getting choppers to shoot at infantry is difficult.   Have a good hunt using the forum search function, this has come up before and I think somebody solved it.     It was probably reveal, doTarget, doFire.

doMove getPos loops can be temperamental.     The command gets issued too often and the game gets confused.     Keep the loop very slow, that should help.

doFollow only applies to units within the same group.
Plenty of reviewed ArmA missions for you to play

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:Getting a chopper to target and follow a Unit.
« Reply #2 on: 26 Feb 2005, 22:58:05 »
first off, the goto command needs inverted commas "".

secondly, put a pause in the loop there.

Code: [Select]
#loop
patrolchopper DoMove getpos p1
~10
goto "loop"

for one thing it will give the chopper time to decide where it's flying to, and more importantly it will stop flashpoint crashing. fast loops eat up processor power, and this particular loop doesn't need to be all that fast.


Olle Stolpe

  • Guest
Re:Getting a chopper to target and follow a Unit.
« Reply #3 on: 26 Feb 2005, 23:55:37 »
thanks.. it's solved.. But there is a new problem with getting a couple of variables to work...


_player = _this select 0
_markerpos = getpos chmark

#loop
?(not alive _player):goto "return"
patrolchopper DoMove getpos _player
~10
patrolchopper DoTarget _player
~10
goto"loop"

#return
patrolchopper DoMove getpos chmark
_chpos = getpos patrolchopper
?(_chpos == _markerpos):goto "land"
~10
goto "return"

#land
patrolchopper setbehaviour "SAFE"
patrolchopper Land "land"
exit


Works like a charm.. But then the line.

?(_chpos == _markerpos):goto "land"

Returns an error.. No matter how I try. I can't get the loop to break when the
chopper is at the same potition as the marker named chmark

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:Getting a chopper to target and follow a Unit.
« Reply #4 on: 27 Feb 2005, 00:05:50 »
it (almost) never will be. if you fire up notepad and take a look at the positions of any of the elements within the mission.sqm you'll see why -

Code: [Select]
class Item1
{
position[]={5360.383301,449.903229,10138.098633};
azimut=95.000000;
etc....

the chances of two separate positional arrays matching to 6 decimal places are about the same as me winning a lottery jackpot. slim.

one other point is that you don't use getpos with markers; it's getmarkerpos.

i would suggest using distance instead, thus:

Code: [Select]
?(_chpos distance _markerpos <=5):goto "land"
that's untested, so may not work.
« Last Edit: 27 Feb 2005, 00:08:39 by bedges »

Olle Stolpe

  • Guest
Re:Getting a chopper to target and follow a Unit.
« Reply #5 on: 27 Feb 2005, 00:30:46 »
Thanks.. But after doing this:

Code: [Select]
player = _this select 0
_markerpos = getmarkerpos "chmark"


#loop
?(not alive _player):goto "return"
patrolchopper DoMove getpos _player
~10
patrolchopper DoTarget _player
~10
goto"loop"

#return
patrolchopper DoMove _markpos
_chpos = getpos patrolchopper
?(_chpos distance _markerpos <=5):goto "land"
~10
goto "return"

#land
patrolchopper setbehaviour "SAFE"
patrolchopper Land "land"

exit

I still get an error on the line

Code: [Select]
?(_chpos distance _markerpos <=5):goto "land"
Somhow I can't get the chopperposition in the _chpos.. It always says "Error, Array expected Number" or something like that.
I can't use an eventhandler to put the chopperposition it he _chpos since I need to loop the check.

GRRR!! Help!
And thanks alot for yer help. Now the chopper returns to the markerpos.

Olle Stolpe

  • Guest
Re:Getting a chopper to target and follow a Unit.
« Reply #6 on: 27 Feb 2005, 00:39:43 »
I found it...
I need to put the objects, not the getpos-value of them in the distance thingy.
But still I cant get the chopper to land when it's stopped at the marker.

Olle Stolpe

  • Guest
Re:Getting a chopper to target and follow a Unit.
« Reply #7 on: 27 Feb 2005, 00:42:02 »
Is there another good way of ordering a chopper to land at a specific place?

Dubieman

  • Guest
Re:Getting a chopper to target and follow a Unit.
« Reply #8 on: 27 Feb 2005, 00:59:11 »
Not that it is much help, but I made a script that sort of does what you want with a small addon. Not very tidy, but it worked. :P
http://www.ofpec.com/editors/browse.php?browseon=&browsewhat=-1&catselected=-1_-1&catagory=-1&subcategory=-1_-1&numreturn=25&displayformat=0&ofpv=1&searchwhat=1&searchlevel=0&searchwhat=1&searchopts=&searchstring=gunship

Wow that was large... ::)

And to help choppers land quicker, try using an invisble "H" so they head towards that as their landing zone. ;)

Cut & paste the address if you're gonna look at it. The forum didn't like my link. :'( ;D
« Last Edit: 27 Feb 2005, 01:01:00 by GuiltyRoachKillar »

Olle Stolpe

  • Guest
Re:Getting a chopper to target and follow a Unit.
« Reply #9 on: 27 Feb 2005, 00:59:11 »
I now use Game Logic instead of a marker.. Works great apart from one stupid thing.

When the chopper lands it just lands, turns off the engine and then starts and holds
at about 35 meter above the ground... I WANT IT TO STAY DOWN!

Code: [Select]
_player = _this select 0
_markerpos = getpos chmark


#loop
?(not alive _player):goto "return"
patrolchopper DoMove getpos _player
~7
patrolchopper flyinheight 35
~2
patrolchopper DoTarget _player
~10
goto"loop"

#return
patrolchopper flyinheight 70
patrolchopper DoMove _markerpos
?(patrolchopper distance chmark <=100):goto "land"
~10
goto "return"

#land
titleText ["landing", "PLAIN"]
patrolchopper setbehaviour "SAFE"
patrolchopper Land "land"
exit

 


(chmark is Game Logic)

Offline Raptorsaurus

  • Editors Depot Staff
  • *****
Re:Getting a chopper to target and follow a Unit.
« Reply #10 on: 27 Feb 2005, 01:06:08 »
Olle Stolpe,

The distance command will not work for positions or markers, it only works for objects, so you have to put an object at at the marker "chmark" (use a game logic or something else invisible). Try adding this before your problem if-then statement:

Code: [Select]
_gl = "logic" createVehicle (getMarkerPos "chmark")
then change your your if-then statement to this:

Code: [Select]
?(patrolchopper distance _gl <=5):goto "land"
At the end of the script delete the game logic with:

Code: [Select]
deleteVehicle _gl
One other option is to use this function I made that finds the distance between an object and a marker (DisToMark.sqf).  The function is called thusly:

Code: [Select]
_dis = [_obj, _marker] call DisToMark
If you use this function then you need not create the camelogic, instead just change your if-then statement to:

Code: [Select]
?(([patrolchopper, "chmark"] call DisToMark) <=5):goto "land"
Of course this will also require putting this line at the begining of any script using this function or in the inti.sqs file in you mission folder:

Code: [Select]
DisToMark = preprocessFile "DisToMark.sqf"
The function is attached

Olle Stolpe

  • Guest
Re:Getting a chopper to target and follow a Unit.
« Reply #11 on: 27 Feb 2005, 01:13:41 »
Thank you so much.
But I already solved it. I used a Game Logic.

But why should I create the Game Locic in the script instead of putting it on the map in the
editor?

My problem now is that the chopper takes off directly after it has landed and stay hovering...
« Last Edit: 27 Feb 2005, 01:14:26 by Olle Stolpe »

Offline Raptorsaurus

  • Editors Depot Staff
  • *****
Re:Getting a chopper to target and follow a Unit.
« Reply #12 on: 27 Feb 2005, 01:17:47 »
You figured it out before I finished putting my post together.

I have a new script for making choppers land called fastland.sqs.  I have only used it in a few missions that I am working on and it needs some "tweaking" but feel free to "tweak" it as you see fit.  I am attaching that script.  The present version uses the call command so that you can initiate different script/actions when the chopper lands (like haveing troops get out or get in or have the crew all get out or whatever.  But the call command can be confusing to new scripters (I am asuming you are fairly new to scripting).  If you have any questions about using/modifiing this script feel free to PM me.  I was working on submitting it to the editor depot,  but I believe I must do more tweaking and testing first.  So, maybe you can help me beta test it by trying it in your mission and it may also help solve your chopper landing problems.

Olle Stolpe

  • Guest
Re:Getting a chopper to target and follow a Unit.
« Reply #13 on: 27 Feb 2005, 01:20:11 »
thanks alot!

Offline Raptorsaurus

  • Editors Depot Staff
  • *****
Re:Getting a chopper to target and follow a Unit.
« Reply #14 on: 27 Feb 2005, 01:21:34 »
You can put it on the map ahead of time, but if you create it in the script you have more freedom for naming it (and you can use a local variable name instead the global name of an editor made logic).  Also a script created logic will not be influenced by other script that are using logics.  If you have many scripts that need logics, it can be quite cumbersome to create all the logics on the map ahead of time.

Oh, one more thing.  It may be helpfull if you use invisible targets to track the unit.  Aircraft sometimes have problems tracking infantry ground units, but if you use the invisible tagets addon made by Lester you can make it easier for the chopper to "see" the ground unit.  Also, what kind of chopper are you using?  If it is one with a side gun you may have noticed that those have trouble targeting units because the pilot and side gunner do not have their differing directions well coordinated.  I have a script/demo mission called "sidegunner aid" that I am almost ready to post at the editor depot (I will have it ready by next weekend), so you may want to keep an eye out for that.
« Last Edit: 27 Feb 2005, 01:30:32 by Raptorsaurus »

Olle Stolpe

  • Guest
Re:Getting a chopper to target and follow a Unit.
« Reply #15 on: 27 Feb 2005, 01:24:05 »
Thanks again.. Now.
Here's my script:

Code: [Select]
_player = _this select 0
_logicpos = getpos chmark


#loop
?(not alive _player):goto "return"
patrolchopper DoMove getpos _player
~2
patrolchopper DoTarget _player
~5
goto"loop"

#return
patrolchopper flyinheight 70
patrolchopper DoMove _logicpos
?(patrolchopper distance chmark <=100):goto "land"
~10
goto "return"

#land
titleText ["landing", "PLAIN"]
patrolchopper setbehaviour "SAFE"
patrolchopper Land "land"
patrolchopper flyinheight 0
exit

 


Do you have any clue why my chopper takes off directly after landing, and then stays hovering.

Offline Raptorsaurus

  • Editors Depot Staff
  • *****
Re:Getting a chopper to target and follow a Unit.
« Reply #16 on: 27 Feb 2005, 01:45:05 »
Choppers do weird things sometimes.  You can make a mission and it works fine with the coppers landing/taking off ect. 20 times in a row, then suddenly when testing the mission the choppers stop landing where they are supposed to or they do weird stuff like hover.  That is why I made the fastland script.  The script just completely takes over the chopper when it gets close to the landing area.  No matter what the AI pilots want to do that script will setVelcity that chopper down to the exact landing spot within .5 meters!!!  Try it and if you have any problems let me know (use PM though since this thread is starting to go off topic).

Olle Stolpe

  • Guest
Re:Getting a chopper to target and follow a Unit.
« Reply #17 on: 27 Feb 2005, 01:55:59 »
Now it works..
Here's the script:

Code: [Select]
_player = _this select 0
_logicpos = getpos chmark


patrolchopper Reveal _player


#loop
   ?(not alive _player):goto "return"
   patrolchopper DoMove getpos _player
   ~2
   patrolchopper DoTarget _player
   ~5
   goto"loop"



#return
   patrolchopper flyinheight 70
   patrolchopper DoMove _logicpos
   ?(patrolchopper distance chmark <=100):goto "land"
   ~10
   goto "return"



#land
   patrolchopper Land "land"
   ~5
   
exit

 

Not bad for my very first mission uh?
Thank you so much for your help!
I'll probably need more help on this script as I go along.

For example, this is for a MP mission so I don't know I need to
use any  public variables...

Offline Raptorsaurus

  • Editors Depot Staff
  • *****
Re:Getting a chopper to target and follow a Unit.
« Reply #18 on: 27 Feb 2005, 02:11:22 »
Good job Olle!!! ;D

Hey if a problem is solved make sure you click on the "sloved" button (only administrators or the original poster can do that).