createVehicle: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (position type)
m (Some wiki formatting)
(126 intermediate revisions by 10 users not shown)
Line 1: Line 1:
{{Command|= Comments
{{RV|type=command
____________________________________________________________________________________________


| ofp |= Game name
|game1= ofp
|version1= 1.34


|1.34|= Game version
|game2= ofpe
|version2= 1.00


|eff= global |= Effects in MP
|game3= arma1
____________________________________________________________________________________________
|version3= 1.00


| Creates an empty object of given classname type (See [[Arma 3 Assets]] or [[createVehicle/vehicles]])
|game4= arma2
<br>For a class reference from older games see [[:Category:ArmA Classes|Classes]].<br><br>
|version4= 1.00
<u>Some special 'Scripted' vehicle classes:</u>
* DemoCharge_Remote_Ammo_Scripted - same as DemoCharge_Remote_Ammo but will explode when destroyed or [[setDamage]] 1;
* SatchelCharge_Remote_Ammo_Scripted - same as SatchelCharge_Remote_Ammo but will explode when destroyed or [[setDamage]] 1;
* ClaymoreDirectionalMine_Remote_Ammo_Scripted -  same as ClaymoreDirectionalMine_Remote_Ammo but will explode when destroyed or [[setDamage]] 1;
* GroundWeaponHolder_Scripted - same as GroundWeaponHolder but will not be auto-deleted when empty
* WeaponHolderSimulated_Scripted - same as WeaponHolderSimulated but will not be auto-deleted when empty


<br>'''Randomization:'''<br>
|game5= arma2oa
In Arma 3 many vehicles will get randomized in appearance by default in order to add some variety to the game. It is possible to override this default behavior by setting ''BIS_enableRandomization'' variable to [[false]] in the vehicle namespace:
|version5= 1.50
<code>_veh <nowiki>=</nowiki> "C_Offroad_01_F" [[createVehicle]] [[position]] [[player]];
_veh [[setVariable]] ["BIS_enableRandomization", [[false]]];</code>
or
<code>this [[setVariable]] ["BIS_enableRandomization", [[false]]];</code>
if done in mission editor init field. |= Description
____________________________________________________________________________________________


| type '''createVehicle''' position |= Syntax
|game6= tkoh
|version6= 1.00


|p1= type: [[String]] - vehicle/object className |= Parameter 1
|game7= arma3
|version7= 0.50


|p2= position: [[Position]] - Desired placement position. If the exact position is occupied, nearest empty position is used.
|eff= global
|= Parameter 2


| [[Object]] |= Return value
|gr1= Object Manipulation
____________________________________________________________________________________________


|descr= Creates an empty object of given classname type.
See [[Arma 3 Assets]] / [[Arma 3: createVehicle/vehicles]], or [[:Category:CfgVehicles]] for earlier games.


| s2= '''createVehicle''' [type, position, markers, placement, special] |= Syntax
{{Feature|informative|
* To create objects of type {{hl|"Logic"}}, use [[createUnit]].
* To create an editable [[:Category: Eden Editor| Eden Editor]] entity, see [[create3DENEntity]].
}}


|p21= [type, position, markers, placement, special]: [[Array]] |= Parameter 1
{{Feature|arma3|To avoid vehicle randomisation in {{arma3}}, set the {{hl|BIS_enableRandomization}} variable immediately after creating the vehicle:
<sqf>private _vehicle = "C_Offroad_01_F" createVehicle position player;
_vehicle setVariable ["BIS_enableRandomization", false];</sqf>
Check [[Vehicle Customization (VhC)]] page for more information and settings.}}


|p22= type: [[String]] - vehicle/object className |= Parameter 2
|s1= type [[createVehicle]] position


|p23= position: [[PositionATL]], [[PositionASLW]] if boat on water, [[Position2D]], or [[Object]] - Desired placement position |= Parameter 3
|p1= type: [[String]] - vehicle/object className


|p24= markers: [[Array]] - If the markers array contains any markers, the position is randomly picked from array of given markers plus desired placement position. If any of the markers were given z coordinate with [[setMarkerPos]], the vehicle will also be created at given z coordinate. |= Parameter 4
|p2= position: [[Array]] format [[Position]] - desired placement position. If the exact position is occupied, nearest empty position is used.


|p25= placement: [[Number]] - The vehicle is placed inside a circle with given position as center and placement as its radius|= Parameter 5
|r1= [[Object]]


|p26= special: [[String]] - <tt>"NONE"</tt>, <tt>"FLY"</tt>, <tt>"FORM"</tt>, <tt>"CAN_COLLIDE"</tt>. "CAN_COLLIDE" creates the vehicle exactly where asked, not checking if others objects can cross its 3D model. |= Parameter 6
|s2= [[createVehicle]] [type, position, markers, placement, special]


| r2= [[Object]] |= Return value
|p21= type: [[String]] - vehicle/object className
____________________________________________________________________________________________
 
|x1= <code>_jeep = "Jeep" [[createVehicle]] [[position]] [[player]];</code> |= Example 1
|x2= <code>_heli = "AH1Z" [[createVehicle]] [[getMarkerPos]] "hspawn";</code> |= Example 2
|x3= <code>_veh = [[createVehicle]] ["ah1w", [[position]] [[player]], [], 0, "FLY"];</code> |= Example 3
|x4 = <code>_veh = [[createVehicle]] ["2S6M_Tunguska", [[getMarkerPos]] "marker1", ["marker2","marker3"], 0, "NONE"];</code> |= Example 4
|x5= Objects such as
* test_EmptyObjectForBubbles
* test_EmptyObjectForFireBig
* test_EmptyObjectForSmoke
create additional emitters that needs to be deleted first before deleting the object itself: <code>///--- function to delete test object (MP compatible)
fnc_deleteTestObj = {
_this [[addMPEventHandler]] ["MPKilled", {
_this = _this [[select]] 0;
{
[[deleteVehicle]] _x;
} [[forEach]] (_this [[getVariable]] ["effects", []]);
[[if]] ([[isServer]]) [[then]] {
[[deleteVehicle]] _this;
};
}];
_this [[setDamage]] 1;
};
///--- example
[] [[spawn]] {
_fire = "test_EmptyObjectForFireBig" [[createVehicle]] [[position]] [[player]];
[[sleep]] 5;
_fire [[call]] fnc_deleteTestObj;
};</code> |= Example 5
|x6=The following explosives (with ending _Scripted)
* DemoCharge_Remote_Ammo_Scripted
* SatchelCharge_Remote_Ammo_Scripted
* ClaymoreDirectionalMine_Remote_Ammo_Scripted
can be set off by applying [[setDamage]] 1 to them for ease of scripting: <code>_claymore = "ClaymoreDirectionalMine_Remote_Ammo_Scripted" [[createVehicle]] [[position]] [[player]];
0 = _claymore [[spawn]] {
[[uiSleep]] 5;
_this [[setDamage]] 1;
};
</code> |= Example 6
|x7= How to add inventory to objects without inventory:<code>_boxes = "Land_Pallet_MilBoxes_F" [[createVehicle]] [[position]] [[player]];
_cargo = "Supply500" [[createVehicle]] [0,0,0];
_cargo [[attachTo]] [_boxes, [0,0,0.85]];


// optional for objects that can take damage
|p22= position: [[Object]]; [[Array]] format [[Position#Introduction|Position2D]] or [[PositionATL]] ([[PositionAGL]] if watercraft or amphibious) - desired placement position
_boxes [[addEventHandler]] ["Killed", {
{
[[detach]] _x,
[[deleteVehicle]] _x;
}
[[forEach]] [[attachedObjects]] (_this [[select]] 0);
}];</code>
|= Example 7
|x8= Drop weapon:<code>_wh = "GroundWeaponHolder_Scripted" [[createVehicle]] [[position]] [[player]];
[[player]] [[action]] ["DropWeapon", _wh, [[currentWeapon]] [[player]]];</code> |= Example 7
____________________________________________________________________________________________


|[[createVehicleLocal]], [[createVehicleCrew]], [[createAgent]], [[createTrigger]], [[createUnit]], [[deleteVehicle]], [[createGroup]], [[createCenter]], [[setVehiclePosition]] |= See also
|p23= markers: [[Array]] of [[String]]s - (Optional, default []) if the markers array contains any markers, the position is randomly picked from array of given markers plus desired placement position. If any of the markers were given z coordinate with [[setMarkerPos]], the vehicle will also be created at given z coordinate.


}}
|p24= placement: [[Number]] - (Optional, default 0) the vehicle is placed inside a circle with given position as center and placement as its radius.


<h3 style="display:none">Notes</h3>
|p25= special: [[String]] - (Optional, default "NONE") can be one of the following:
<dl class="command_description">
* {{hl|"NONE"}} - will look for suitable empty position near given position (subject to other placement params) before placing vehicle there.
<!-- Note Section BEGIN -->
* {{hl|"CAN_COLLIDE"}} - places vehicle at given position (subject to other placement params), without checking if others objects can cross its 3D model.
* {{hl|"FLY"}} - if vehicle is capable of flying and has crew, it will be made airborne at default height.
If ''special'' is "" or not specified, default {{hl|"NONE"}} is used.


<dd class="notedate">Posted on August 13, 2006 - 12:18
|r2= [[Object]] - created vehicle or [[objNull]] if failed
<dt class="note">'''[[User:Raedor|raedor]]'''<dd class="note">
Using main syntax of this command sets the created vehicle not exactly at the given position, you have to [[setPos]] it there, if accuracy counts.


<dd class="notedate">Posted on Jan 20, 2006
|x1= <sqf>_jeep = "Jeep" createVehicle position player;</sqf>
<dt class="note">'''[[User:bdfy|bdfy]]'''<dd class="note">
Using main syntax of this command sets the created vehicle in the nearest ''possible'' position. You can create a dozen of tanks with it - they will appear side by side.


<dd class="notedate">Posted on December 13, 2006 - 12:27
|x2= <sqf>_heli = "AH1Z" createVehicle getMarkerPos "hspawn";</sqf>
<dt class="note">'''[[User:Salisan|Salisan]]'''<dd class="note">
Observe that buildings with the default [https://manuals.bisimulations.com/vbs2/1-60/devref/Content/Config_Manual/CfgVehicles/D_cpp/cpp_destrType.htm destrType] will not work correctly in multiplayer in Armed Assault when created with this command. The Destruction effect will only be displayed where the building is local.


<dd class="notedate">Posted on Oct 18, 2009 - 05:42
|x3= <sqf>_veh = createVehicle ["ah1w", position player, [], 0, "FLY"];</sqf>
<dt class="note">'''[[User:Canukausiuka|Canukausiuka]]'''<dd class="note">
As of Arma2, this command cannot be used to create game logics [http://forums.bistudio.com/showthread.php?t=81964 (source)].  Use [[createUnit]] instead.


<dd class="notedate">Posted on January 14, 2011
|x4= <sqf>_veh = createVehicle ["2S6M_Tunguska", getMarkerPos "marker1", ["marker2", "marker3"], 0, "NONE"];</sqf>
<dt class="note">'''[[User:Galzohar|Galzohar]]'''<dd class="note">
In multiplayer, only run this command on one machine. It will create a the vehicle on all machines every time it is called on any machine.


<dd class="notedate">Posted on January 26 2014 - 20:12
|x5= Objects such as
<dt class="note">'''[[User:Katulobotomia|Katulobotomia]]'''<dd class="note">
* "test_EmptyObjectForBubbles"
Using [[getPosATL]] should work, if otherwise you are struggling to get a the proper position coordinates.
* "test_EmptyObjectForFireBig"
<!-- Note Section END -->
* "test_EmptyObjectForSmoke"
</dl>
create additional emitters, which are stored in "effects" variable on the object. Since {{arma3}} v1.72 these emitters are automatically deleted when object is deleted
<sqf>[] spawn
{
private _fire = "test_EmptyObjectForFireBig" createVehicle position player;
sleep 5;
deleteVehicle _fire;
};</sqf>


<h3 style="display:none">Bottom Section</h3>
|x6= The following explosives (ending with {{hl|_Scripted}}) can be set off by applying [[setDamage]] 1 to them for ease of scripting:
* "DemoCharge_Remote_Ammo_Scripted"
* "SatchelCharge_Remote_Ammo_Scripted"
* "ClaymoreDirectionalMine_Remote_Ammo_Scripted"
<sqf>_claymore = "ClaymoreDirectionalMine_Remote_Ammo_Scripted" createVehicle position player;
_claymore spawn
{
sleep 5;
_this setDamage 1;
};</sqf>


[[Category:Scripting Commands|CREATEVEHICLE]]
|x7= Add inventory to objects without inventory:
[[Category:Scripting Commands OFP 1.99|CREATEVEHICLE]]
<sqf>_boxes = "Land_Pallet_MilBoxes_F" createVehicle position player;
[[Category:Scripting Commands OFP 1.96|CREATEVEHICLE]]
_cargo = "Supply500" createVehicle [0,0,0];
[[Category:Scripting Commands OFP 1.46|CREATEVEHICLE]]
_cargo attachTo [_boxes, [0,0,0.85]];
[[Category:Scripting Commands ArmA|CREATEVEHICLE]]
[[Category:Command_Group:_Object_Manipulation|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands ArmA2|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting_Commands_Take_On_Helicopters|{{uc:{{PAGENAME}}}}]]


<!-- CONTINUE Notes -->
// optional for objects that can take damage
<dl class="command_description">
_boxes addEventHandler ["Killed",
<dd class="notedate">Posted on September 12, 2014 - 07:59 (UTC)</dd>
{
<dt class="note">[[User:Killzone Kid|Killzone Kid]]</dt>
{
<dd class="note">
detach _x,
<tt>"vehclass" [[createVehicle]] pos</tt> is the same if not faster than <tt>[[createVehicle]] ["vehclass", pos, [], 0, "NONE"]</tt>
deleteVehicle _x;
</dd>
}
</dl>
forEach attachedObjects (_this select 0);
<!-- DISCONTINUE Notes -->
}];</sqf>


<!-- CONTINUE Notes -->
|x8= Drop player's weapon:
<dl class="command_description">
<sqf>_wh = "GroundWeaponHolder_Scripted" createVehicle position player;
<dd class="notedate">Posted on August 22, 2015 - 13:04 (UTC)</dd>
player action ["DropWeapon", _wh, currentWeapon player];</sqf>
<dt class="note">[[User:MrSanchez|MrSanchez]]</dt>
<dd class="note">


GroundWeaponHolder class is automatically deleted when empty after 0.5 to 1 seconds in A3 1.48. The exact delay is random but never lower than 0.50 secs after creation. You can stop deletion by adding something (cargo) to it within 0.5 seconds.
|x9= The following weapon holders (ending with ''_Scripted'') do '''not''' auto-delete when empty. It is up to the mission maker to take care of these:
* "GroundWeaponHolder_Scripted"
* "WeaponHolderSimulated_Scripted"
* "Weapon_Empty" (a special weaponholder that displays only a single weapon, even if it contains magazines for this weapon)
<sqf>private _weaponHolder = createVehicle ["Weapon_Empty", getPosATL player, [], 0, "CAN_COLLIDE"];
_weaponHolder addWeaponCargo ["arifle_Katiba_F", 1];
hint "You have 5 seconds to grab this weapon";
sleep 5;
deleteVehicle _weaponHolder;</sqf>


</dd>
|seealso= [[createVehicleLocal]] [[create3DENEntity]] [[createVehicleCrew]] [[createAgent]] [[createTrigger]] [[createUnit]] [[createMine]] [[deleteVehicle]] [[createGroup]] [[createCenter]] [[setVehiclePosition]]
</dl>
}}
<!-- DISCONTINUE Notes -->


<!-- CONTINUE Notes -->
{{Note
<dl class="command_description">
|user= MrSanchez
<dd class="notedate">Posted on December 1, 2015 - 16:46 (UTC)</dd>
|timestamp= 20150822130400
<dt class="note">[[User:Zectbumo|Zectbumo]]</dt>
|text= GroundWeaponHolder class is automatically deleted when empty after 0.5 to 1 seconds in A3 1.48. The exact delay is random but never lower than 0.50 secs after creation. You can stop deletion by adding something (cargo) to it within 0.5 seconds.
<dd class="note">The short syntax creates vehicles at ground level ignoring the Z in pos
}}
<code>"vehclass" createVehicle pos</code> This is equivalent to <code>createVehicle ["vehclass", [pos select 0, pos select 1, 0], [], 0, "NONE"]</code>
 
</dd>
{{Note
</dl>
|user= AgentRevolution
<!-- DISCONTINUE Notes -->
|timestamp= 20170516090500
|text= For the alternative syntax, if the vehicle has {{hl|c= canFloat = 1;}} in its config class (e.g. boats and wheeled APCs), the command expects [[Position#PositionAGL|PositionAGL]], and otherwise always [[Position#PositionATL|PositionATL]].
}}
 
{{Note
|user= demellion
|timestamp= 20181102121600
|text= '''WARNING:''' Do not instigate [[createVehicle]] or [[createVehicleLocal]] within a server function executed with [[Arma 3: Functions Library#Pre_and_Post_Init|preInit]] flag.<br>
This will cause ''"You cannot play/edit this mission"'' for a vehicles compiled from a [[Arma_3_Startup_Parameters|-mod]] and make server skip/loop that mission init.
}}
 
{{Note
|user= R3vo
|timestamp= 20190810091000
|text= The main syntax creates vehicles at ground level ignoring the Z in ''pos'' and is also faster than the alternative syntax.
<sqf>"vehclass" createVehicle pos;</sqf> This is equivalent to <sqf>createVehicle ["vehclass", [pos select 0, pos select 1, 0], [], 0, "NONE"];</sqf>
}}


<!-- CONTINUE Notes -->
{{Note
<dl class="command_description">
|user= DreadedEntity
<dd class="notedate">Posted on May 16, 2017 - 09:05 (UTC)</dd>
|timestamp= 20220313172236
<dt class="note">[[User:AgentRevolution|AgentRev]]</dt>
|text= Objects are created with a [[vectorUp]] of [[surfaceNormal|terrain surface normal]]. If you are creating new buildings to add to the map, you will probably want to call [[setVectorUp]] on the newly-spawned object.
<dd class="note">
<sqf>
For the alternative syntax, if the vehicle has <tt>canFloat = 1;</tt> in its config class (e.g. boats and wheeled APCs), the command expects [[PositionASLW]] if surface is water, and otherwise always [[PositionATL]].
_veh = createVehicle [etc...];
</dd>
_veh setVectorUp [0,0,1];
</dl>
</sqf>
<!-- DISCONTINUE Notes -->
}}

Revision as of 14:57, 22 May 2022

Hover & click on the images for description

Description

Description:
Creates an empty object of given classname type. See Arma 3 Assets / Arma 3: createVehicle/vehicles, or Category:CfgVehicles for earlier games.
Arma 3
To avoid vehicle randomisation in Arma 3, set the BIS_enableRandomization variable immediately after creating the vehicle:

private _vehicle = "C_Offroad_01_F" createVehicle position player; _vehicle setVariable ["BIS_enableRandomization", false];

Check Vehicle Customization (VhC) page for more information and settings.
Groups:
Object Manipulation

Syntax

Syntax:
type createVehicle position
Parameters:
type: String - vehicle/object className
position: Array format Position - desired placement position. If the exact position is occupied, nearest empty position is used.
Return Value:
Object

Alternative Syntax

Syntax:
createVehicle [type, position, markers, placement, special]
Parameters:
type: String - vehicle/object className
position: Object; Array format Position2D or PositionATL (PositionAGL if watercraft or amphibious) - desired placement position
markers: Array of Strings - (Optional, default []) if the markers array contains any markers, the position is randomly picked from array of given markers plus desired placement position. If any of the markers were given z coordinate with setMarkerPos, the vehicle will also be created at given z coordinate.
placement: Number - (Optional, default 0) the vehicle is placed inside a circle with given position as center and placement as its radius.
special: String - (Optional, default "NONE") can be one of the following:
  • "NONE" - will look for suitable empty position near given position (subject to other placement params) before placing vehicle there.
  • "CAN_COLLIDE" - places vehicle at given position (subject to other placement params), without checking if others objects can cross its 3D model.
  • "FLY" - if vehicle is capable of flying and has crew, it will be made airborne at default height.
If special is "" or not specified, default "NONE" is used.
Return Value:
Object - created vehicle or objNull if failed

Examples

Example 1:
_jeep = "Jeep" createVehicle position player;
Example 2:
_heli = "AH1Z" createVehicle getMarkerPos "hspawn";
Example 3:
_veh = createVehicle ["ah1w", position player, [], 0, "FLY"];
Example 4:
_veh = createVehicle ["2S6M_Tunguska", getMarkerPos "marker1", ["marker2", "marker3"], 0, "NONE"];
Example 5:
Objects such as
  • "test_EmptyObjectForBubbles"
  • "test_EmptyObjectForFireBig"
  • "test_EmptyObjectForSmoke"
create additional emitters, which are stored in "effects" variable on the object. Since Arma 3 v1.72 these emitters are automatically deleted when object is deleted
[] spawn { private _fire = "test_EmptyObjectForFireBig" createVehicle position player; sleep 5; deleteVehicle _fire; };
Example 6:
The following explosives (ending with _Scripted) can be set off by applying setDamage 1 to them for ease of scripting:
  • "DemoCharge_Remote_Ammo_Scripted"
  • "SatchelCharge_Remote_Ammo_Scripted"
  • "ClaymoreDirectionalMine_Remote_Ammo_Scripted"
_claymore = "ClaymoreDirectionalMine_Remote_Ammo_Scripted" createVehicle position player; _claymore spawn { sleep 5; _this setDamage 1; };
Example 7:
Add inventory to objects without inventory:
_boxes = "Land_Pallet_MilBoxes_F" createVehicle position player; _cargo = "Supply500" createVehicle [0,0,0]; _cargo attachTo [_boxes, [0,0,0.85]]; // optional for objects that can take damage _boxes addEventHandler ["Killed", { { detach _x, deleteVehicle _x; } forEach attachedObjects (_this select 0); }];
Example 8:
Drop player's weapon:
_wh = "GroundWeaponHolder_Scripted" createVehicle position player; player action ["DropWeapon", _wh, currentWeapon player];
Example 9:
The following weapon holders (ending with _Scripted) do not auto-delete when empty. It is up to the mission maker to take care of these:
  • "GroundWeaponHolder_Scripted"
  • "WeaponHolderSimulated_Scripted"
  • "Weapon_Empty" (a special weaponholder that displays only a single weapon, even if it contains magazines for this weapon)
private _weaponHolder = createVehicle ["Weapon_Empty", getPosATL player, [], 0, "CAN_COLLIDE"]; _weaponHolder addWeaponCargo ["arifle_Katiba_F", 1]; hint "You have 5 seconds to grab this weapon"; sleep 5; deleteVehicle _weaponHolder;

Additional Information

See also:
createVehicleLocal create3DENEntity createVehicleCrew createAgent createTrigger createUnit createMine deleteVehicle createGroup createCenter setVehiclePosition

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note
MrSanchez - c
Posted on Aug 22, 2015 - 13:04 (UTC)
GroundWeaponHolder class is automatically deleted when empty after 0.5 to 1 seconds in A3 1.48. The exact delay is random but never lower than 0.50 secs after creation. You can stop deletion by adding something (cargo) to it within 0.5 seconds.
AgentRevolution - c
Posted on May 16, 2017 - 09:05 (UTC)
For the alternative syntax, if the vehicle has canFloat = 1; in its config class (e.g. boats and wheeled APCs), the command expects PositionAGL, and otherwise always PositionATL.
demellion - c
Posted on Nov 02, 2018 - 12:16 (UTC)
WARNING: Do not instigate createVehicle or createVehicleLocal within a server function executed with preInit flag.
This will cause "You cannot play/edit this mission" for a vehicles compiled from a -mod and make server skip/loop that mission init.
R3vo - c
Posted on Aug 10, 2019 - 09:10 (UTC)
The main syntax creates vehicles at ground level ignoring the Z in pos and is also faster than the alternative syntax.
"vehclass" createVehicle pos;
This is equivalent to
createVehicle ["vehclass", [pos select 0, pos select 1, 0], [], 0, "NONE"];
DreadedEntity - c
Posted on Mar 13, 2022 - 17:22 (UTC)
Objects are created with a vectorUp of terrain surface normal. If you are creating new buildings to add to the map, you will probably want to call setVectorUp on the newly-spawned object.
_veh = createVehicle [etc...]; _veh setVectorUp [0,0,1];