Jump to content
Sign in to follow this  
Dreadp1r4te

Need the expert's help! (createUnit related)

Recommended Posts

I don't get it at all. I cannot for the life of me get this to work...

_airlifteast = "O_Heli_Light_02_unarmed_F" createUnit [_eastposition, _eastspawn];
player moveInCargo _airlifteast;
_wp = _eastspawn addWaypoint [getMarkerPos "opf_air_land", 0];
[_eastspawn, 1] setWaypointType "UNLOAD";

What I'm trying to do is spawn a Heli, then move player inside said heli via magics, and order the heli to fly to that position and unload the player. I can't even get the heli to spawn, despite using the exact syntax as listed on the createUnit wiki page. I've defined a group in an earlier expression:

_eastspawn = createGroup east

And the position variable "_eastposition" is an array extracted from a getmarkerpos, seperated into 3 variable so I can add 200m to the Z variable so it spawns airborne, so I'm at a loss here. Any help?

Edited by Dreadp1r4te

Share this post


Link to post
Share on other sites

Use createVehicle instead.

_veh = createVehicle ["O_Heli_Light_02_unarmed_F", _eastposition, [], 0, "FLY"] ;
player moveInCargo _veh;
_wp = group player addWaypoint [getMarkerPos "opf_air_land", 0];
_wp setWaypointType "UNLOAD";

Edited by cobra4v320

Share this post


Link to post
Share on other sites
Use createVehicle instead.

_veh = createVehicle ["O_Heli_Light_02_unarmed_F", _eastposition, [], 0, "FLY"] ;
player moveInCargo _veh;
_wp = group player addWaypoint [getMarkerPos "opf_air_land", 0];
_wp setWaypointType "UNLOAD";

Erm, won't that create an empty helicopter? An empty helicopter that's flying, at that? That sounds a bit... dangerous. Just sayin'. :P

I want the heli that spawns to be crewed by AI, an air taxi of sorts.

Share this post


Link to post
Share on other sites

Then use Bis_fnc_spawnVehicle or you can spawn the crew bis_fnc_spawnCrew

Share this post


Link to post
Share on other sites

Alright thanks a ton! That worked beautifully. New problem now! I can't make the aircraft land via a scripted waypoint... The Unload waypoint type won't work, because I'm only transporting players and not AI. Any ideas how to fix this? Keep in mind, must be executed via script not in editor.

Share this post


Link to post
Share on other sites

Make sure there's a helipad object (invisible or not) where you want it to land and use

