Jump to content
Sign in to follow this  
theavonlady

createVehicle for a plane plus waypoints

Recommended Posts

For an SP mission, when a condition is true, I want to create an AI plane at a specific location, name it, have it start off flying at 3000 meters, set it to engage at will and assign to it seek and destroy waypoints.

All I need to know is how? rock.gif

Yes, I've searched but I'm only finding bits and pieces.

TIA. smile_o.gif

Share this post


Link to post
Share on other sites

hm AFAIK you can't dynamically create WPs

but you can do it like that:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_aPos = [1,2,3]

_aSpd = 400

_aDir = 0

_tPos1 = [1,2,3]

t1destroyed = false

_tPos2 = [1,2,3]

t2destroyed = false

_aVel = [sin(_aDir)*_aSpd, cos(_aDir)*_aSpd,0]

_plane = "A10" createVehicle _aPos

_plane engineOn true

_plane setDir _aDir

_plane setVelocity _aVel

while {(speed _plane)<_aSpd} do {_aVel=velocity _plane; _plane setVelocity [1.05*_aVel select 0, 1.05*_aVel select 1, 0]}

_plane setBehaviour "Combat"

_plane setCombatMode "RED"

;; WP 1 ---------------------

_plane doMove _tPos1

#wait1

~0.5

?! (t1destroyed) : goto "wait1"

;; WP 2 ---------------------

_plane doMove _tPos2

#wait2

~0.5

?! (t2destroyed) : goto "wait2"

That's just a simple example for how to do the whole thing with two waypoints. Of course you have to change the position arrays in the beginning of the script. You can also include dynamically moving of the waypoint positions, maybe also moving of a preset trigger for the conditions.

Note that the boolean t1destroyed has to be true to let the plane move on to the next waypoint.

Edit: changed a bit of the script

Share this post


Link to post
Share on other sites

Thanks, Hardrock. Some fine tuning help needed:

Can I set initial position by a marker?

How do I set the plane's initial height in this script?

Can I set doMove position to the current location of an enemy aircraft or is there a simpler method to instruct the created plane to attack the enemy aircraft?

Share this post


Link to post
Share on other sites

1) Change _apos to <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_apos = getmarkerpos "markername"

2)In this script change the initial height by changing the last entry in _apos (3), if you already changed that to getmarkerpos "markername", then use this line of code<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_apos = [getmarkerpos "markername" select 0,getmarkerpos "markername" select 1, (your height here)]

3) Not really, just use _plane domove (getpos enemyplane), and _plane dotarget enemyplane and he should engage

Share this post


Link to post
Share on other sites

What's wrong with the following? The plane is starting off at ground level, when I want it to start at 3000 meters. rock.gif

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_apos = [getmarkerpos "a10start" select 0,getmarkerpos "a10start" select 1, 3000]

_aSpd = 600

_aDir = 220

_aVel = [sin(_aDir)*_aSpd, cos(_aDir)*_aSpd,0]

_plane = "A10" createVehicle _aPos

_plane engineOn true

_plane setDir _aDir

_plane setVelocity _aVel

while {(speed _plane)<_aSpd} do {_aVel=velocity _plane; _plane setVelocity [1.05*_aVel select 0, 1.05*_aVel select 1, 0]}

_plane setBehaviour "Combat"

_plane setCombatMode "RED"

#targeth1

? not (canMove h1) : goto "targeth2"

_plane domove (getpos h1)

_plane dotarget h1

~2

goto "targeth1"

#targeth2

? not (canMove h2) : goto "exit"

_plane domove (getpos h2)

_plane dotarget h2

~2

goto "targeth2"

#exit

exit

Share this post


Link to post
Share on other sites

since resistance you can't beam things... or something similar. i can't remember exactly. try this:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_plane = "A10" createVehicle [0,0]; _plane setPos _aPosif that does not work try with setVelocity:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_plane setVelocity [x,y,z](speed vector in m/s)

