createAgent: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(format)
m (Text replacement - "(\|[pr][0-9]+ *= *[^- ]*) *- *P([a-gi-z ])" to "$1 - p$2")
 
(104 intermediate revisions by 10 users not shown)
Line 1: Line 1:
{{Command|= Comments
{{RV|type=command
____________________________________________________________________________________________


| arma2 |= Game name
|game1= arma2
|version1= 1.00


|1.00|= Game version
|game2= arma2oa
____________________________________________________________________________________________
|version2= 1.50


| Creates an (independent) agent (person) of the given type (type is a name of a subclass of CfgVehicles). If the markers array contains several marker names, the position of a random one is used, otherwise, the given position is used. The unit is placed inside a circle with this position as its center and placement as its radius.
|game3= tkoh
|version3= 1.00


Players assigned to an agent using [[setPlayable]] will be able to control the agent, operate weapons and other actions, but will not be able to access their inventory using the gear screen.
|game4= arma3
|version4= 0.50


Special properties can be: "NONE" and "FORM". |= Description
|eff= global
____________________________________________________________________________________________


| [[Object]] <nowiki>=</nowiki> '''createAgent''' [type, position, markers, placement, special] |= Syntax
|gr1= Object Manipulation


|p1= [type, position, markers, placement, special]: [[Array]] |= Parameter 1
|descr= Creates an agent of the given type. An agent does not have a group or leader or the standard soldier [[FSM]] associated with it - for instance, an enemy soldier spawned as an agent has limited AI and will do nothing when fired upon - which can be useful to limit the amount of AI processing being done in a mission with very large numbers of "AI". Animals are also commonly created as agents.
|p2= type: [[String]] from CfgVehicles |= Parameter 2
{{Feature|informative|
|p3= position: [[Array]] ([[Position]] format)|= Parameter 3
* Players assigned to an agent using [[selectPlayer]] will be able to control the agent, operate weapons and other actions, but will not be able to access their inventory using the gear screen.
|p4= markers: [[Array]] |= Parameter 4
* To create objects of type {{hl|"Logic"}}, use [[createUnit]].
|p5= placement: [[Number]] radius |= Parameter 5
}}
|p6= special: [[String]] "None", or "Form" |= Parameter 6
 
|s1= [[createAgent]] [type, position, markers, placement, special]
 
|p1= type: [[String]] - class from [[CfgVehicles]]
 
|p2= position: [[Object]] or [[Array]] format [[Position#PositionAGL|PositionAGL]] or [[Position#Introduction|Position2D]] - desired placement position
 
|p4= 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.


| [[Object]] |= Return value
|p5= placement: [[Number]] - placement radius, the unit is randomly place in a circle with this radius
____________________________________________________________________________________________
 
|x1= <code>agent = [[createAgent]] ["SoldierWB", [[position]] [[player]], [], 0, "FORM"];</code> |= Example 1
____________________________________________________________________________________________


| [[agent]], [[agents]], [[isAgent]], [[forEachMemberAgent]] |= See also
|p6= special: [[String]] - one of:
* {{hl|"NONE"}} - will look for a suitable empty position near given position (subject to other placement params) before creating the agent
* {{hl|"CAN_COLLIDE"}} - creates the agent at given position (subject to other placement params), without checking if others objects can cross its 3D model


}}
|r1= [[Object]]


<h3 style="display:none">Notes</h3>
|x1= <sqf>private _agent = createAgent ["B_Soldier_F", getPosATL player, [], 0, "NONE"];</sqf>
<dl class="command_description">
<!-- Note Section BEGIN -->
<!-- Note Section END -->
</dl>


<h3 style="display:none">Bottom Section</h3>
|x2= <sqf>private _agent = createAgent ["Snake_random_F", ASLToAGL getPosASL player, [], 0, "CAN_COLLIDE"]; // Creates a snake at player's feet</sqf>


[[Category:Scripting Commands|CREATEAGENT]]
|seealso= [[agent]] [[agents]] [[isAgent]] [[forEachMemberAgent]] [[execFSM]] [[BIS_fnc_execFSM]]
[[Category:Scripting Commands ArmA|CREATEAGENT]]
}}
[[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 -->
{{Note
<dl class="command_description">
|user= Killzone_Kid
<dd class="notedate">Posted on September 29, 2014 - 20:03 (UTC)</dd>
|timestamp= 20140929200300
<dt class="note">[[User:Killzone Kid|Killzone Kid]]</dt>
|text= In {{arma3}}, default FSM is calling [[BIS_fnc_animalBehaviour]] script upon agent creation, which takes on some animal behavioural logic. The problem here is that it is almost impossible to make animal do what is told. Until now. Since {{arma3}} v1.32 you can set ''BIS_fnc_animalBehaviour_disable'' variable on the agent at the moment of agent creation, to override the function.
<dd class="note">
In Arma 3, default FSM is calling [[BIS_fnc_animalBehaviour]] script upon agent creation, which takes on some animal behavioural logic. The problem here is that it is almost impossible to make animal do what is told. Until now. Since Arma 3 v1.31.127383 you can set ''BIS_fnc_animalBehaviour_disable'' variable on the agent at the moment of agent creation, to override the function.


<code>tr = [[createTrigger]] ["EmptyDetector", [[player]] [[modelToWorld]] [0, 10, 0]];
<sqf>
tr [[setTriggerArea]] [5, 5, 0, [[true]]];
tr = createTrigger ["EmptyDetector", player modelToWorld [0, 10, 0]];
tr [[setTriggerActivation]] ["CIV", "PRESENT", true];
tr setTriggerArea [5, 5, 0, true];
tr setTriggerActivation ["CIV", "PRESENT", true];
rabbits = [];
rabbits = [];
[[private]] "_r";
private "_r";
[[for]] "_i" [[from]] 1 [[to]] 10 [[do]] {
for "_i" from 1 to 10 do {
_r = [[createAgent]] ["Rabbit_F", [[position]] tr, [], 0, "NONE"];
_r = createAgent ["Rabbit_F", position tr, [], 0, "NONE"];
_r [[setVariable]] ["BIS_fnc_animalBehaviour_disable", [[true]]];
_r setVariable ["BIS_fnc_animalBehaviour_disable", true];
rabbits [[pushBack]] _r;  
rabbits pushBack _r;
};
};
tr [[setTriggerStatements]] [
tr setTriggerStatements [
"[[if]] (rabbits [[isEqualTo]] thisList) [[exitWith]] {
"if (rabbits isEqualTo thisList) exitWith {
_r = thisList [[select]] [[floor]] [[random]] [[count]] thisList;
_r = thisList select floor random count thisList;
_r [[moveTo]] (_r [[modelToWorld]] [2.5 - [[random]] 5, 2.5 - [[random]] 5, 0]);
_r moveTo (_r modelToWorld [2.5 - random 5, 2.5 - random 5, 0]);
};
};
_esc = rabbits - thisList;
_esc = rabbits - thisList;
[[doStop]] _esc;
doStop _esc;
{_x [[moveTo]] [[position]] thisTrigger} [[forEach]] _esc;
{_x moveTo position thisTrigger} forEach _esc;
[[systemChat]] [[str]] <nowiki>[</nowiki>[[time]], _esc];
systemChat str [time, _esc];
[[false]]",
false",
"",
"",
""
""
];</code>  
];
</dd>
</sqf>  
</dl>
}}
<!-- DISCONTINUE Notes -->
 
{{Note
|user= Waffle SS.
|timestamp= 20150418071700
|text= Agents seem to use the same collision model that the player uses, unlike normal AI. Normal AI don't collide with objects, but agents are physically stopped by obstacles the same way players are. This also probably means agents cost more resources than normal AI.
}}

Latest revision as of 15:45, 8 November 2023

Hover & click on the images for description

Description

Description:
Creates an agent of the given type. An agent does not have a group or leader or the standard soldier FSM associated with it - for instance, an enemy soldier spawned as an agent has limited AI and will do nothing when fired upon - which can be useful to limit the amount of AI processing being done in a mission with very large numbers of "AI". Animals are also commonly created as agents.
  • Players assigned to an agent using selectPlayer will be able to control the agent, operate weapons and other actions, but will not be able to access their inventory using the gear screen.
  • To create objects of type "Logic", use createUnit.
Groups:
Object Manipulation

Syntax

Syntax:
createAgent [type, position, markers, placement, special]
Parameters:
type: String - class from CfgVehicles
position: Object or Array format PositionAGL or Position2D - desired placement position
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.
placement: Number - placement radius, the unit is randomly place in a circle with this radius
special: String - one of:
  • "NONE" - will look for a suitable empty position near given position (subject to other placement params) before creating the agent
  • "CAN_COLLIDE" - creates the agent at given position (subject to other placement params), without checking if others objects can cross its 3D model
Return Value:
Object

Examples

Example 1:
private _agent = createAgent ["B_Soldier_F", getPosATL player, [], 0, "NONE"];
Example 2:
private _agent = createAgent ["Snake_random_F", ASLToAGL getPosASL player, [], 0, "CAN_COLLIDE"]; // Creates a snake at player's feet

Additional Information

See also:
agent agents isAgent forEachMemberAgent execFSM BIS_fnc_execFSM

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
Killzone_Kid - c
Posted on Sep 29, 2014 - 20:03 (UTC)
In Arma 3, default FSM is calling BIS_fnc_animalBehaviour script upon agent creation, which takes on some animal behavioural logic. The problem here is that it is almost impossible to make animal do what is told. Until now. Since Arma 3 v1.32 you can set BIS_fnc_animalBehaviour_disable variable on the agent at the moment of agent creation, to override the function.
tr = createTrigger ["EmptyDetector", player modelToWorld [0, 10, 0]]; tr setTriggerArea [5, 5, 0, true]; tr setTriggerActivation ["CIV", "PRESENT", true]; rabbits = []; private "_r"; for "_i" from 1 to 10 do { _r = createAgent ["Rabbit_F", position tr, [], 0, "NONE"]; _r setVariable ["BIS_fnc_animalBehaviour_disable", true]; rabbits pushBack _r; }; tr setTriggerStatements [ "if (rabbits isEqualTo thisList) exitWith { _r = thisList select floor random count thisList; _r moveTo (_r modelToWorld [2.5 - random 5, 2.5 - random 5, 0]); }; _esc = rabbits - thisList; doStop _esc; {_x moveTo position thisTrigger} forEach _esc; systemChat str [time, _esc]; false", "", "" ];
Waffle SS. - c
Posted on Apr 18, 2015 - 07:17 (UTC)
Agents seem to use the same collision model that the player uses, unlike normal AI. Normal AI don't collide with objects, but agents are physically stopped by obstacles the same way players are. This also probably means agents cost more resources than normal AI.