Jump to content
Sign in to follow this  
Koga1211

Air Plane Spawn height?

Recommended Posts

Hey, quick question, and I apologize if its stupidly simple, I'm still fairly new to scripting this game.

How would I set the height of a jet thats set to be "Flying" at the start of the game? The thing is, while the AI doesn't usually have a problem, when I try to play those kinds of maps with friends we seem to end up crashing right after the map loads. It seems to enjoy putting us at 100 feet above the ground/sea.

So basically, is there a way, through the init area of the unit, to set the altitude? I tried Flyinheight, but that didn't work. The only thing I can think of is maybe SetPos? Problem is I'm not really sure how to use that parameter so I can't test it.

Any one know of a way?

Thanks for your time.

Share this post


Link to post
Share on other sites

I can think of a few ways to go about it.

One is to use the full version of createVehicle, which requires the x-y-z of the vehicle you're spawning:

_newVeh = createVehicle [_aircraftName, [_posx, _posy, _posz], [], 0, _special];

where _aircraftName is of course what you want to spawn, then the 3 map positions (note that _posz is your altitude that you are asking about), and _special would be "FLY" for aircraft.

http://community.bistudio.com/wiki/createVehicle_array

You can certainly use the shorter non-array version of createVehicle. Let's say you want to spawn on a marker called "startHere":

_pos = getMarkerPos "startHere";
"_aircraftName" createVehicle [(_pos select 0),(_pos select 1),500];

I did not test that, but I think it will spawn at 500 meters on top of the marker.

Share this post


Link to post
Share on other sites

So with either version, how would I go about doing that? I use a marker or? In otherwords, where do I place the code?

Appreciate both your posts!

Thanks again!

Edited by Koga1211

Share this post


Link to post
Share on other sites

You would run them in a script, my dear, such as the init.sqf, which runs at the start of mission.

Or, if you wanted them to be run later in the mission, you would have, for example:

- The code above in a script - "AircraftCreate.sqf"

And in a trigger, "xhandler = []execVM "AircraftCreate.sqf";"

Does this answer your question?

Share this post


Link to post
Share on other sites

Be careful about altitude. The following does not seem to work, not anymore anyways:

this flyInHeight 1000; this setPos [getPos this select 0, getPos this select 1, 1000]; 0 = [this] spawn {sleep 60; _p = group vehicle (_this select 0); {(waypoints _p select _forEachIndex) setWPPos [waypointPosition (waypoints _p select _forEachIndex) select 0, waypointPosition (waypoints _p select _forEachIndex) select 1, 1000]} forEach (waypoints _p); for "_i" from 0 to count waypoints _p - 1 do {player globalChat format ["WP%1: %2",_i,getWPPos [_p,_i]]; sleep 1}}

Be grouped to the chopper, and set yourself to "In Cargo". Then apply the code above to the chopper (use init field). You should see what goes on. You'll start at 1000m, and continue at 1000m, but waypoints are on ground. After one minute waypoints are moved to 1000m altitude, meaning they should be easier to complete (make a waypoint cycle where waypoints are always shown, and you'll get a cross on completed waypoints on the map).

My chopper will start flying in circles, not knowing what to do. Once the waypoints are lifted by 1000m, this will show correctly in the hud, but, as you can see from the readouts, the internal waypoints are still at ground level. Sometimes it will fly in circles for a long time before actually heading toward the waypoint, sometimes it starts immediately, sometimes it will never "complete" the waypoint, and sometime a "complete" waypoint does not seem to activate the next. So wtf is going on?

Edited by CarlGustaffa

Share this post


Link to post
Share on other sites

That's interesting. I set a group of 3 choppers flying in formation at 1000 meters height. When they got to the first waypoint, they circled around in chaos, eventually one of them bumped my tail rotor and broke it, the jerk.

Share this post


Link to post
Share on other sites

Carl, you can confirm the setpos getpos array doesn't work? I noticed that the other day, but thought I was doing something wrong, i.e:

this setpos [(getpos this select 0),(getpos this select 1),500];

This no longer works?

Share this post


Link to post
Share on other sites

That part works for me. It's the progression of waypoints that are wacky. The waypoint seen on screen does not match the waypoint list, when you read the height of them.

Share this post


Link to post
Share on other sites

I appreciate all the replies. Waypoints are not an issue at this time, the issue had to do with jumping into jets midflight on MP missions with a mate, it starts you off at a low ALT and by the time its done receiving, one or both of us crash into the ground by the time we get control. I finally managed to solve this problem by using

this setpos [getpos this select 0, getpos this select 1,(getpos this select 2) +5000];

This seems to start us out at around 5000 ALT without fail, so no more lame crashes. I'm not sure I need that "(getpos this select 2)" but it was in the code I copied from somewhere else, so I left it there lol.

I may eventually need to figure out the waypoint portion, so the replies related to that are still helpful.

Thanks again all, the posts helped me figure it out either way :)

That's interesting. I set a group of 3 choppers flying in formation at 1000 meters height. When they got to the first waypoint, they circled around in chaos, eventually one of them bumped my tail rotor and broke it, the jerk.

Nice. I'm sure I'll just happen to run into this problem my self, on some of my other projects. At least I'll get to laugh at a problem for a change.

EDIT: Also, about spawning them via init.sqf, thanks for clarifying this. At the moment my skills with creating init.sqf's are limited at best, but more importantly, I'm using lots of custom units/vehicles, and while I've been able to find some of their class names, the majority have been, so far, impossible to find. So that makes any tricks like that a bit difficult.

Edited by Koga1211

Share this post


Link to post
Share on other sites

Ouch! I fear though that that is not a good solution, where i.e. just a slower connect or start will still be able to cause problems. I would have spawned the vehicle with engines running and some forward motion, on command instead, via a signal when both are ready. Not something I have ever tried, but that would be my angle.

Share this post


Link to post
Share on other sites

You're right, the getpos select 2 is not necessary, that just adds 5000m altitude to the default, presumably 100, so 5100. Nothing wrong with it either ;) especially if you wanted to spawn over mountains. In that case I might use getposatl / setposatl, which ensures height is added based on terrain height.

Carl raises a good point. In fact, when I spawn AI jets, I give them some speed because otherwise the jets tend to spin around or crash within the first few seconds. You could do this:

_heading = 0;   // whatever direction you want to start going
_speed = 150;  // this is usually sufficient, don't want it too high
_velx = (sin _heading * _speed);
_vely = (cos _heading * _speed);
_velz = 0;	// could try a positive value here for a rate of climb

_newVeh = createVehicle [_vehicle, [_posx, _posy, _posz], [], 0, _special];  // as from my first post
_newVeh setDir _heading;
_newVeh setVelocity [_velx, _vely, _velz];

No guarantees of course, since with server lag and whatnot, you may still crash as Carl mentioned. I lack MP experience, so I'm not sure how to sync the planes up.

Edited by AZCoder

Share this post


Link to post
Share on other sites

Right. Well this is working for me for now, the mission is just two planes, basically a 1 vs 1 dogfight. I'll be doing more complex setups with jets and choppers for other missions though, so this is all good stuff.

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  

×