Share this post


Link to post
Share on other sites
try this:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_plane = "A10" createVehicle [0,0]; _plane setPos _aPos

Looks like either nothing was created or it died on mission start. Nothing showed up on an armor unit's radar HUD.

Quote[/b] ]if that does not work try with setVelocity:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_plane setVelocity [x,y,z]
(speed vector in m/s)

HELP! What am I supposed to code for x,y,z? rock.gif

Share this post


Link to post
Share on other sites

tested a bit, this should be enough. change<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_plane = "A10" createVehicle _aPosto<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_plane = "A10" createVehicle [0,0]; _plane setPos _aPosworks here.

Share this post


Link to post
Share on other sites
tested a bit, this should be enough. change<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_plane = "A10" createVehicle _aPos
to<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_plane = "A10" createVehicle [0,0]; _plane setPos _aPosworks here.

I tried this again, with the following script:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_apos = [getmarkerpos "a10start" select 0,getmarkerpos "a10start" select 1, 3000]

_aSpd = 600

_aDir = 220

_aVel = [sin(_aDir)*_aSpd, cos(_aDir)*_aSpd,0]

_plane = "A10" createVehicle [0,0]; _plane setPos _aPos

_plane engineOn true

_plane setDir _aDir

_plane setVelocity _aVel

while {(speed _plane)<_aSpd} do {_aVel=velocity _plane; _plane setVelocity [1.05*_aVel select 0, 1.05*_aVel select 1, 0]}

_plane setBehaviour "Combat"

_plane setCombatMode "RED"

#targeth1

? not (canMove hog1) : goto "targeth2"

_plane domove (getpos hog1)

_plane dotarget hog1

~2

goto "targeth1"

#targeth2

? not (canMove hog2) : goto "exit"

_plane domove (getpos hog2)

_plane dotarget hog2

~2

goto "targeth2"

#exit

exit

What's happening is about 10-15 seconds after the mission starts, I hear the A10's engines somewhere up and out there. Then, after another 5-7 seconds there's no engine noise, followed by a crash sound.

I cannot figure out where the A10 is crashing or why. Help again?! sad_o.gif

Are you using the exact same script as I am, above, or slightly different? rock.gif

Share this post


Link to post
Share on other sites

For the record, I also tried setting local variable _aPos like this:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_apos = [getmarkerpos "a10start" select 0,getmarkerpos "Bandit" select 1,(getmarkerpos "a10start" select 2) + 3000]

Same or similar result. sad_o.gif

My test mission consists of one enemy piece of armor name H1, myself as a soldier nearby and a marker named a10start.

This is on the desert island, with the marker NE of the armor. Very simple.

I switched myself as a player in a flying A10 and I was able to spot the created A10's green HUD indicator way out at sea to the S - SW, before the indicator turned white, as a result of the created A10 being in the water or crashing into it very shortly after being created.

It's as if it's being created in the wrong location and height. rock.gif

UPDATE: I made another change, along with the above line:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_plane = "A10" createVehicle _aPos

This at least appears to get the plane created at the right A and B axis locations except that:

1. It's on the ground

2. There's no pilot! crazy_o.gif

EDIT: No wonder there's no pilot! The ComRef editing doc says about createVehicle

Quote[/b] ]Description:

Create empty vehicle of given type.

So, Raedor, just how did you get this script to work? rock.gif

HELP!

Share this post


Link to post
Share on other sites

Well I think you need to put a pilot on the map then

put "Pilot moveindriver avon-a10" in the script and it

will work? rock.gif As it should move the driver in the a10.

Provided the A10 has the name "avon-a10".

*edit* and provided the pilot is named pilot.

*edit* Is it organic Green tea? smile_o.gif

Share this post


Link to post
Share on other sites
Well I think you need to put a pilot on the map then

put "Pilot moveindriver avon-a10" in the script and it

will work? rock.gif As it should move the driver in the a10.

