Jump to content
Sign in to follow this  
KrazySwede

"createUnit" works with men but not vehicles

Recommended Posts

I posted this on the Armaholic forum a while ago but was unable to solve the problem, so I thought I'd give it a shot here.

My basic problem is that the "createVehicle" will spawn men but not occupied vehicles.

I'm using the following chunk of script:

_hq_east = createCenter east;
_group_e1 = createGroup east;

_target = _this select 0;
_homeplate = getPos _target;

_group_e1 createUnit ["Ins_Soldier_1",_homeplate,[],0,"NONE"];
_group_e1 createUnit ["UAZ_INS",_homeplate,[],0,"NONE"];

This is using the array form of createVehicle (here: http://community.bistudio.com/wiki/createUnit_array ) and I also tried using the other format (here: http://community.bistudio.com/wiki/createUnit ) by replacing the last two lines above with:

"Ins_Soldier_1" createUnit [_homeplate, _group_e1];
"UAZ_INS" createUnit [_homeplate, _group_e1];

_homeplate is defined and the insurgent spawns without any problem, but the UAZ only appears for a second and then it's gone. I have tried it with several different vehicle types.

I want to avoid having to create an empty vehicle and then populating it manually.

Am I missing something that's necessary to make this work?

Thanks,

Marcus

Share this post


Link to post
Share on other sites

I think it is not possible to spawn manned vehicles. Never saw this in nearly 10 years OFP/ArmA/ArmA2 history...

The only way ist to create the empty vehicle and then the crew. After that use moveInDriver etc. to put them into the vehicle...

:rolleyes:

Share this post


Link to post
Share on other sites

_unit = ([_pos, 0, "UAZ_INS", _grp] call BIS_fnc_spawnVehicle) select 0;

Share this post


Link to post
Share on other sites

I can't get this to work. I've tried the following and non of them work:

_unit = ([getmarkerpos "mark1", 0, "BMP3", east]call BIS_fnc_spawnVehicle) select 0;

_unit = ([getmarkerpos mark1, 0, "BMP3", east]call BIS_fnc_spawnVehicle) select 0;

_unit = ([(getmarkerpos mark1), 0, "BMP3", east]call BIS_fnc_spawnVehicle) select 0;

---------- Post added at 04:20 AM ---------- Previous post was at 03:49 AM ----------

Okay, a friend helped me figure out the problem. The BIS functions take about half a second to load once the mission starts, so you either have to wait a second or two with "sleep" before calling BIS_fnc_spawnVehicle, or you can just put in:

{!isnil "bis_fnc_init"};

to check and see if it has loaded or not.

Oh, and the _unit = ... stuff really isn't necessary. You can just use:

[(getmarkerpos marker1), 0, "BMP3", east] call BIS_fnc_spawnVehicle; and it should work fine.

Share this post


Link to post
Share on other sites
Okay, a friend helped me figure out the problem. The BIS functions take about half a second to load once the mission starts, so you either have to wait a second or two with "sleep" before calling BIS_fnc_spawnVehicle, or you can just put in:

{!isnil "bis_fnc_init"};

to check and see if it has loaded or not.

Oh, and the _unit = ... stuff really isn't necessary. You can just use:

[(getmarkerpos marker1), 0, "BMP3", east] call BIS_fnc_spawnVehicle; and it should work fine.

The best way seems to be using init.sqf:

waituntil {!isnil "bis_fnc_init"};
waituntil {!isnil "BIS_MPF_InitDone"};

Share this post


Link to post
Share on other sites

how can i delete this vehicle after it spawns? my problem is im spawning a m2 static mg and trying to name it mg1 = then the code. when i try to deletevehicle mg1 it does not delete. im trying to do this because i cant get a man to remount my m2 guns if the gunner gets killed. ive tried moveingunner and moveturret and driver ect when creating a unit. but they just wont go. there smart and move. ive even tried assignasgunner and assign vehicle and unassign vehicle. if i knew how to name each unit(gunner and gun) or get their names maybe i could this. think ill try setting a waypoint to a marker and get in next lol. thank you. instead im doing this>> http://forums.bistudio.com/showthread.php?t=95047 . using this respawn ai script and then telling moveingunner worked for me. i didnt use the "east_wp" script part.

Edited by SplatterFace

Share this post


Link to post
Share on other sites

_mg = createvehicle [blabla];

_mg setVehicleVarName "mg1";

Share this post


Link to post
Share on other sites

How to spawn a vehicle flying with BIS_fnc_spawnVehicle?

Edit:

[[markerPos "heloStart" select 0, markerPos "heloStart" select 1, 100], 0, "UH60M_EP1", west] call BIS_fnc_spawnVehicle;

Where 100 is the starting height.

Edited by scifer

Share this post


Link to post
Share on other sites
How to spawn a vehicle flying with BIS_fnc_spawnVehicle?

i believe you would have to spawn the vehicle, create the units (pilots) assign them into the vehicle, move them into the vehicle (assignasdriver, moveindriver) and under createunit set NONE to FLYING.

thats just a guess tho, but i believe it may work.

Share this post


Link to post
Share on other sites
i believe you would have to spawn the vehicle, create the units (pilots) assign them into the vehicle, move them into the vehicle (assignasdriver, moveindriver) and under createunit set NONE to FLYING.

thats just a guess tho, but i believe it may work.

No with the function you don't have to create the crew. The function will do it for you.

---------- Post added at 08:45 AM ---------- Previous post was at 08:36 AM ----------

How to spawn a vehicle flying with BIS_fnc_spawnVehicle?

Edit:

[[markerPos "heloStart" select 0, markerPos "heloStart" select 1, 100], 0, "UH60M_EP1", west] call BIS_fnc_spawnVehicle;

Where 100 is the starting height.

Here's a script i made with the assistance of Demonized, who was so helpful to help me finish it:

//Vehicle_Respawn
//Concept and code adaptation by =WB=Tex
//Most of the code by Demonized
// put in init line of any vehicle: _null = [this, "markername", number of lives, time until respawn, external script] execVM "script_name.sqf"
// create a new vehicle after first is dead _x amount of times.

_veh = _this select 0; // this is the vehicle that runs the script.
_spawnpos = _this select 1; // this is the marker where you want it to spawn at.
_respawns = _this select 2; // this is where you get the number of lives (respawns) of the unit.
_delay = _this select 3; // this gets the time until a new unit respawns and other is deleted;
_movescript = _this select 4; // sets execution of script defined in editor unit init
_vehicleType = typeOf _veh; // gets the type of vehicle.
_side = side (driver _veh); // gets the side of vehicle.
[_veh] execVM _movescript; //external script execution for editor unit.

waitUntil {!alive _veh OR !canMove _veh}; // wait until the placed unit in the editor is destroyed or disabled.
sleep _delay; // delayed timer defined in the initialization
deleteVehicle _veh; // deletes the placed editor unit.

_altitude = 0; // default altitude if not Air unit.
if (_veh isKindOf "Air") then {
_altitude = 150; //spawn altitude for Air units.
};

while {_respawns != 0} do {
_sv = [[getMarkerPos _spawnpos select 0,getMarkerPos _spawnpos select 1, _altitude], (random 360), _vehicleType, _side] call BIS_fnc_spawnVehicle; // creates a new unit regarding it hasn't ran out of lives.

_vehicle = _sv select 0; // vehicle spawned
_vehiclegrp = _sv select 2; //vehicle spawned group
[_vehicle] execVM _movescript; // external script execution for respawned unit.

//helo1= _vehicle; // just for testing purposes when using triggers.

_fuelchk = [_vehicle] spawn {
if (isServer) then {
_vehicle = _this select 0;
waitUntil { if !(alive _vehicle) exitWith {}; if (fuel _vehicle < 0.1) then { _vehicle setfuel 1}; false }; // this allows for the vehicle to never have fuel shortage
};
};

waitUntil { !alive _vehicle OR !canMove _vehicle }; // this waits until vehicle is dead (!alive) or vehicle cannot move due to damage.
_respawns = _respawns - 1; // _x amount respawns is now -1 and will create the vehicle again in exact same way as first one.
sleep _delay; // this is how long after vehicle is dead before it will respawn.

[_vehicle] spawn {
_vehicle = _this select 0;
sleep 180;
deleteVehicle _vehicle;
};

};

Put this in the init field of the unit:

null = [this, "markername", "number of lives", "time until respawn", "external move script if wanted"] execVM "vehicle_respawn.sqf"

If you want to edit the spawn altitude just go in to the variable in the script and change 150 to whatever you want.

Edited by CarlosTex

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  

×