setUnitLoadout: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (fixed broken template)
No edit summary
 
(60 intermediate revisions by 6 users not shown)
Line 1: Line 1:
{{Command|Comments=  
{{RV|type=command
| arma3 |Game name=
 
|1.58|Game version=
|game1= arma3
|arg= global |Arguments=  in MP
|version1= 1.58
|eff= global |Effects= in MP
 
| Creates a loadout from given inventory structure and applies it to a unit. When [[String]] for class name is supplied, the command will search <tt>CfgVehicles</tt> for the given class in order to extract the loadout from config. If [[Config]] is given, it will search given config (including [[missionConfigFile | mission config]]) for the loadout information. In either case, the config should contain the following entries, which is standard for any unit class, for example:
|arg= global
<syntaxhighlight lang=cpp>
 
|eff= global
 
|gr1= Unit Inventory
 
|descr= Creates a loadout from given inventory structure and applies it to a unit.
When [[String]] for class name is supplied, the command will search {{hl|CfgVehicles}} for the given class in order to extract the loadout from config.
If [[Config]] is given, it will search given config (including [[missionConfigFile|mission config]]) for the loadout information.
In either case, the config should contain the following entries, which is standard for any unit class, for example:
<syntaxhighlight lang="cpp">
class MyLoadout
class MyLoadout
{
{
uniformClass = "U_B_CombatUniform_mcam";
uniformClass = "U_B_CombatUniform_mcam";
backpack = "B_AssaultPack_mcamo";
backpack = "B_AssaultPack_mcamo";
linkedItems[] = {"V_PlateCarrier1_rgr","H_HelmetB","ItemCompass","ItemWatch","ItemRadio","NVGoggles"};
linkedItems[] = { "V_PlateCarrier1_rgr", "H_HelmetB", "ItemCompass", "ItemWatch", "ItemRadio", "NVGoggles" };
weapons[] = {"arifle_MX_ACO_pointer_F","hgun_P07_F"};
weapons[] = { "arifle_MX_ACO_pointer_F", "hgun_P07_F" };
items[] = {"FirstAidKit","FirstAidKit","FirstAidKit"};
items[] = { "FirstAidKit", "FirstAidKit", "FirstAidKit" };
magazines[] = {"30Rnd_65x39_caseless_mag","16Rnd_9x21_Mag","SmokeShell","HandGrenade","HandGrenade","HandGrenade","HandGrenade","HandGrenade","HandGrenade","HandGrenade","HandGrenade","HandGrenade","HandGrenade","HandGrenade","HandGrenade","HandGrenade","HandGrenade","HandGrenade","HandGrenade","HandGrenade","HandGrenade","HandGrenade","HandGrenade","HandGrenade","HandGrenade","HandGrenade","HandGrenade"};
magazines[] = {
};</syntaxhighlight>
"30Rnd_65x39_caseless_mag", "16Rnd_9x21_Mag", "SmokeShell",
"HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade",
"HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade",
"HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade",
"HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade",
"HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade"
};
};
</syntaxhighlight>
 
{{Feature|important|Since {{GVI|arma3|2.20|size= 0.75}} if the command is executed while the unit is in the process of switching weapon, the command will be aborted. To check if unit is switching weapon use [[isSwitchingWeapon]].}}
 
|pr= {{Feature|important|If this command is used on the player, it makes the inventory window bug (if opened) - vest and backpack tabs disappear. Closing and re-opening the inventory solves the issue.}}
 
|s1= unit [[setUnitLoadout]] loadout
 
|p1= unit: [[Object]]
 
|p2= loadout: [[Array]] - [[Unit Loadout Array]]


| unit [[setUnitLoadout]] loadout|SYNTAX1=
|r1= [[Nothing]]
|p1= unit: [[Object]] |PARAMETER1=
|p2= loadout: [[Array]] - [[Unit Loadout Array]] |PARAMETER2=
| [[Nothing]] |RETURNVALUE1=


|s2= unit [[setUnitLoadout]] [loadout, fullMagazines]


| s2= unit [[setUnitLoadout]] [loadout, fullMagazines]|SYNTAX2=
|p21= unit: [[Object]]
|p21= unit: [[Object]] |PARAMETER21=
|p22=[loadout, fullMagazines] : [[Array]]|PARAMETER22=
|p23= loadout: [[Array]] - [[Unit Loadout Array]] |PARAMETER23=
|p24= fullMagazines: [[Boolean]] - Partially emptied magazines will be refilled when the loadout is applied|PARAMETER24=
| r2= [[Nothing]] |RETURNVALUE2=


|s3= unit [[setUnitLoadout]] name |SYNTAX3=
|p22= loadout: [[Array]] - [[Unit Loadout Array]]
|p41= unit: [[Object]] |PARAMETER41=
|p42= name: [[String]] - class name (see description)|PARAMETER42=


|r3= [[Nothing]] |RETURNVALUE3=
|p23= fullMagazines: [[Boolean]] - partially emptied magazines will be refilled when the loadout is applied


|s4= unit [[setUnitLoadout]] config |SYNTAX4=
|r2= [[Nothing]]
|p61= unit: [[Object]] |PARAMETER61=
|p62= config: [[Config]] - config class (see description) |PARAMETER62=


|r4= [[Nothing]] |RETURNVALUE4=
|s3= unit [[setUnitLoadout]] name


|x1= <code>player_2 [[setUnitLoadout]] ([[getUnitLoadout]] player_1); // Copies loadout from player_1 and applies it to player_2 </code>|EXAMPLE1=
|p41= unit: [[Object]]
|x2= <code>player_2 [[setUnitLoadout]] <nowiki>[</nowiki>[[getUnitLoadout]] player_1, [[true]]]; // Copies loadout from player_1 and applies it to player_2 while topping up all magazines</code>|EXAMPLE2=
|x3= <code>_unit [[setUnitLoadout]] "B_Soldier_F";</code>|EXAMPLE3=
|x4= <code>_unit [[setUnitLoadout]] ([[configFile]] >> "CfgVehicles" >> "B_Soldier_F");</code>|EXAMPLE4=
|x5= <code>_unit [[setUnitLoadout]] ([[missionConfigFile]] >> "MyLoadout");</code>|EXAMPLE5=
|x6= Strip unit of everything (after Arma 3 v1.93):<code>_unit [[setUnitLoadout]] ([[configFile]] >> "EmptyLoadout");</code>|EXAMPLE6=


| [[getUnitLoadout]]|SEEALSO=  
|p42= name: [[String]] - class name (see description)
| |MPBEHAVIOUR=  
 
}}
|r3= [[Nothing]]
 
|s4= unit [[setUnitLoadout]] config
 
|p61= unit: [[Object]]
 
|p62= config: [[Config]] - config class (see description)
 
|r4= [[Nothing]]
 
|x1= <sqf>
_unit setUnitLoadout "B_Soldier_F"; // by class name
_unit setUnitLoadout (configFile >> "CfgVehicles" >> "B_Soldier_F"); // by config entry
_unit setUnitLoadout (missionConfigFile >> "MyLoadout"); // (also works for mission config)
_unit setUnitLoadout getUnitLoadout _otherUnit; // by loadout array
</sqf>
 
|x2= <sqf>
player_2 setUnitLoadout (getUnitLoadout player_1); // Copies loadout from player_1 and applies it to player_2
player_2 setUnitLoadout [getUnitLoadout player_1, true]; // Copies loadout from player_1 and applies it to player_2 while topping up all magazines
</sqf>
 
|x3= Strip unit of everything:
<sqf>_unit setUnitLoadout (configFile >> "EmptyLoadout");</sqf>


<h3 style='display:none'>Bottom Section</h3>
|x4= Make sure the unit is not switching weapon:
[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]]
<sqf>player spawn
[[Category:Scripting Commands|{{uc:{{PAGENAME}}}}]]
{
[[Category:Arma_3:_New_Scripting_Commands_List|{{uc:{{PAGENAME}}}}]]
waitUntil {!isSwitchingWeapon _this};
_this setUnitLoadout (configFile >> "EmptyLoadout");
};</sqf>


<h3 style='display:none'>Notes</h3>
<dl class="command_description">
<!-- BEGIN Note Section -->
<!-- END Note Section -->
</dl>


<h3 style="display:none">Bottom Section</h3>
|seealso= [[getUnitLoadout]] [[isSwitchingWeapon]]
}}