Provided the A10 has the name "avon-a10".

*edit* and provided the pilot is named pilot.

I tried the following script, with your suggestions highlighted in red. Still no pilot in the cockpit.

Quote[/b] ]_apos = [getmarkerpos "a10start" select 0,getmarkerpos "a10start" select 1,(getmarkerpos "a10start" select 2) + 3000]

_aSpd = 600

_aDir = 220

_aVel = [sin(_aDir)*_aSpd, cos(_aDir)*_aSpd,0]

<span style='color:red'>_pilot = "SoldierWPilot" createUnit [_aPos,groupAlpha,"",1]</span>

_plane = "A10" createVehicle _aPos

<span style='color:red'>_pilot moveindriver _plane</span>

_plane engineOn true

_plane setDir _aDir

_plane setVelocity _aVel

while {(speed _plane)<_aSpd} do {_aVel=velocity _plane; _plane setVelocity [1.05*_aVel select 0, 1.05*_aVel select 1, 0]}

_plane setBehaviour "Combat"

_plane setCombatMode "RED"

#targeth1

? not (canMove hog1) : goto "targeth2"

_plane domove (getpos hog1)

_plane dotarget hog1

~2

goto "targeth1"

#targeth2

? not (canMove hog2) : goto "exit"

_plane domove (getpos hog2)

_plane dotarget hog2

~2

goto "targeth2"

#exit

exit

Something wrong with my moveInDriver statement? rock.gif

Share this post


Link to post
Share on other sites
<span style='color:red'>_pilot = "SoldierWPilot" createUnit [_aPos,groupAlpha,"",1]</span>

I even tried:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_pilot = "SoldierWPilot" createUnit [_getmarkerpos "a10start",groupAlpha,"",1]

But no pilot was created at that position and none was in the created A10 cockpit.

Share this post


Link to post
Share on other sites

To give waypoints to a camcreated unit I've always used the following.

Add a unit and give it all the waypoints etc you want, then in it's init you put...

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">group1 = group this; deletevehicle this

Then when you camcreate the unit <unit1> you also use the code

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">[unit1] join group1

When you delete the unit in the first section of code his waypoints remain... once you join the aircraft/pilot to that group it inherits all the waypoints.

Hope that helps/works ??

Share this post


Link to post
Share on other sites

That's a good idea for coding waypoints. Thanks. I just saw that mentioned elsewhere, in Doolittle's AI Vehicle Respawn.

However, my major problem right now in this script is getting the createUnit pilot to even show up in the mission. Here's my current script:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_apos = [getmarkerpos "a10start" select 0,getmarkerpos "a10start" select 1,(getmarkerpos "a10start" select 2) + 3000]

_aSpd = 600

_aDir = 220

_aVel = [sin(_aDir)*_aSpd, cos(_aDir)*_aSpd,0]

vpilot = []

"SoldierWPilot" createUnit [getmarkerpos "a10start",groupAlpha,"vpilot=this",1]

_plane = "A10" createVehicle _aPos

vpilot moveInDriver _plane

_plane engineOn true

_plane setDir _aDir

_plane setVelocity _aVel

while {(speed _plane)<_aSpd} do {_aVel=velocity _plane; _plane setVelocity [1.05*_aVel select 0, 1.05*_aVel select 1, 0]}

_plane setBehaviour "Combat"

_plane setCombatMode "RED"

#targeth1

? not (canMove h1) : goto "targeth2"

_plane domove (getpos h1)

_plane dotarget h1

~2

goto "targeth1"

#targeth2

? not (canMove h2) : goto "exit"

_plane domove (getpos h2)

_plane dotarget h2

~2

goto "targeth2"

#exit

exit

I used a global variable, vpilot, to define the pilot and try to move him into the plane. This is based on what Doolittle wrote in his script document:

