Fix SetUnitLoadout

This commit is contained in:
He-Man 2019-08-10 01:47:06 +02:00
parent 43ec66a05a
commit 8d5f99d1c4
4 changed files with 116 additions and 10 deletions

View File

@ -0,0 +1,96 @@
/*
Author: He-Man - EpochMod.com
Contributors:
Description:
Change PlayerLoadout
Licence:
Arma Public License Share Alike (APL-SA) - https://www.bistudio.com/community/licenses/arma-public-license-share-alike
Github:
https://github.com/EpochModTeam/Epoch/tree/release/Sources/epoch_code/compile/inventory/EPOCH_SetUnitLoadout.sqf
*/
//[[[cog import generate_private_arrays ]]]
private ["_type","_loadabs"];
//[[[end]]]
params ["_newPlyr","_loadout"];
// _loadout params ["_primaryarr","_secondaryarr","_handgunarr","_uniformarr","_vestarr","_bpackarr","_HeadGear","_Glasses","_Rangefinderarr","_LinedItemsarr"];
_loadout = +_loadout;
_loadout params ["","","","_uniformarr","_vestarr","_bpackarr","","","",""];
_loadout set [3,[]];
_loadout set [4,[]];
_loadout set [5,[]];
_newPlyr setunitloadout _loadout;
_uniformarr params [["_uniform",""],["_uniformitems",[]]];
_vestarr params [["_vest",""],["_vestitems",[]]];
_bpackarr params [["_bpack",""],["_bpackitems",[]]];
if !(_uniform isequalto "") then {
_newPlyr forceadduniform _uniform;
};
if !(_vest isequalto "") then {
_newPlyr addVest _vest;
};
if !(_bpack isequalto "") then {
_newPlyr addBackpack _bpack;
};
{
_x params ["_container","_items"];
if !(isnull _container) then {
clearitemcargoglobal _container;
clearbackpackcargoglobal _container;
clearmagazinecargoglobal _container;
clearweaponcargoglobal _container;
{
if (count _x > 2) then {
_container addMagazineAmmoCargo _x;
}
else {
if ((_x select 0) isequaltype []) then {
_x params ["_arr","_cnt"];
_type = _arr deleteat 0;
_container addWeaponcargoglobal [_type,_cnt];
{
if !(_x isequalto "" || _x isequalto []) then {
if (_x isequaltype []) then {
_container addMagazineAmmoCargo [_x select 0,1,_x select 1];
}
else {
_container addItemCargoGlobal [_x,1];
};
};
} foreach _arr;
}
else {
_x params [["_type",""],["_cnt",1]];
if !(_cnt isequaltype 1) then {
_cnt = 1;
};
if (_type iskindof "Bag_Base") then {
_container addBackpackCargoGlobal [_type,_cnt];
}
else {
_container addItemCargoGlobal [_type,_cnt];
};
};
};
} foreach _items;
};
} foreach [
[Uniformcontainer _newPlyr, _uniformitems],
[Vestcontainer _newPlyr, _vestitems],
[BackpackContainer _newPlyr, _bpackitems]
];
/*
_loadabs = loadabs _newPlyr;
if !(uniform _newPlyr isequalto _uniform && vest _newPlyr isequalto _vest && backpack _newPlyr isequalto _bpack) then {
diag_log format ["EPOCH Debug: Setunitloadout failed - Unifmorm should: %1 is: %2 - Vest should: %3 is: %4 - Backpack should: %5 is: %6",_uniform,uniform _newPlyr,_vest,vest _newPlyr,_bpack,backpack _newPlyr];
_loadabs = -1;
};
_loadabs
*/

View File

@ -111,7 +111,8 @@ _fnc_moveWeaponFromContainer = {
//add new entry
_loadout set [_dIdx,_temp];
//save changes
player setUnitLoadout _loadout;
// player setUnitLoadout _loadout;
[player,_loadout] call Epoch_SetUnitLoadout;
};
_fnc_MoveWeaponToContainer = {
@ -135,7 +136,8 @@ _fnc_MoveWeaponToContainer = {
((_loadout select (_container + 3)) select 1) append [[_loadout select _sIdx,1]]; //cut out from above comment, looks like appending alone works great
_loadout set [_sIdx,[]];
player setUnitLoadout _loadout;
// player setUnitLoadout _loadout;
[player,_loadout] call Epoch_SetUnitLoadout;
};
_fnc_canMoveToContainer = {
@ -230,7 +232,8 @@ _fnc_MoveShellToContainer = {
((_loadout select (_container + 3)) select 1) append [_temp2]; //cut out from above comment, looks like appending alone works great
};
(_loadout select 0) set [5,[]];
player setUnitLoadout _loadout;
// player setUnitLoadout _loadout;
[player,_loadout] call Epoch_SetUnitLoadout;
};
_fnc_moveShellFromContainer = {
@ -248,7 +251,8 @@ _fnc_moveShellFromContainer = {
((_loadout select (_container + 3)) select 1) deleteAt _sIdx;
};
(_loadout select 0) set [5,[_temp select 0,_temp select 2]];
player setUnitLoadout _loadout;
// player setUnitLoadout _loadout;
[player,_loadout] call Epoch_SetUnitLoadout;
};
};
@ -272,7 +276,8 @@ _fnc_dropEquipShells = {
if !(_drop) exitWith {_return = 4;};
_equipped call _fnc_dropItem;
(_loadout select 0) set [5,[]];
player setUnitLoadout _loadout;
// player setUnitLoadout _loadout;
[player,_loadout] call Epoch_SetUnitLoadout;
_return = 2;
};
if (_forceEquip && _return != 4) then {
@ -345,25 +350,29 @@ _fnc_dropEquipAccessories = {
_equipped = (_loadout select _slot) select _accessory;
if (player canAdd _equipped) then {
(_loadout select _slot) set [_accessory,""];
player setUnitLoadout _loadout;
// player setUnitLoadout _loadout;
[player,_loadout] call Epoch_SetUnitLoadout;
player addItem _equipped;
_return = 1;
} else {
if !(_drop) exitWith {_return = 4;};
_equipped call _fnc_dropItem;
(_loadout select _slot) set [_accessory,""];
player setUnitLoadout _loadout;
// player setUnitLoadout _loadout;
[player,_loadout] call Epoch_SetUnitLoadout;
_return = 2;
};
if ((((toLower _equipped) != (toLower _item)) || _forceEquip) && _return != 4) then {
(_loadout select _slot) set [_accessory,_item];
player setUnitLoadout _loadout;
// player setUnitLoadout _loadout;
[player,_loadout] call Epoch_SetUnitLoadout;
player addItem _equipped;
player removeItem _item;
};
} else {
(_loadout select _slot) set [_accessory,_item];
player setUnitLoadout _loadout;
// player setUnitLoadout _loadout;
[player,_loadout] call Epoch_SetUnitLoadout;
player removeItem _item;
_return = 1;
};

View File

@ -74,7 +74,7 @@ _respawnButton ctrlEnable false;
(isNull _display) || ((_startTime - diag_tickTime) <= 0)
};
if (!isNull _display) then {
player setUnitLoadout (getUnitLoadout player);
[player,(getUnitLoadout player)] call (missionnamespace getvariable ["Epoch_SetUnitLoadout",{}]);
uisleep 1; // give one second to broadcast clothing change
missionnamespace setvariable ["EPOCH_forceUpdateNow",true];
};

View File

@ -220,6 +220,7 @@ class CfgClientFunctions
class itemTypeSlot {};
class usedItemRepack {};
class CryptoButtons {};
class SetUnitLoadout {};
};
class servicepoint
{