<!-- CONTINUE Notes -->
{{Note
<dl class="command_description">
|user= Demellion
<dd class="notedate">Posted on December 17, 2019 - 23:08 (UTC)</dd>
|timestamp= 20191217230800
<dt class="note">[[User:demellion|demellion]]</dt>
|text= Empty or used magazines in loadouts will be refilled under specific circumstance, even if the refill argument is [[false]]. This seems to happen if amount of used magazines is 2 or more.
<dd class="note">
<sqf>
'''NOTE:''' Empty or used magazines in loadouts will be refilled under specific circumstance, even if the refill argument is [[false]]. This seems to happen if amount of used magazines is 2 or more.
player setUnitLoadout [
<code>player setUnitLoadout [
["arifle_MX_ACO_pointer_F", "", "acc_pointer_IR", "optic_Aco", [], [], ""],
["arifle_MX_ACO_pointer_F","","acc_pointer_IR","optic_Aco",[],[],""],
[],
[],
["hgun_P07_F","","","",["16Rnd_9x21_Mag",16],[],""],
["hgun_P07_F", "", "", "", ["16Rnd_9x21_Mag", 16], [], ""],
["U_B_CombatUniform_mcam",[ ["30Rnd_65x39_caseless_mag",1,1] ]],
["U_B_CombatUniform_mcam", [["30Rnd_65x39_caseless_mag", 1, 1]]],
["V_PlateCarrier1_rgr",[]],
["V_PlateCarrier1_rgr", []],
["B_AssaultPack_mcamo_Ammo",[]],
["B_AssaultPack_mcamo_Ammo", []],
"H_HelmetB_grass","",[],["ItemMap","","ItemRadio","ItemCompass","ItemWatch","NVGoggles"]
"H_HelmetB_grass", "", [], ["ItemMap", "", "ItemRadio", "ItemCompass", "ItemWatch", "NVGoggles"]
]</code>
];
</sqf>
 
Will result in 30Rnd magazine with one bullet in it.
Will result in 30Rnd magazine with one bullet in it.
<code>player setUnitLoadout [
<sqf>
["arifle_MX_ACO_pointer_F","","acc_pointer_IR","optic_Aco",[],[],""],
player setUnitLoadout [
["arifle_MX_ACO_pointer_F", "", "acc_pointer_IR", "optic_Aco", [], [], ""],
[],
[],
["hgun_P07_F","","","",["16Rnd_9x21_Mag",16],[],""],
["hgun_P07_F", "", "", "", ["16Rnd_9x21_Mag", 16], [], ""],
["U_B_CombatUniform_mcam",[ ["30Rnd_65x39_caseless_mag",2,1] ]],
["U_B_CombatUniform_mcam", [["30Rnd_65x39_caseless_mag", 2, 1]]],
["V_PlateCarrier1_rgr",[]],
["V_PlateCarrier1_rgr", []],
["B_AssaultPack_mcamo_Ammo",[]],
["B_AssaultPack_mcamo_Ammo", []],
"H_HelmetB_grass","",[],["ItemMap","","ItemRadio","ItemCompass","ItemWatch","NVGoggles"]
"H_HelmetB_grass", "", [], ["ItemMap", "", "ItemRadio", "ItemCompass", "ItemWatch", "NVGoggles"]
]</code>
];
Will result in 2 magazines but full, 30 rounds in it. This applies to any magazines count >2. They will never be with specified amount of rounds, even if you force the refill argument to [[false]]
</sqf>
</dd>
Will result in 2 magazines but full, 30 rounds in it. This applies to any magazines count >2. They will never be with specified amount of rounds, even if you force the refill argument to [[false]].
</dl>
}}
<!-- DISCONTINUE Notes -->
 