_wp [url="https://community.bistudio.com/wiki/setWaypointStatements"]setWaypointStatements[/url] ["TRUE", "this [url="https://community.bistudio.com/wiki/land"]land[/url] 'LAND'""];

Edit: When using this, it's actually better to put the waypoint well before the helipad, else the helicopter probably overshoots and the landing takes more time.

Edited by Magirot

Share this post


Link to post
Share on other sites
Make sure there's a helipad object (invisible or not) where you want it to land and use

_wp [url="https://community.bistudio.com/wiki/setWaypointStatements"]setWaypointStatements[/url] ["TRUE", "this [url="https://community.bistudio.com/wiki/land"]land[/url] 'LAND'""];

Edit: When using this, it's actually better to put the waypoint well before the helipad, else the helicopter probably overshoots and the landing takes more time.

Thanks, I'll try that out! Are you sure your syntax is correct? I'm really new to scripting but it looks like there's one too many " in the expression...

Share this post


Link to post
Share on other sites

Haha fair enough, but unfortunately that script didn't help. In fact, with your syntax it broke the script file completely. I had to reword it such:

[_wgroup, 1] setWaypointStatements ["TRUE", "this land 'LAND'"];

This fixed the script from crashing, but still doesn't force the aircraft to land. :( I also have

[_wgroup, 1] setWaypointType "UNLOAD";

but conveniently the Unload command won't work without actual AI in the helo, and since it's a player transport... it's somewhat useless. Why BI did that is somewhat of a bistery.

Share this post


Link to post
Share on other sites

How did it break it? Did it give any error message?

But apparently the problem is that the land command wants the helicopter object itself instead of the group leader or pilot. Geh.

This works for me, at least:

_veh = [_eastposition, 0, "O_Heli_Light_02_unarmed_F", opfor] call BIS_fnc_spawnVehicle;

heli1      = _veh select 0;
_heligroup = _veh select 2;

_heligroup setBehaviour "SAFE";
player moveInCargo heli1;


_wp = _heligroup addWaypoint [getMarkerPos "opf_air_land", 0];
_wp setWaypointType "MOVE";
_wp setWaypointStatements ["TRUE", "heli1 land 'LAND'"]; // or 'GET OUT' for keeping engine on


// if the heli should leave afterwards
waitUntil { vehicle player != heli1 };

heli1 setVehicleLock "LOCKED";
_wp = _heligroup addWaypoint [getMarkerPos "somewhere_far_away", 0];
_wp setWaypointType "MOVE";

Share this post


Link to post
Share on other sites
Haha fair enough, but unfortunately that script didn't help. In fact, with your syntax it broke the script file completely. I had to reword it such:

[_wgroup, 1] setWaypointStatements ["TRUE", "this land 'LAND'"];

This fixed the script from crashing, but still doesn't force the aircraft to land. :( I also have

[_wgroup, 1] setWaypointType "UNLOAD";

but conveniently the Unload command won't work without actual AI in the helo, and since it's a player transport... it's somewhat useless. Why BI did that is somewhat of a bistery.

remember that in waypoint statements (condition and onActivation/deactivation)

this refers to the group leader (not the vehicle)

thisList refers to all the units in the group (again, excluding the vehicle)

to make it land you need to put:

(vehicle this) land 'LAND'

to force players and AI to leave a vehicle:

{_x action["eject", vehicle _x]} forEach units _myGroup;
{unAssignVehicle _x} forEach units _myGroup;

however be warned, if your trigger condition is not properly set up for checking if the helicopter actually landed, then everyone will be ejected out of the helicopter mid-air

to prevent this, you need to also check in either a trigger, or waypoint condition:

isTouchingGround (vehicle this) // in in waypoint condition

Edited by Igneous01

Share this post


Link to post
Share on other sites

Here is another example. I also have an extraction example that you can find in my signature.

/*
example: 0 = [player, markerPos "spawnMrk", markerPos "endMrk", 50] execVM "transport.sqf" 
*/

//Parameters
private ["_group","_startPos","_endPos","_height"];
_group 	  = _this select 0;
_startPos = _this select 1;
_endPos   = _this select 2;
_height   = if (count _this > 3) then {_this select 3} else {50};

//Validate parameter count
if ((count _this) < 3) exitWith { false};

//Validate Parameters
if (isNull _group) exitWith {"Group (0) parameter must not be null. Accepted: GROUP or OBJECT" call BIS_fnc_error; false};
if ((typeName _startPos) != (typeName [])) exitWith {"Position (1) should be an Array!" call BIS_fnc_error; false};
if ((count _startPos) < 2) exitWith {"Position (1) should contain at least 2 elements!" call BIS_fnc_error; false};
if ((typeName _endPos) != (typeName [])) exitWith {"Position (2) should be an Array!" call BIS_fnc_error; false};
if ((count _endPos) < 2) exitWith {"Position (2) should contain at least 2 elements!" call BIS_fnc_error; false};

//Object given instead of group
if (typeName _group == "OBJECT") then {
if (_group isKindOf "MAN") then {
	_group = group _group;
} else {
	if (count crew _group < 1) exitWith {
		"Vehicle given as GROUP has no crew" call BIS_fnc_error;
	};
	if (!isNull group driver _group) then {
		_group = group driver _group;
	} else {
		if (!isNull group gunner _group) then {
			_group = group gunner _group;
		} else {
			_group = group ((crew _group) select 0);
		};
	};
};
};

//Create the helicopter based on groups side
private "_heliContainer";
switch (side _group) do {
case blufor:
{
	_heliContainer = [[_startPos select 0, _startPos select 1, _height], [_startPos, _endPos] call BIS_fnc_dirTo, "B_Heli_Transport_01_F", blufor] call BIS_fnc_spawnVehicle;
};
case opfor:
{
	_heliContainer = [[_startPos select 0, _startPos select 1, _height], [_startPos, _endPos] call BIS_fnc_dirTo, "O_Heli_Light_02_F", opfor] call BIS_fnc_spawnVehicle;
};
case independent:
{
	_heliContainer = [[_startPos select 0, _startPos select 1, _height], [_startPos, _endPos] call BIS_fnc_dirTo , "I_Heli_light_03_F", independent] call BIS_fnc_spawnVehicle;
};
};

private ["_heli","_heliGroup"];
_heli = _heliContainer select 0;
_heliGroup = _heliContainer select 2;

//height & speed
private "_dir";
_dir = direction _heli;
_heli setVelocity [sin (_dir) * 50, cos (_dir) * 50, 0];
_heli flyInHeight _height;

_heliGroup allowFleeing 0;

{
_x assignAsCargo _heli;
_x moveInCargo _heli;
} forEach (units _group);

_wp1 = _heliGroup addWaypoint [_endPos, 0];
_wp1 setWaypointType "UNLOAD";
_wp1 setWaypointBehaviour "CARELESS";
_wp1 setWaypointCombatMode "GREEN";
_wp1 setWaypointSpeed "FULL";
_wp1 setWaypointStatements ["true", "_heli = vehicle this; _heli land 'GET OUT'"];

waitUntil { {_x in _heli} count (units _group) < 1 };

_wp2 = _heliGroup addWaypoint [_startPos, 0];
_wp2 setWaypointType "MOVE";
_wp2 setWaypointBehaviour "CARELESS";
_wp2 setWaypointCombatMode "GREEN";
_wp2 setWaypointSpeed "FULL";
_wp2 setWaypointStatements ["true", "_group = group this; _heli = vehicle this; _units = crew _heli; {deleteVehicle _x} forEach _units; deleteVehicle _heli; deleteGroup _group"];

Share this post


Link to post
Share on other sites

Wow thanks a ton guys! Okay so I got the heli to land, and I set up a trigger to activate when the heli lands:

waitUntil {isTouchingGround (vehicle player)};
player action ["Eject", player];
sleep 2;
_wheli lock true;
_wp2 = _wgroup addWaypoint [getMarkerPos "blu_air_depart", 0];
[_wgroup, 2] setWaypointType "MOVE";

But the problem now is that the waitUntil command isn't working. I tested the "isTouchingGround" bit in game with a simple variable and hint:

_contact = isTouchingGround (vehicle player);
hint format["This variable returns as: %1",_contact];

And it returned as true, meaning the problem has to be in my implementation of the waitUntil command. I do know that everything AFTER the "waitUntil" command isn't firing, so the script is in fact waiting, but it doesn't trigger when I land. Any ideas there?

Oh and huge thanks for all the help. I'm learning a ton! :D

Share this post


Link to post
Share on other sites

You have to specify the vehicle to eject in the player action as well, as in Ignaeous01's example above:

player action ["Eject", vehicle player];

Share this post


Link to post
Share on other sites

Okay, I changed that, but the other expressions after the waitUntil aren't executing either. It should also lock the vehicle and add a new waypoint.

This is what I'm about to test; it should work from what I'm reading...

wcontact = false; // Initialize a variable, assign it false to prevent accidental trigger
wcontact = isTouchingGround (vehicle player); // Change the variable to true once the player's heli has landed
waitUntil { wcontact };// waitUntil won't trigger until the value of wcontact is true

I just added the comments to explain my rationale. I realize I could just call the isTouchingGround function inside the block of the waitUntil function, but this way I can avoid any potential syntax errors on my part, as I can test independently the value of wcontact in game with the debug editor.

Share this post


Link to post
Share on other sites

There's nothing wrong with your use of waitUntil, at least. I just tested it in the editor and it worked fine.

Maybe it's something before that? Can you post the full script? Here's all of what I tested:

_eastposition = getMarkerPos "eastposmarker";

_veh = [_eastposition, 0, "O_Heli_Light_02_unarmed_F", opfor] call BIS_fnc_spawnVehicle;

// BIS_fnc_spawnVehicle returns three things in an array:
// vehicle object, the units of the crew created, and the group itself
// They can be accessed with select
_wheli  = _veh select 0;
_wgroup = _veh select 2;

player moveInCargo _wheli;

_wp = _wgroup addWaypoint [getMarkerPos "opf_air_land", 0];
_wp setWaypointType "MOVE";
_wp setWaypointStatements ["TRUE", "(vehicle this) land 'LAND'"];

waitUntil {isTouchingGround (vehicle player)};
player action ["Eject", vehicle player];
sleep 2;
_wheli lock true;
_wp2 = _wgroup addWaypoint [getMarkerPos "blu_air_depart", 0];
[_wgroup, 2] setWaypointType "MOVE";

Share this post


Link to post
Share on other sites

Sure thing, will do.

{
_eheli = [getMarkerPos "opf_air_spawn", 225, "O_Heli_Light_02_F", east] call bis_fnc_spawnvehicle;
_etaxi = _eheli select 0;
_egroup = _eheli select 2;
_egroup allowFleeing 0;
player moveInCargo _etaxi;
_wp = _egroup addWaypoint [getMarkerPos "opf_air_land", 50];
[_egroup, 1] setWaypointType "UNLOAD";
[_egroup, 1] setWaypointStatements ["TRUE", "(vehicle this) land 'LAND'"];
10000 cutText ["Use your scroll wheel to gear up!", "BLACK IN", 10];
_econtact = isTouchingGround (vehicle _egroup);
waitUntil {_econtact = true};
player action ["Eject", vehicle _wgroup];
sleep 1;
_wheli lock true;
_wp2 = _egroup addWaypoint [getMarkerPos "opf_air_depart", 0];
[_egroup, 2] setWaypointType "MOVE";
};

That's the entire block of code. I removed some spaces, because I keep my code properly spaced so it makes sense when one looks at the entire file, and add comments as needed, after I troubleshoot everything. Mostly everything I have is the same as yours; I'm at a loss as to why mine doesn't work. Note that the initial open curved bracket and ending close curved bracket are due to this block being inside an IF argument's "Then" block, which is working fine near as I can tell.

EDIT: Also note that on my last test, using "player vehicle" in the waitUntil isTouchingGround condition for some reason caused the heli to eject me right after moving me into the cargo, so I switched it to check "vehicle _egroup" instead. That fixed the insta-eject, but again after the helo lands nothing happens.

EDIT AGAIN!:

I just changed the code around a bit back to stuff that SHOULD make sense (using player vehicle and such where possible) annnnd noted a mistake; I was trying to apply the Lock command to the variable _wheli, when I should have been applying it to _wtaxi, which is the actual vehicle object. Not sure if that was causing my issue, but I'm happy to report everything is working as expected now! The heli flies in, drops my happy ass off, chills for sec, then dusts off and heads out. Pretty slick! Thanks again for all the help! Couldn't have done it without ya.

_wheli = [getMarkerPos "blu_air_spawn", 45, "B_Heli_Transport_01_F", west] call bis_fnc_spawnvehicle;
_wtaxi = _wheli select 0;
_wgroup = _wheli select 2;
_wgroup allowFleeing 0;
player moveInCargo _wtaxi;
_wp = _wgroup addWaypoint [getMarkerPos "blu_air_land", 100];
[_wgroup, 1] setWaypointType "MOVE";
[_wgroup, 1] setWaypointStatements ["TRUE", "(vehicle this) land 'LAND'"];
10000 cutText ["Use your scroll wheel to gear up!", "BLACK IN", 10];
waitUntil {isTouchingGround (vehicle player)};
player action ["Eject", vehicle player];
sleep 2;
_wtaxi lock true;
_wp2 = _wgroup addWaypoint [getMarkerPos "blu_air_depart", 0];
[_wgroup, 2] setWaypointType "MOVE";

Edited by Dreadp1r4te

Share this post


Link to post
Share on other sites
Also note that on my last test, using "player vehicle" in the waitUntil isTouchingGround condition for some reason caused the heli to eject me right after moving me into the cargo, so I switched it to check "vehicle _egroup" instead.

That's a smart thing to do actually, because "vehicle player" refers to the player infantry unit if the player isn't in a vehicle. So if the waitUntil manages to run before the player is in the helicopter, it checks if the player is standing on the ground, and queues the eject action.

The issue was that you checked for the vehicle of "_wgroup", which is a group instead of an object. Like with the lock command, isTouchingGround _wtaxi (or isTouchingGround vehicle leader _wgroup) would be functional.

Glad that you got it working! :)

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  

×