-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPie_Helper_DynamicPlayerFaction.sqf
More file actions
272 lines (220 loc) · 9.79 KB
/
Pie_Helper_DynamicPlayerFaction.sqf
File metadata and controls
272 lines (220 loc) · 9.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
if(isServer) then
{
_missionSetupInteractionPoint = _this param [0, objNull];
_supplySetup = _this param [1, objNull];
_addArsenal = _this param [2, true];
if(_addArsenal) then
{
[_supplySetup, true] remoteExec ["ace_arsenal_fnc_initBox", 0, true];
["AmmoboxInit", [_supplySetup, true]] remoteExec ["BIS_fnc_arsenal", 0, true];
};
missionNamespace setVariable ["Pie_Mis_SelectedFaction", configFile >> "cfgFactionClasses" >> faction player, true];
[
_missionSetupInteractionPoint, ["Choose player faction", {
[] call Pie_fnc_DynPlayerFaction_ChooseFaction;
},
nil, 1.5, true, true, "", "true", 5]
] remoteExec ["addAction", 0, true];
[
_supplySetup, ["Choose loadout", {
[] call Pie_fnc_DynPlayerFaction_ChooseLoadout;
},
nil, 1.5, true, true, "", format ["missionNamespace getVariable ['Pie_Mis_SelectedPlayerFaction', ''] != ''"], 5]
] remoteExec ["addAction", 0, true];
};
Pie_fnc_DynPlayerFaction_ChooseFaction = {
if (!isMultiplayer || call BIS_fnc_admin != 0 || clientOwner == 2 || !isNull (getAssignedCuratorLogic player)) then {
_display = createDialog ["RscDisplayEmpty", true];
_instructionLabel = _display ctrlCreate ["RscText", -1];
_instructionLabel ctrlSetPosition [0, 0, 1, 0.04];
_instructionLabel ctrlSetText "Select a faction";
_instructionLabel ctrlCommit 0;
_factionDropdown = _display ctrlCreate ["RscCombo", 100];
_factionDropdown ctrlSetPosition [0, 0.08, 0.89, 0.04];
_factionDropdown ctrlCommit 0;
// Add a button to select a random faction
_factionRandomButton = _display ctrlCreate ["RscButton", -1];
_factionRandomButton ctrlSetPosition [0.93, 0.08, 0.04, 0.04];
_factionRandomButton ctrlSetText "";
_factionRandomButton ctrlSetBackgroundColor [0, 0, 0, 0];
_factionRandomButton ctrlSetTextColor [0, 0, 0, 0];
_factionRandomButton ctrlCommit 0;
_factionRandomButton ctrlAddEventHandler ["ButtonClick",
{
params ["_control"];
private _dropdownCtrl = (ctrlParent _control) displayCtrl 100;
private _count = lbSize _dropdownCtrl;
if (_count > 0) then {
private _randomIndex = floor random _count;
_dropdownCtrl lbSetCurSel _randomIndex;
};
}];
_factionRandomIcon = _display ctrlCreate ["RscPicture", -1];
_factionRandomIcon ctrlSetPosition [0.93, 0.08, 0.04, 0.04];
_factionRandomIcon ctrlSetText "\a3\ui_f\data\IGUI\Cfg\Actions\reammo_ca.paa";
_factionRandomIcon ctrlCommit 0;
_factionColours = [
[1, 0, 0, 1],
[0, 0, 1, 1],
[0, 1, 0, 1]
];
_factionList = [];
{
_displayName = getText (_x >> 'displayName');
if(_displayName != "" && _displayName != 'Other') then
{
_factionList pushBack [_displayName, _x];
};
} forEach (configProperties [configFile >> "cfgFactionClasses", "isClass _x && (getNumber (_x >> 'side')) <= 2", true]);
_factionList sort true;
{
_displayName = _x select 0;
_configEntry = _x select 1;
_item = _factionDropdown lbAdd _displayName;
_factionDropdown lbSetColor [_item, _factionColours select (getNumber (_configEntry >> 'side'))];
_factionDropdown lbSetData [_item, configName _configEntry];
} forEach _factionList;
_factionDropdown ctrlAddEventHandler ["LBSelChanged",
{
params ["_control", "_selectedIndex"];
_selection = _control lbData (lbCurSel _control);
if(_selection != "") then
{
_factionName = getText (configFile >> "cfgFactionClasses" >> _selection >> "displayName");
private _kitCount = count([_selection] call Pie_fnc_DynPlayerFactionInt_GetFactionLoadouts);
// Make sure the selected faction has actual classes (can't run this when populating the dialog, it's too slow)
if(_kitCount < 1) then
{
[format ["Invalid Faction, too few kits: %1", _factionName]] remoteExec ["systemChat", player];
}
else
{
private _dlcRequirements = [_selection] call Pie_fnc_DynPlayerFactionInt_GetFactionDLCs;
[formatText ["Faction selected: %1 %2 %3", _factionName, lineBreak, "Please choose a new loadout to match."]] remoteExec ["hintSilent"];
[format ["%1 has %2 kits, requires DLC: %3", _factionName, _kitCount, _dlcRequirements]] remoteExec ["systemChat", player];
missionNamespace setVariable ["Pie_Mis_SelectedPlayerFaction", _selection, true];
};
};
}];
_factionCloseButton = _display ctrlCreate ["RscButton", -1];
_factionCloseButton ctrlSetPosition [0.25, 0.5, 0.35, 0.04];
_factionCloseButton ctrlCommit 0;
_factionCloseButton ctrlSetText "Close";
_factionCloseButton ctrlAddEventHandler ["ButtonClick",
{
closeDialog 1;
}];
}
};
Pie_fnc_DynPlayerFaction_ChooseLoadout = {
_display = createDialog ["RscDisplayEmpty", true];
_instructionLabel = _display ctrlCreate ["RscText", 101];
_instructionLabel ctrlSetPosition [0, 0, 1, 0.04];
_instructionLabel ctrlSetText "Select a loadout";
_instructionLabel ctrlCommit 0;
_factionLabel = _display ctrlCreate ["RscText", 102];
_factionLabel ctrlSetPosition [0, 0.08, 1, 0.04];
_factionLabel ctrlSetText getText (configFile >> "cfgFactionClasses" >> (missionNamespace getVariable "Pie_Mis_SelectedPlayerFaction") >> "displayName");
_factionLabel ctrlCommit 0;
_loadoutDropdown = _display ctrlCreate ["RscCombo", 100];
_loadoutDropdown ctrlSetPosition [0, 0.16, 1, 0.04];
_loadoutDropdown ctrlCommit 0;
_loadoutList = [];
{
_loadoutList pushBack [getText (_x >> 'displayName'), _x];
} forEach ([missionNamespace getVariable "Pie_Mis_SelectedPlayerFaction"] call Pie_fnc_DynPlayerFactionInt_GetFactionLoadouts);
_loadoutList sort true;
{
_displayName = _x select 0;
_configEntry = _x select 1;
_item = _loadoutDropdown lbAdd format ["%1 - %2", _displayName, configName _configEntry];
_loadoutDropdown lbSetData [_item, configName _configEntry];
} forEach _loadoutList;
_loadoutDropdown ctrlAddEventHandler ["LBSelChanged",
{
params ["_control", "_selectedIndex"];
_selection = _control lbData (lbCurSel _control);
if(_selection != "") then
{
player setUnitLoadout _selection;
player setVariable ["Pie_Mis_PlayerSelectedClass", _selection, true];
// UK3CB don't actually add items, do that now
if (missionNamespace getVariable "Pie_Mis_SelectedPlayerFaction" find "UK3CB" == 0) then
{
// We can't use the actual function because it uses typeOf -.-
// [player] call UK3CB_factions_Common_fnc_unit_loadout;
[player, null, _selection] execVM "globalScripts\_ThirdParty\Pie_UK3CB_LoadoutAssigner.sqf";
};
player setUnitTrait ["engineer", if (getNumber (configFile >> "cfgVehicles" >> _selection >> "engineer") == 1) then { true } else { false }, true];
player setUnitTrait ["explosiveSpecialist", if (getNumber (configFile >> "cfgVehicles" >> _selection >> "canDeactivateMines") == 1) then { true } else { false }, true];
player setUnitTrait ["medic", if (getNumber (configFile >> "cfgVehicles" >> _selection >> "attendant") == 1) then { true } else { false }, true];
player setUnitTrait ["UAVHacker", if (getNumber (configFile >> "cfgVehicles" >> _selection >> "uavHacker") == 1) then { true } else { false }, true];
};
}];
_factionCloseButton = _display ctrlCreate ["RscButton", 103];
_factionCloseButton ctrlSetPosition [0.25, 0.5, 0.35, 0.04];
_factionCloseButton ctrlCommit 0;
_factionCloseButton ctrlSetText "Close";
_factionCloseButton ctrlAddEventHandler ["ButtonClick",
{
closeDialog 1;
}];
};
Pie_fnc_DynPlayerFactionInt_GetFactionLoadouts = {
params ["_selected_faction"];
configProperties [configFile >> "CfgVehicles", format ["isClass _x && (getText (_x >> 'unitinfotype') == 'rscunitinfosoldier') and (getText (_x >> 'faction') == '%1')", _selected_faction], true]
};
// ChatGPT (mostly) did this, don't look too close
Pie_fnc_DynPlayerFactionInt_GetFactionDLCs = {
params ["_selected_faction"];
// step 1: collect all faction units
private _units = configProperties [
configFile >> "CfgVehicles",
format [
"isClass _x && {getText (_x >> 'unitInfoType') == 'RscUnitInfoSoldier'} && {getText (_x >> 'faction') == '%1'}",
_selected_faction
],
true
];
if (_units isEqualTo []) exitWith {"ERROR: No units found"};
// Updated version, checking all units
// step 2: prefer medic, else random
// private _medics = _units select {getNumber (_x >> "attendant") > 0};
// private _chosen = if (_medics isNotEqualTo []) then {selectRandom _medics} else {selectRandom _units};
{
// 1. Find config entry for the class
private _cfg = _x;
if (isNull _cfg) then { continue; };
// 2. Collect all gear classnames
private _classnames = [];
{
private _arr = getArray (_cfg >> _x);
_classnames append _arr;
} forEach ["weapons", "respawnWeapons", "magazines", "respawnMagazines", "linkedItems", "respawnLinkedItems"];
{
private _str = getText (_cfg >> _x);
if (_str != "") then {_classnames pushBack _str};
} forEach ["uniformClass", "backpack"];
// Remove blanks and duplicates
_classnames = _classnames select {_x != ""};
_classnames = _classnames arrayIntersect _classnames;
// 3. Collect requiredAddons
private _addons = [];
{
private _cfgItem = configNull;
if (isClass (configFile >> "CfgVehicles" >> _x)) then {_cfgItem = configFile >> "CfgVehicles" >> _x} else {
if (isClass (configFile >> "CfgWeapons" >> _x)) then {_cfgItem = configFile >> "CfgWeapons" >> _x} else {
_cfgItem = configNull;
};
};
if (!isNull _cfgItem) then {
private _picturePath = toLower (getText(_cfgItem >> "picture"));
if (_picturePath find "enoch" != -1) then { if !("Contact" in _addons) then {_addons pushBack "Contact"}; };
if (_picturePath find "contact" != -1) then { if !("Contact" in _addons) then {_addons pushBack "Contact"}; };
if (_picturePath find "jets" != -1) then { if !("Jets" in _addons) then {_addons pushBack "Jets"}; };
};
} forEach _classnames;
// 5. Return comma-separated string
_addons joinString ", "
} forEach _units;
};