{{Note
|user= Andrew_S90
|timestamp= 20201023211600
|text= Here is a command I wrote up that provides a fix for the ammo bug described by Demellion above.
https://pastebin.com/SHX41Jkk
Pass a loadout to your compiled command and it will provide one back that will not refill ammo.
}}
 
{{Note
|user= POLPOX
|timestamp= 20220823082709
|text= <sqf>
player setUnitLoadout [
nil, nil, nil, nil, nil,
["B_Bergen_sgg", nil],
nil, nil, nil, nil
];
</sqf>
You can use [[nil]] to skip some desired parameter. The skipped part will be ignored and remain the same with old loadout.<br>
This method is ''very slightly'' faster than the latter method:
<sqf>
private _loadout = getUnitLoadout player;
_loadout#5 set [0, "B_Bergen_mcamo_F"];
player setUnitLoadout _loadout;
</sqf>
}}

Latest revision as of 00:29, 3 November 2024

Hover & click on the images for description

Description

Description:
Creates a loadout from given inventory structure and applies it to a unit. When String for class name is supplied, the command will search CfgVehicles for the given class in order to extract the loadout from config. If Config is given, it will search given config (including mission config) for the loadout information. In either case, the config should contain the following entries, which is standard for any unit class, for example:
class MyLoadout
{
	uniformClass = "U_B_CombatUniform_mcam";
	backpack = "B_AssaultPack_mcamo";
	linkedItems[] = { "V_PlateCarrier1_rgr", "H_HelmetB", "ItemCompass", "ItemWatch", "ItemRadio", "NVGoggles" };
	weapons[] = { "arifle_MX_ACO_pointer_F", "hgun_P07_F" };
	items[] = { "FirstAidKit", "FirstAidKit", "FirstAidKit" };
	magazines[] = {
		"30Rnd_65x39_caseless_mag", "16Rnd_9x21_Mag", "SmokeShell",
		"HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade",
		"HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade",
		"HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade",
		"HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade",
		"HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade"
	};
};
Since Arma 3 logo black.png2.20 if the command is executed while the unit is in the process of switching weapon, the command will be aborted. To check if unit is switching weapon use isSwitchingWeapon.
Problems:
If this command is used on the player, it makes the inventory window bug (if opened) - vest and backpack tabs disappear. Closing and re-opening the inventory solves the issue.
Groups:
Unit Inventory