Quote[/b] ]Of technical note, I just wanted to point out createUnit does not return an object to reference (!) which is too bad. To get around this, I am using the global variable Soldier in the Init to "remember" which unit was created (it's object assignment) so that I can do stuff with the new unit.

Yet, as I said, the pilot unit is nowhere to be seen. sad_o.gif

Share this post


Link to post
Share on other sites

I think you have to place on on the map some place out the way and in his name field put "Pilot" and then some how the

A10 that spawns needs to have a "Name field" Specified...

Otherwise he won't get in even if he appears.

Duno how I can explain it. Like if you put a empty a10 on a

blank map and leave the name field blank the man can't

be put into it because it has no designated name.

I think thats whats going on with the script.

Is it possible to put a a10 out of the way and just

telaport it to the marker and height you need it at?

Share this post


Link to post
Share on other sites
I think you have to place on on the map some place out the way and in his name field put "Pilot" and then some how the

A10 that spawns needs to have a "Name field" Specified...

Otherwise he won't get in even if he appears.

Duno how I can explain it. Like if you put a empty a10 on a

blank map and leave the name field blank the man can't

be put into it because it has no designated name.

I think thats whats going on with the script.

Is it possible to put a a10 out of the way and just

telaport it to the marker and height you need it at?

First, an initial comment: no matter what, something is really wrong with the script as the pilot from the CreateUnit command is simply not to be found in the mission. The CreateUnit command in the script should be working no matter what.

Second, I would much prefer that the plane and pilot are not predefined on the map. However, I'll test this out now anyway and see if it works.

EDIT: this script works if I predefine the plane and pilot in the mission:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_apos = [getmarkerpos "VplaneStart" select 0,getmarkerpos "VplaneStart" select 1,(getmarkerpos "VplaneStart" select 2) + 1000]

_aSpd = 600

_aDir = 220

_aVel = [sin(_aDir)*_aSpd, cos(_aDir)*_aSpd,0]

vplane setPos _apos

vpilot moveInDriver vplane

vplane engineOn true

vplane setDir _aDir

vplane setVelocity _aVel

while {(speed vplane)<_aSpd} do {_aVel=velocity vplane; vplane setVelocity [1.05*_aVel select 0, 1.05*_aVel select 1, 0]}

vplane setBehaviour "Combat"

vplane setCombatMode "RED"

#targeth1

? not (canMove h1) : goto "targeth2"

vplane domove (getpos h1)

vplane dotarget h1

vplane dofire h1

~2

goto "targeth1"

#targeth2

? not (canMove h2) : goto "exit"

vplane domove (getpos h2)

vplane dotarget h2

vplane dofire h2

~2

goto "targeth2"

#exit

exit

But I still want to understand why my original spawn script's CreateUnit command is not working. rock.gif

EDIT: Added doFire commands to script.

Share this post


Link to post
Share on other sites
EDIT: No wonder there's no pilot! The ComRef editing doc says about createVehicle
Quote[/b] ]Description:

Create empty vehicle of given type.

So, Raedor, just how did you get this script to work? rock.gif

HELP!

i tried it not long enough it seems.

when you createUnit someone he has to be created in an existing group.

Share this post


Link to post
Share on other sites
Guest [B.B.S.] T_D

Is the groupAlpha present on the map? because you need an existing group on the map in which you can create the pilot. you can also take a unit instead of a group. After the createunit command you should write "[vpilot] join grpnull" to get him out of the group.

EDIT

raedor was a bit faster wow_o.gif

Share this post


Link to post
Share on other sites
T_D @ Sep. 26 2004,15:18)]Is the groupAlpha present on the map? because you need an existing group on the map in which you can create the pilot. you can also take a unit instead of a group. After the createunit command you should write "[vpilot] join grpnull" to get him out of the group.

seconds too late... tounge_o.gif

Share this post


Link to post
Share on other sites
Guest [B.B.S.] T_D

i had more to write tounge_o.gif

And i need longer for my english sad_o.gif

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  

×