createUnit: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(see also)
No edit summary
Line 14: Line 14:
____________________________________________________________________________________________
____________________________________________________________________________________________


| type '''createUnit''' [ position, group, init, skill, rank] |= Syntax
| type '''createUnit''' [position, group, init, skill, rank] |= Syntax
,init ([[String]]), skill ([[Number]]), rank ([[String]])]


|p1= type: [[String]] - Classname of unit to be created as per cfgVehicles |= Parameter 1
|p1= type: [[String]] - Class name of unit to be created as per [[CfgVehicles]] |= Parameter 1
|p2= [position, group, init, skill, rank]: [[Array]] |= Parameter 2
|p3= position: [[Position]], [[Position2D]] or [[Object]] - Location unit is created at |= Parameter 3
|p4= group: [[Group]] - Existing group new unit will join |= Parameter 4
|p5= 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
|p6= skill (Optional): [[Number]] - Unit [[skill]]. Default: 0.5 |= Parameter 6
|p7= rank (Optional): [[String]] - Unit [[rank]]. Default: [[rank|PRIVATE]] |= Parameter 7


|p2= [ position, group, init, skill, rank]: [[Array]] |= Parameter 2
| [[Nothing]] |= Return value
|p3= position: [[Position]], [[Position2D]] or [[Object]] - Location unit is created at. |= Parameter 3
 
|p4= group: [[Group]] - Existing group new unit will join. |= Parameter 4
| s2=group '''createUnit''' [type, position, markers, placement, special] |= Syntax
|p5= init: [[String]] - (optional, default "") Command to be executed upon creation of unit. Parameter [[this]] is set to the created unit and passed to the code. |= Parameter 5
 
|p6= skill: [[Number]] - (optional, default 0.5) |= Parameter 6
|p21= group: [[Group]] - Existing group new unit will join |= Parameter 1
|p7= [[rank]]: [[String]] - (optional, default "[[rank|PRIVATE]]") |= Parameter 7
|p22= [type, position, markers, placement, special]: [[Array]] |= Parameter 2
|p23= type: [[String]] - Class name of unit to be created as per [[CfgVehicles]] |= Parameter 3
|p24= position: [[Position]], [[Position2D]] or [[Object]] - Location unit is created at |= Parameter 4
|p25= markers: [[Array]] - Placement markers |= Parameter 5
|p26= placement: [[Number]] - Placement radius |= Parameter 6  
|p27= special: [[String]] - Unit placement special, one of <tt>"NONE", "FORM", "CAN_COLLIDE", "CARGO"</tt>  |= Parameter 7


| [[Nothing]] |= Return value
| r2= [[Object]] - reference to created unit |= Return value


|mp= The code in '''init''' is executed on all connected clients in multiplayer.
|mp= |=
It can therefore be used to get around the [[publicVariable]] limitation of not being able to send strings and arrays over the network. |=
____________________________________________________________________________________________
____________________________________________________________________________________________
   
   
|x1= <code>"SoldierWB" [[createUnit]] [ [[position]] [[player]], [[group]] [[player]] ];</code> |= Example 1
|x1= <code>"SoldierWB" [[createUnit]] <nowiki>[</nowiki>[[position]] [[player]], [[group]] [[player]]];</code> |= Example 1
|x2= <code>"soldierWB" [[createUnit]] [ [[getMarkerPos]] "barracks", _groupAlpha];</code> |= Example 2
|x2= <code>"soldierWB" [[createUnit]] <nowiki>[</nowiki>[[getMarkerPos]] "barracks", _groupAlpha];</code> |= Example 2
|x3= <code>"soldierWB" [[createUnit]] [ [[getMarkerPos]] "marker_1", _groupAlpha,"loon1 = this;
|x3= <code>"soldierWB" [[createUnit]] <nowiki>[</nowiki>[[getMarkerPos]] "marker_1", _groupAlpha, "loon1 = this;
  this [[addWeapon]] 'BAF_L85A2_RIS_SUSAT'", 0.6, "corporal"];</code> |= Example 3
  this [[addWeapon]] 'BAF_L85A2_RIS_SUSAT'", 0.6, "corporal"];</code> |= Example 3
|x4= <code>_unit = [[group]] [[player]] [[createUnit]] ["SoldierWB", [[position]] [[player]], [], 0, "FORM"];</code>|=
____________________________________________________________________________________________
____________________________________________________________________________________________


| [[createUnit array]], [[createCenter]], [[createGroup]], [[createVehicle]], [[setVehiclePosition]] |= See also
| [[createCenter]], [[createGroup]], [[createVehicle]], [[setVehiclePosition]] |= See also


}}
}}
Line 79: Line 89:
</code>
</code>
</dd>
</dd>
<!-- 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.
<!-- Note Section END -->
</dl>
</dl>
<!-- DISCONTINUE Notes -->
<!-- DISCONTINUE Notes -->

Revision as of 10:38, 30 August 2016

Hover & click on the images for description

Description

Description:
Create unit of a class that's defined in CfgVehicles. The Group parameter MUST be an existing group or the unit won't be created.
Groups:
Uncategorised

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 or Object - Location unit is created at
group: Group - Existing group new unit will join
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: ""
skill (Optional): Number - Unit skill. Default: 0.5
rank (Optional): String - Unit rank. Default: PRIVATE
Return Value:
Nothing

Alternative Syntax

Syntax:
group createUnit [type, position, markers, placement, special]
Parameters:
group: Group - Existing group new unit will join
[type, position, markers, placement, special]: Array
type: String - Class name of unit to be created as per CfgVehicles
position: Position, Position2D or Object - Location unit is created at
markers: Array - Placement markers
placement: Number - Placement radius
special: String - Unit placement special, one of "NONE", "FORM", "CAN_COLLIDE", "CARGO"
Return Value:
Object - reference to created unit

Examples

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

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 August 13, 2006 - 12:32
raedor
To give a newly created unit a name, put "newUnit = this" in the init field.
Posted on 18:41, 5 April 2007 (CEST)
Shuko
The eventhandlers added with addEventHandler in the init parameter will only fire locally on the machine where this creation command is called from.
Posted on December 24, 2007 - 00:33
MulleDK13
If you do not wish it to be in a group, you can create a gamelogic and group it to that.
Note: The unit will deny to move away from the gamelogic.

Bottom Section

Posted on August 27, 2015 - 02:25 (UTC)
Austin medic
In order to solve the above problem you can simply group it to the game logic as stated, then group it to grpNull

e.g myUnit join myGroupLogic; myUnit join grpNull
Posted on 21 December 2006
Sbsmac
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: 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 ; However, some commands such as setUnitPos only work if run before the join.
Posted on 11 March 2011
kju
Comment above about 'an additional join required' is no longer true for Operation Arrowhead.