Syntax 1

Syntax:
unit setUnitLoadout loadout
Parameters:
unit: Object
loadout: Array - Unit Loadout Array
Return Value:
Nothing

Syntax 2

Syntax:
unit setUnitLoadout [loadout, fullMagazines]
Parameters:
unit: Object
loadout: Array - Unit Loadout Array
fullMagazines: Boolean - partially emptied magazines will be refilled when the loadout is applied
Return Value:
Nothing

Syntax 3

Syntax:
unit setUnitLoadout name
Parameters:
unit: Object
name: String - class name (see description)
Return Value:
Nothing

Syntax 4

Syntax:
unit setUnitLoadout config
Parameters:
unit: Object
config: Config - config class (see description)
Return Value:
Nothing

Examples

Example 1:
_unit setUnitLoadout "B_Soldier_F"; // by class name _unit setUnitLoadout (configFile >> "CfgVehicles" >> "B_Soldier_F"); // by config entry _unit setUnitLoadout (missionConfigFile >> "MyLoadout"); // (also works for mission config) _unit setUnitLoadout getUnitLoadout _otherUnit; // by loadout array
Example 2:
player_2 setUnitLoadout (getUnitLoadout player_1); // Copies loadout from player_1 and applies it to player_2 player_2 setUnitLoadout [getUnitLoadout player_1, true]; // Copies loadout from player_1 and applies it to player_2 while topping up all magazines
Example 3:
Strip unit of everything:
_unit setUnitLoadout (configFile >> "EmptyLoadout");
Example 4:
Make sure the unit is not switching weapon:
player spawn { waitUntil {!isSwitchingWeapon _this}; _this setUnitLoadout (configFile >> "EmptyLoadout"); };

Additional Information

See also:
getUnitLoadout isSwitchingWeapon

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
Demellion - c
Posted on Dec 17, 2019 - 23:08 (UTC)
Empty or used magazines in loadouts will be refilled under specific circumstance, even if the refill argument is false. This seems to happen if amount of used magazines is 2 or more.
player setUnitLoadout [ ["arifle_MX_ACO_pointer_F", "", "acc_pointer_IR", "optic_Aco", [], [], ""], [], ["hgun_P07_F", "", "", "", ["16Rnd_9x21_Mag", 16], [], ""], ["U_B_CombatUniform_mcam", [["30Rnd_65x39_caseless_mag", 1, 1]]], ["V_PlateCarrier1_rgr", []], ["B_AssaultPack_mcamo_Ammo", []], "H_HelmetB_grass", "", [], ["ItemMap", "", "ItemRadio", "ItemCompass", "ItemWatch", "NVGoggles"] ];
Will result in 30Rnd magazine with one bullet in it.
player setUnitLoadout [ ["arifle_MX_ACO_pointer_F", "", "acc_pointer_IR", "optic_Aco", [], [], ""], [], ["hgun_P07_F", "", "", "", ["16Rnd_9x21_Mag", 16], [], ""], ["U_B_CombatUniform_mcam", [["30Rnd_65x39_caseless_mag", 2, 1]]], ["V_PlateCarrier1_rgr", []], ["B_AssaultPack_mcamo_Ammo", []], "H_HelmetB_grass", "", [], ["ItemMap", "", "ItemRadio", "ItemCompass", "ItemWatch", "NVGoggles"] ];
Will result in 2 magazines but full, 30 rounds in it. This applies to any magazines count >2. They will never be with specified amount of rounds, even if you force the refill argument to false.
Andrew_S90 - c
Posted on Oct 23, 2020 - 21:16 (UTC)
Here is a command I wrote up that provides a fix for the ammo bug described by Demellion above. https://pastebin.com/SHX41Jkk Pass a loadout to your compiled command and it will provide one back that will not refill ammo.
POLPOX - c
Posted on Aug 23, 2022 - 08:27 (UTC)
player setUnitLoadout [ nil, nil, nil, nil, nil, ["B_Bergen_sgg", nil], nil, nil, nil, nil ];
You can use nil to skip some desired parameter. The skipped part will be ignored and remain the same with old loadout.
This method is very slightly faster than the latter method:
private _loadout = getUnitLoadout player; _loadout#5 set [0, "B_Bergen_mcamo_F"]; player setUnitLoadout _loadout;