Jump to content
Sign in to follow this  
LSHD

CreateVehicle & CreateUnit issues

Recommended Posts

Hello all,

Before you all are tempted to use your noobhammer on me, just bare with me here. Afterall, I'm just fairly new to all this as compared to you gurus.

What I am after is a random spawn of a UH60 model (UH60M_EP1) with a pilot (US_Soldier_Pilot_EP1")that is attached to it (not necessarily in it).

I have played around with either lines of the code but I can't seem to group them to spawn at the random "marker" positions together.

Also, as I have stated. It's either the soldier or the UH60 model only. Not both, which I'd like to see.

Here is the brain busting code I used.

//Random Spawn Script ;

//UH60 and Pilot;

// []execVM "UH60.sqf";

if (! isServer) exitwith {};

_veh = createVehicle ["UH60M_EP1",getMarkerPos "marker1",["marker2","marker3","marker4","marker5","marker6"], 0, "NONE"];

_pilot = createUnit ["US_Soldier_Pilot_EP1",getMarkerPos "marker1",["marker2","marker3","marker4","marker5","marker6"], 0, "FORM"];

Any help would be greatly appreciated.

---------- Post added at 06:23 AM ---------- Previous post was at 06:20 AM ----------

Failing that, I can't seem to figure out a way to name the spawned UH60.

So if destroyed a trigger can detect it. Effectively, completing a task.

Share this post


Link to post
Share on other sites

You could simply place the UH-60 on the map in one possible location. Then place markers in the other possible locations. Then group the markers to the helo. When the game starts the helo will be in it's original location or one of the marker locations.

That way since it's on the map you can give it a name and use it in triggers just fine.

Share this post


Link to post
Share on other sites

Here's the code version.

In your code they won't spawn at the same marker because each marker is chosen separately!

This is not tested but should work.

Name the vehicle like this... give it a Global name.

[b]myChopper[/b] = createVehicle ["UH60M_EP1",getMarkerPos "marker1",["marker2","marker3","marker4","marker5","marker6"], 0, "NONE"];

Then create the driver anywhere ("marker1") and move him to the chopper's position plus a few metres... You need to create his group as well.

_squad = createGroup WEST;
_pilot = createUnit ["US_Soldier_Pilot_EP1",getMarkerPos "marker1",_squad];
_pilot setpos [((getpos myChopper) select 0) + 5,((getpos myChopper) select 1) + 5,0];

....or create the driver anywhere ("marker1") and move him in to the helo....

_squad = createGroup WEST;
_pilot = createUnit ["US_Soldier_Pilot_EP1",getMarkerPos "marker1",_squad];
_pilot assignAsDriver [b]myChopper[/b];
_pilot moveInDriver [b]myChopper[/b];

You should be able to refer to myChopper from anywhere.

Hope it works...and helps.

Edited by twirly
Fixed an error in the code

Share this post


Link to post
Share on other sites

on a related note, you can also use BIS_fnc_spawnVehilce if you want a full crewed heli to spawn.

place a function module on map, make sure that at least 1 of te west side is created on map, and place your markers.

run this code:

waituntil {!isnil "bis_fnc_init"}; /// make sure function module is ready.

// all optional markers to choose from.
_marker = ["marker1","marker2","marker3","marker4","marker5","marke r6"];

// spawn the heli with full crew at a random marker position.
_helispawn = [getMarkerPos (_markers select (floor (random (count _markers)))), 180, "UH60M_EP1", west] call bis_fnc_spawnvehicle;
_vehicle = _helispawn select 0;  // the vehicle itself.

// name the vehicle so all triggers etc work again for both SP and MP missions.
_vehicle SetVehicleVarName "myChopperName";
_vehicle Call Compile Format ["%1=_This ; PublicVariable ""%1""","myChopperName"];

Share this post


Link to post
Share on other sites

Thank you very much all.

I will try your suggestions once I get home.

Share this post


Link to post
Share on other sites

@kylania

Your suggestion worked like a charm. Never knew you could group markers and use them that way.

By the way, it worked when the unit was placed with "In formation" not "None"

Thanks

@twirly & @Demonized I'll check your suggestions out too and report back.

Share this post


Link to post
Share on other sites

Hi, hate to high jack your post. I also have a createVehicle issue, but trying to setHeight of spawned vehicles. The code below works great to spawn vehicles at ground level at marker.

init.sqf

WaitUntil{not isNull player};
_air = player addAction ["Spawn: I44_Plane_A_C47A_AAF","Spawn_Vec.sqf",["I44_Plane_A_C47A_AAF"],5,false,true,"","player in list SpawnVehicleArea"];
_air1 = player addAction ["Spawn: I44_Plane_A_P51D_HVAR_AAF","Spawn_Vec.sqf",["I44_Plane_A_P51D_HVAR_AAF"],5,false,true,"","player in list SpawnVehicleArea"];
_air2 = player addAction ["Spawn: I44_Plane_A_P51D_250lb_AAF","Spawn_Vec.sqf",["I44_Plane_A_P51D_250lb_AAF"],5,false,true,"","player in list SpawnVehicleArea"];
_air3 = player addAction ["Spawn: I44_Plane_A_P51D_AAF","Spawn_Vec.sqf",["I44_Plane_A_P51D_AAF"],5,false,true,"","player in list SpawnVehicleArea"];
_air4 = player addAction ["Spawn: I44_Plane_A_P38_HVAR_AAF","Spawn_Vec.sqf",["I44_Plane_A_P38_HVAR_AAF"],5,false,true,"","player in list SpawnVehicleArea"];
_air5 = player addAction ["Spawn: I44_Plane_A_P38_M64_AAF","Spawn_Vec.sqf",["I44_Plane_A_P38_M64_AAF"],5,false,true,"","player in list SpawnVehicleArea"];
_air6 = player addAction ["Spawn: I44_Plane_A_P38_AAF","Spawn_Vec.sqf",["I44_Plane_A_P38_AAF"],5,false,true,"","player in list SpawnVehicleArea"];

Spawn_Vec.sqf

_type = (_this select 3) select 0;
_vec = _type createVehicle (getMarkerPos "Spawn_Aircraft");
_vec setDir 150;
AllVecsSpawned = AllVecsSpawned + [_vec];
publicVariable "AllVecsSpawned";

I changed _vec = _type createVehicle (getMarkerPos "Spawn_Aircraft");

to

_vec = _type createVehicle ["_vec", [(getMarkerPos "Spawn_Aircraft") select 0,(getMarkerPos "Spawn_Aircraft") select 1, 15.9]];

but get a script error. Error type string, expected number line 2. Can someone plz help thanks.

---------- Post added at 10:50 AM ---------- Previous post was at 10:45 AM ----------

Forgot to tell ya, I have gamelogic in editor named AllVecsSpawned=[]

and a trigger activated by BLUFOR named SpawnVehicleArea.

Edited by Flat4ej20

Share this post


Link to post
Share on other sites

o.0 where did you learn to use that command like that?

it should be like this:

_vec = _type createVehicle [(getMarkerPos "Spawn_Aircraft") select 0,(getMarkerPos "Spawn_Aircraft") select 1, 15.9];

also i recomend using createVehicle array any time, since it is faster and more reliable in creating a handle.

Share this post


Link to post
Share on other sites

_vec = _type createVehicle [(getMarkerPos "Spawn_Aircraft") select 0,(getMarkerPos "Spawn_Aircraft") select 1, 15.9];

This spawns vehicles at ground level. I was trying to spawn vehicles at marker location with a predetermined height of 15.9. You got another idea I can try plz.

Share this post


Link to post
Share on other sites
_veh = createVehicle ["AH64D_EP1", [getMarkerPos "Spawn_Aircraft" select 0,getMarkerPos "Spawn_Aircraft" select 1, 15.9], [], 0, "NONE"];

Share this post


Link to post
Share on other sites

chucking in my 2 pennies worth...

Not sure if this helps - but you can create an invisible H object, call it Spawn_aircraft

players init - this addAction ["spawn stuff","aircraftspawn.sqf"];

script - aircraftspawn.sqf

_vec = "A10_US_EP1" createVehicle (Spawn_aircraft modelToWorld [0,0,0]);
_vec setPosASL  [getPosASL Spawn_aircraft select 0, (getPosASL Spawn_aircraft select 1),
(getPosASL Spawn_aircraft select 2)+10];

seems to work for me. hope this of some use

[FOCK] Mikie J

http://fockers.moonfruit.com/#

Share this post


Link to post
Share on other sites

Thanks for everyone's help. I have came up with this script which spawn's different aircrafts depending on which one I select & spawns at predetermined hieght and marker location.

_type = (_this select 3) select 0;
_vec = _type createVehicle (Spawn_Aircraft modelToWorld [0,0,0]);
_vec setPosASL  [getPosASL Spawn_Aircraft select 0, (getPosASL Spawn_Aircraft select 1),(getPosASL Spawn_Aircraft select 2)+10];
AllVecsSpawned = AllVecsSpawned + [_vec];
publicVariable "AllVecsSpawned";

With out everyone's help I would still be scratching my head.

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  

×