createUnit: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(format)
(Page fix and comments cleanup)
Line 1: Line 1:
{{Command|= Comments
{{Command|Comments=
____________________________________________________________________________________________
____________________________________________________________________________________________


| ofp |= Game name
| ofp |Game name=


|1.34|= Game version
|1.34|Game version=


|eff= global |= Effects in MP
|eff= global |Effects in MP=
____________________________________________________________________________________________
____________________________________________________________________________________________


| Creates a unit of class that's defined in [[:Category:CfgVehicles|CfgVehicles]].<br><br>
| Create a unit of class that is defined in [[:Category:CfgVehicles|CfgVehicles]].
 
{{Important| <div style{{=}}"float: left; margin-right: 0.5em;">{{GVI|ofp|1.34}} {{GVI|arma|1.00}}</div>
{{Important|The <tt>group</tt> parameter '''MUST''' be an existing group or the unit won't be created}} |= Description
This command could be bugged in {{ofp}} or {{arma}} ; an additional [[join]] may solve the problem.<br />
However, some commands such as [[setUnitPos]] only work if run before the [[join]].}} |Description=
____________________________________________________________________________________________
____________________________________________________________________________________________


|group '''createUnit''' [type, position, markers, placement, special] |= Syntax
|group [[createUnit]] [type, position, markers, placement, special] |Syntax=


|p1= group: [[Group]] - Existing group new unit will join |= Parameter 1
|p1= group: [[Group]] - Existing group new unit will join {{Important|If ''group'' doesn't exist, the unit will '''not''' be created}} |Parameter 1=
|p2= [type, position, markers, placement, special]: [[Array]] |= Parameter 2
|p2= [type, position, markers, placement, special]: [[Array]] |Parameter 2=
|p3= type: [[String]] - Class name of unit to be created as per [[CfgVehicles]] |= Parameter 3
|p3= type: [[String]] - Class name of unit to be created as per [[CfgVehicles]] |Parameter 3=
|p4= position: [[Position]], [[Position2D]], [[Object]] or [[Group]] - Location unit is created at. In case of [[Group]] position of the [[group]] [[leader]] is used |= Parameter 4
|p4= position: [[Position]], [[Position2D]], [[Object]] or [[Group]] - Location unit is created at. In case of [[Group]] position of the [[group]] [[leader]] is used |Parameter 4=
|p5= markers: [[Array]] - Placement markers |= Parameter 5
|p5= markers: [[Array]] - Placement markers |Parameter 5=
|p6= placement: [[Number]] - Placement radius |= Parameter 6  
|p6= placement: [[Number]] - Placement radius |Parameter 6=
|p7= special: [[String]] - Unit placement special, one of:
|p7= special: [[String]] - Unit placement special, one of:
* <tt>"NONE"</tt> - The unit will be created at the first available free position nearest to given position
* <tt>"NONE"</tt> - The unit will be created at the first available free position nearest to given position
* <tt>"FORM"</tt> - The unit will be created in formation around the group leader, regardless of the passed position
* <tt>"FORM"</tt> - The unit will be created in formation around the group leader, regardless of the passed position
* <tt>"CAN_COLLIDE"</tt> - The unit will be created exactly at passed position
* <tt>"CAN_COLLIDE"</tt> - The unit will be created exactly at passed position
* <tt>"CARGO"</tt> - The unit will be created in cargo of the group's vehicle, regardless of the passed position. If group has no vehicle or there is no cargo space available, the unit will be placed according to <tt>"NONE"</tt>. To check available cargo space use:<code>_hasCargo = _veh [[emptyPositions]] "CARGO" > 0;</code>|= Parameter 7
* <tt>"CARGO"</tt> - The unit will be created in cargo of the group's vehicle, regardless of the passed position. If group has no vehicle or there is no cargo space available, the unit will be placed according to <tt>"NONE"</tt>. To check available cargo space use:<code>_hasCargo = _veh [[emptyPositions]] "CARGO" > 0;</code>|Parameter 7=


| {{Informative |[[Object]] - The reference to created unit }}|= Return value
| [[Object]] - The created unit |Return value=


|s2= type [[createUnit]] [position, group, init, skill, rank] |Syntax2=


| s2= type '''createUnit''' [position, group, init, skill, rank] |= Syntax
|p21= type: [[String]] - Class name of unit to be created as per [[CfgVehicles]] |Parameter 21=
|p22= [position, group, init, skill, rank]: [[Array]] |Parameter 22=
|p23= position: [[Position]], [[Position2D]], [[Object]] or [[Group]] - Location unit is created at. In case of [[Group]] position of the [[group]] [[leader]] is used |Parameter 23=
|p24= group: [[Group]] - Existing group new unit will join |Parameter 24=
|p25= init: [[String]] - (Optional, default "") Command to be executed '''locally''' upon creation of the unit. Parameter [[this]] is set to the created unit and passed to the code. |Parameter 25=
|p26= skill: [[Number]] - (Optional, default 0.5) Unit [[skill]] |Parameter 26=
|p27= rank: [[String]] - (Optional, default "PRIVATE") Unit [[rank]] |Parameter 27=


|p21= type: [[String]] - Class name of unit to be created as per [[CfgVehicles]] |= Parameter 1
|r2= {{Warning|'''[[Nothing]]''' - This syntax does NOT return a unit reference!<br />
|p22= [position, group, init, skill, rank]: [[Array]] |= Parameter 2
In order to reference this unit, you can use {{Inline code|newUnit {{=}} this}} in the ''init'' field}}|Return value 2=
|p23= position: [[Position]], [[Position2D]], [[Object]] or [[Group]] - Location unit is created at. In case of [[Group]] position of the [[group]] [[leader]] is used |= Parameter 3
|p24= group: [[Group]] - Existing group new unit will join |= Parameter 4
|p25= init (Optional): [[String]] - Command to be executed upon creation of unit. Parameter [[this]] is set to the created unit and passed to the code. Default: "" |= Parameter 5
|p26= skill (Optional): [[Number]] - Unit [[skill]]. Default: 0.5 |= Parameter 6
|p27= rank (Optional): [[String]] - Unit [[rank]]. Default: [[rank|PRIVATE]] |= Parameter 7
 
| r2= {{Warning| [[Nothing]] - THIS SYNTAX RETURNS NO UNIT REFERENCE!}}|= Return value
 
|mp=  |=
____________________________________________________________________________________________
____________________________________________________________________________________________


|x1= <code>_unit = [[group]] [[player]] [[createUnit]] ["B_RangeMaster_F", [[position]] [[player]], [], 0, "FORM"];</code>|=
|x1= <code>_unit = [[group]] [[player]] [[createUnit]] ["B_RangeMaster_F", [[position]] [[player]], [], 0, "FORM"];</code>|Example 1=
|x2= <code>"B_RangeMaster_F" [[createUnit]] <nowiki>[</nowiki>[[position]] [[player]], [[group]] [[player]]];</code> |= Example 1
|x2= <code>"B_RangeMaster_F" [[createUnit]] <nowiki>[</nowiki>[[position]] [[player]], [[group]] [[player]]];</code> |Example 2=
|x3= <code>"B_RangeMaster_F" [[createUnit]] <nowiki>[</nowiki>[[getMarkerPos]] "barracks", _groupAlpha];</code> |= Example 2
|x3= <code>"B_RangeMaster_F" [[createUnit]] <nowiki>[</nowiki>[[getMarkerPos]] "barracks", _groupAlpha];</code> |Example 3=
|x4= <code>"B_RangeMaster_F" [[createUnit]] <nowiki>[</nowiki>[[getMarkerPos]] "marker_1", _groupAlpha, "loon1 = this;
|x4= <code>"B_RangeMaster_F" [[createUnit]] [
this [[addWeapon]] 'BAF_L85A2_RIS_SUSAT'", 0.6, "corporal"];</code> |= Example 3
[[getMarkerPos]] "marker_1",
_groupAlpha,
"loon1 = [[this]]; [[this]] [[addWeapon]] 'BAF_L85A2_RIS_SUSAT'",
0.6,
"corporal"
];</code> |Example 4=
____________________________________________________________________________________________
____________________________________________________________________________________________


| [[createCenter]], [[createGroup]], [[createVehicle]], [[setVehiclePosition]] |= See also
| [[createCenter]], [[createGroup]], [[createVehicle]], [[setVehiclePosition]] |See also=
 
}}
}}


<h3 style="display:none">Notes</h3>
[[Category:Scripting Commands|{{uc:{{PAGENAME}}}}]]
<dl class="command_description">
[[Category:Scripting Commands OFP 1.46|{{uc:{{PAGENAME}}}}]]
<!-- Note Section BEGIN -->
[[Category:Scripting Commands OFP 1.96|{{uc:{{PAGENAME}}}}]]
<dd class="notedate">Posted on August 13, 2006 - 12:32
[[Category:Scripting Commands OFP 1.99|{{uc:{{PAGENAME}}}}]]
<dt class="note">'''[[User:Raedor|raedor]]'''<dd class="note">To give a newly created unit a name, put "newUnit = this" in the init field.
[[Category:Scripting Commands ArmA|{{uc:{{PAGENAME}}}}]]
<dd class="notedate">Posted on 18:41, 5 April 2007 (CEST)
<dt class="note">'''[[User:Shuko|Shuko]]'''<dd class="note">The eventhandlers added with [[addEventHandler]] in the init parameter will only fire locally on the machine where this creation command is called from.
<dd class="notedate">Posted on December 24, 2007 - 00:33
<dt class="note">'''[[User:MulleDK13|MulleDK13]]'''<dd class="note">If you do not wish it to be in a group, you can create a gamelogic and group it to that.<br>Note: The unit will deny to move away from the gamelogic.
<!-- Note Section END -->
</dl>
 
<h3 style="display:none">Bottom Section</h3>
 
[[Category:Scripting Commands|CREATEUNIT]]
[[Category:Scripting Commands OFP 1.99|CREATEUNIT]]
[[Category:Scripting Commands OFP 1.96|CREATEUNIT]]
[[Category:Scripting Commands OFP 1.46|CREATEUNIT]]
[[Category:Scripting Commands ArmA|CREATEUNIT]]
[[Category:Scripting Commands ArmA2|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands ArmA2|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting_Commands_Take_On_Helicopters|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting_Commands_Take_On_Helicopters|{{uc:{{PAGENAME}}}}]]
[[Category:Command_Group:_Object_Manipulation|{{uc:{{PAGENAME}}}}]]
[[Category:Command_Group:_Object_Manipulation|{{uc:{{PAGENAME}}}}]]


<!-- CONTINUE Notes -->
<h3 style="display:none">Notes</h3>
<dl class="command_description">
<dl class="command_description">
<dd class="notedate">Posted on August 27, 2015 - 02:25 (UTC)</dd>
<dt class="note">[[User:Austin medic|Austin medic]]</dt>
<dd class="note">
In order to solve the above problem you can simply group it to the game logic as stated, then group it to [[grpNull]]
<br>
<br>
e.g
<code>myUnit [[join]] myGroupLogic;
myUnit [[join]] [[grpNull]]
</code>
</dd>
<!-- Note Section BEGIN -->
<!-- Note Section BEGIN -->
<dd class="notedate">Posted on 21 December 2006
<dt class="note">'''[[User:Sbsmac|Sbsmac]]'''<dd class="note">
Although this command takes a group as an argument, you need to use the [[join]] command if you want the created units to perform actions such as [[move]].  For example:
<code> [[comment]] "Create a new soldier within 100m of the player and cause them to run towards the player" ;
_grp = [[createGroup]] [[west]];
unit = _grp [[createUnit]] ["SoldierWB", [[position]] [[player]], [], 100, "FORM"] ; 
[unit] [[join]] _grp ;
unit [[move]] [[position]] [[player]] ;
</code>
However, some commands such as [[setUnitPos]] only work if run before the [[join]].
<dd class="notedate">Posted on 11 March 2011
<dt class="note">'''[[User:kju|kju]]'''<dd class="note">
Comment above about 'an additional join required' is no longer true for Operation Arrowhead.
<dd class="notedate">Posted on 27th Nov 2016
<dd class="notedate">Posted on 27th Nov 2016
<dt class="note">'''[[User:Ffur2007slx2_5|Ffur2007slx2_5]]'''<dd class="note">
<dt class="note">[[User:Ffur2007slx2_5|Ffur2007slx2_5]]
(A3 v1.64)The side of created unit by this command fallows the fraction from its config and won’t be affected by the side of the passed group parameter which is created by [[createGroup]] on the fly without entities.
<dd class="note">
<code>
{{GVI|arma3|1.64}} The side of the created unit by this command uses its config's side and not the side of a passed empty group created by [[createGroup]]:
_grp = [[createGroup]] [[east]]; // O Alpha 1-1
<code>_grp = [[createGroup]] [[east]];
[[hint]] [[str]] [[side]] _grp; {{codecomment|// EAST}}
_ap = _grp [[createUnit]] [ “C_man_p_beggar_F”, [[position]] [[player]], [], 0, "FORM"];
_ap = _grp [[createUnit]] [ “C_man_p_beggar_F”, [[position]] [[player]], [], 0, "FORM"];
//the side of _ap is still CIV not EAST.
[[hint]] [[str]] [[side]] _ap; {{codecomment|// CIV, not EAST}}</code>
</code>
We can use [[join]] command or fill the _grp with entities in advance to set _ap to the desired side.
We can use [[join]] command family or fill the _grp with entities in advance to set _ap to our desired side.


<dd class="notedate">Posted on 8th Dec 2018
<dd class="notedate">Posted on 8th Dec 2018
<dt class="note">'''[[User:oOKexOo|oOKexOo]]'''<dd class="note">
<dt class="note">[[User:oOKexOo|oOKexOo]]
Since 1.86: If you want to place a module with [[createUnit]], you have to ensure that the module gets activated automatically by setting [[BIS_fnc_initModules_disableAutoActivation]] to [[false]].<br>
<dd class="note">
''e.g.'' for ModuleSmokeWhite_F:
Since {{GVI|arma3|1.86}}: If you want to place a module with [[createUnit]], you have to ensure that the module gets activated automatically by setting '''[[BIS_fnc_initModules]]_disableAutoActivation''' to [[false]], ''e.g'':
<code>
<code>[[private]] _grp = [[createGroup]] [[sideLogic]];
[[private]] _grp = [[createGroup]] [[sideLogic]];
"ModuleSmokeWhite_F" [[createUnit]] [
"ModuleSmokeWhite_F" [[createUnit]] [ [[getPos]] [[player]], _grp, "[[this]] [[setVariable]] ['BIS_fnc_initModules_disableAutoActivation', [[false]], [[true]]]; myModule = [[this]]"];
[[getPos]] [[player]],
</code>
_grp,
"[[this]] [[setVariable]] ['BIS_fnc_initModules_disableAutoActivation', [[false]], [[true]]];"
];</code>


<!-- Note Section END -->
<!-- Note Section END -->
</dl>
</dl>
<!-- DISCONTINUE Notes -->

Revision as of 18:21, 9 January 2019

Hover & click on the images for description

Description

Description:
Create a unit of class that is defined in CfgVehicles.
Logo A0.png1.34 -wrong parameter ("Arma") defined!-1.00

This command could be bugged in Operation Flashpoint or Arma ; an additional join may solve the problem.

However, some commands such as setUnitPos only work if run before the join.
Groups:
Uncategorised

Syntax

Syntax:
group createUnit [type, position, markers, placement, special]
Parameters:
group: Group - Existing group new unit will join
If group doesn't exist, the unit will not be created
[type, position, markers, placement, special]: Array
type: String - Class name of unit to be created as per CfgVehicles
position: Position, Position2D, Object or Group - Location unit is created at. In case of Group position of the group leader is used
markers: Array - Placement markers
placement: Number - Placement radius
special: String - Unit placement special, one of:
  • "NONE" - The unit will be created at the first available free position nearest to given position
  • "FORM" - The unit will be created in formation around the group leader, regardless of the passed position
  • "CAN_COLLIDE" - The unit will be created exactly at passed position
  • "CARGO" - The unit will be created in cargo of the group's vehicle, regardless of the passed position. If group has no vehicle or there is no cargo space available, the unit will be placed according to "NONE". To check available cargo space use:_hasCargo = _veh emptyPositions "CARGO" > 0;
Return Value:
Object - The created unit

Alternative Syntax

Syntax:
type createUnit [position, group, init, skill, rank]
Parameters:
type: String - Class name of unit to be created as per CfgVehicles
[position, group, init, skill, rank]: Array
position: Position, Position2D, Object or Group - Location unit is created at. In case of Group position of the group leader is used
group: Group - Existing group new unit will join
init: String - (Optional, default "") Command to be executed locally upon creation of the unit. Parameter this is set to the created unit and passed to the code.
skill: Number - (Optional, default 0.5) Unit skill
rank: String - (Optional, default "PRIVATE") Unit rank
Return Value:
Nothing - This syntax does NOT return a unit reference!
In order to reference this unit, you can use newUnit = this in the init field

Examples

Example 1:
_unit = group player createUnit ["B_RangeMaster_F", position player, [], 0, "FORM"];
Example 2:
"B_RangeMaster_F" createUnit [position player, group player];
Example 3:
"B_RangeMaster_F" createUnit [getMarkerPos "barracks", _groupAlpha];
Example 4:
"B_RangeMaster_F" createUnit [ getMarkerPos "marker_1", _groupAlpha, "loon1 = this; this addWeapon 'BAF_L85A2_RIS_SUSAT'", 0.6, "corporal" ];

Additional Information

See also:
createCentercreateGroupcreateVehiclesetVehiclePosition

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

Notes

Posted on 27th Nov 2016
Ffur2007slx2_5
Arma 3 logo black.png1.64 The side of the created unit by this command uses its config's side and not the side of a passed empty group created by createGroup: _grp = createGroup east; hint str side _grp; // EAST _ap = _grp createUnit [ “C_man_p_beggar_F”, position player, [], 0, "FORM"]; hint str side _ap; // CIV, not EAST We can use join command or fill the _grp with entities in advance to set _ap to the desired side.
Posted on 8th Dec 2018
oOKexOo
Since Arma 3 logo black.png1.86: If you want to place a module with createUnit, you have to ensure that the module gets activated automatically by setting BIS_fnc_initModules_disableAutoActivation to false, e.g: private _grp = createGroup sideLogic; "ModuleSmokeWhite_F" createUnit [ getPos player, _grp, "this setVariable ['BIS_fnc_initModules_disableAutoActivation', false, true];" ];