mirror of
https://github.com/EpochModTeam/DayZ-Epoch.git
synced 2026-02-24 17:10:49 +03:00
Consolidate weapon/magazine/backpack adding to function
This moves a lot of duplicated code from a server side only function (server_addCargo) to a client/server function called fn_addCargo.
This commit is contained in:
48
SQF/dayz_code/compile/fn_addCargo.sqf
Normal file
48
SQF/dayz_code/compile/fn_addCargo.sqf
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
Adds cargo to an object
|
||||
|
||||
Parameters:
|
||||
_this select 0: array - weapon cargo to add
|
||||
_this select 1: array - magazine cargo to add
|
||||
_this select 2: array - backpack cargo to add
|
||||
_this select 3: object - object to add cargo to
|
||||
*/
|
||||
|
||||
private ["_weapons","_magazines","_backpacks","_holder","_objWpnTypes","_objWpnQty","_counter"];
|
||||
|
||||
_weapons = _this select 0;
|
||||
_magazines = _this select 1;
|
||||
_backpacks = _this select 2;
|
||||
_holder = _this select 3;
|
||||
|
||||
if (count _weapons > 0) then {
|
||||
_objWpnTypes = _weapons select 0;
|
||||
_objWpnQty = _weapons select 1;
|
||||
_counter = 0;
|
||||
{
|
||||
_holder addWeaponCargoGlobal [_x,(_objWpnQty select _counter)];
|
||||
_counter = _counter + 1;
|
||||
} count _objWpnTypes;
|
||||
};
|
||||
|
||||
if (count _magazines > 0) then {
|
||||
_objWpnTypes = _magazines select 0;
|
||||
_objWpnQty = _magazines select 1;
|
||||
_counter = 0;
|
||||
{
|
||||
if (_x != "CSGAS") then {
|
||||
_holder addMagazineCargoGlobal [_x,(_objWpnQty select _counter)];
|
||||
_counter = _counter + 1;
|
||||
};
|
||||
} count _objWpnTypes;
|
||||
};
|
||||
|
||||
if (count _backpacks > 0) then {
|
||||
_objWpnTypes = _backpacks select 0;
|
||||
_objWpnQty = _backpacks select 1;
|
||||
_counter = 0;
|
||||
{
|
||||
_holder addBackpackCargoGlobal [_x,(_objWpnQty select _counter)];
|
||||
_counter = _counter + 1;
|
||||
} count _objWpnTypes;
|
||||
};
|
||||
@@ -4,7 +4,7 @@
|
||||
if (dayz_actionInProgress) exitWith {localize "str_player_actionslimit" call dayz_rollingMessages;};
|
||||
dayz_actionInProgress = true;
|
||||
|
||||
private ["_alreadyPacking","_backpacks","_bag","_campItems","_countr","_dir","_holder","_magazines","_obj","_objWpnQty","_objWpnTypes","_objectID","_objectUID","_ownerID","_packobj","_playerNear","_pos","_weapons","_finished"];
|
||||
private ["_alreadyPacking","_backpacks","_bag","_campItems","_dir","_holder","_magazines","_obj","_objectID","_objectUID","_ownerID","_packobj","_playerNear","_pos","_weapons","_finished"];
|
||||
|
||||
_obj = _this;
|
||||
_ownerID = _obj getVariable["CharacterID","0"];
|
||||
@@ -37,7 +37,7 @@ if (_ownerID in [dayz_characterID,dayz_playerUID] or typeOf _obj in _campItems)
|
||||
|
||||
[player,"tentpack",0,false,20] call dayz_zombieSpeak;
|
||||
[player,20,true,getPosATL player] call player_alertZombies;
|
||||
|
||||
|
||||
_finished = ["Medic",1] call fn_loopAction;
|
||||
if (isNull _obj) exitWith {};
|
||||
if (!_finished) exitWith {_obj setVariable["packing",0,true];};
|
||||
@@ -46,7 +46,7 @@ if (_ownerID in [dayz_characterID,dayz_playerUID] or typeOf _obj in _campItems)
|
||||
_bag = createVehicle [_packobj, _pos, [], 0, "CAN_COLLIDE"];
|
||||
_bag setDir _dir;
|
||||
player reveal _bag;
|
||||
|
||||
|
||||
_holder = createVehicle ["WeaponHolder", _pos, [], 0, "CAN_COLLIDE"];
|
||||
|
||||
_weapons = getWeaponCargo _obj;
|
||||
@@ -57,35 +57,10 @@ if (_ownerID in [dayz_characterID,dayz_playerUID] or typeOf _obj in _campItems)
|
||||
publicVariableServer "PVDZ_obj_Destroy";
|
||||
deleteVehicle _obj;
|
||||
|
||||
//Add weapons
|
||||
_objWpnTypes = _weapons select 0;
|
||||
_objWpnQty = _weapons select 1;
|
||||
_countr = 0;
|
||||
{
|
||||
_holder addWeaponCargoGlobal [_x,(_objWpnQty select _countr)];
|
||||
_countr = _countr + 1;
|
||||
} count _objWpnTypes;
|
||||
|
||||
//Add Magazines
|
||||
_objWpnTypes = _magazines select 0;
|
||||
_objWpnQty = _magazines select 1;
|
||||
_countr = 0;
|
||||
{
|
||||
_holder addMagazineCargoGlobal [_x,(_objWpnQty select _countr)];
|
||||
_countr = _countr + 1;
|
||||
} count _objWpnTypes;
|
||||
|
||||
//Add Backpacks
|
||||
_objWpnTypes = _backpacks select 0;
|
||||
_objWpnQty = _backpacks select 1;
|
||||
_countr = 0;
|
||||
{
|
||||
_holder addBackpackCargoGlobal [_x,(_objWpnQty select _countr)];
|
||||
_countr = _countr + 1;
|
||||
} count _objWpnTypes;
|
||||
[_weapons,_magazines,_backpacks,_holder] call fn_addCargo;
|
||||
|
||||
localize "str_success_tent_pack" call dayz_rollingMessages;
|
||||
} else {
|
||||
localize "str_fail_tent_pack" call dayz_rollingMessages;
|
||||
};
|
||||
dayz_actionInProgress = false;
|
||||
dayz_actionInProgress = false;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
private ["_weapons","_isArray","_backpackWpn","_backpackMag","_currentWpn","_isWeapon","_isMagazine","_backpackWpnTypes","_backpackWpnQtys","_countr","_class","_position","_dir","_currentAnim","_playerUID","_countMags","_magazines","_primweapon","_secweapon","_newBackpackType","_muzzles","_oldUnit","_group","_newUnit","_oldGroup","_idc","_display","_switchUnit","_leader","_currentCamera"];
|
||||
private ["_weapons","_isArray","_backpackWpn","_backpackMag","_currentWpn","_isWeapon","_isMagazine","_countr","_class","_position","_dir","_currentAnim","_playerUID","_countMags","_magazines","_primweapon","_secweapon","_newBackpackType","_muzzles","_oldUnit","_group","_newUnit","_oldGroup","_idc","_display","_switchUnit","_leader","_currentCamera"];
|
||||
_isArray = typeName _this == "ARRAY";
|
||||
_class = if (_isArray) then {_this select 0} else {_this};
|
||||
|
||||
@@ -138,12 +138,6 @@ if (!isNil "_newBackpackType" && {_newBackpackType != ""}) then {
|
||||
//_oldBackpack = dayz_myBackpack;
|
||||
dayz_myBackpack = unitBackpack _newUnit;
|
||||
|
||||
_backpackWpnTypes = [];
|
||||
_backpackWpnQtys = [];
|
||||
if (count _backpackWpn > 0) then {
|
||||
_backpackWpnTypes = _backpackWpn select 0;
|
||||
_backpackWpnQtys = _backpackWpn select 1;
|
||||
};
|
||||
call _switchUnit;
|
||||
if (gear_done) then {sleep 0.001;};
|
||||
["1"] call gearDialog_create;
|
||||
@@ -172,11 +166,8 @@ if (!isNil "_newBackpackType" && {_newBackpackType != ""}) then {
|
||||
};
|
||||
} count _backpackMag;
|
||||
(findDisplay 106) closeDisplay 0;
|
||||
_countr = 0;
|
||||
{
|
||||
dayz_myBackpack addWeaponCargoGlobal [_x,(_backpackWpnQtys select _countr)];
|
||||
_countr = _countr + 1;
|
||||
} count _backpackWpnTypes;
|
||||
|
||||
[_backpackWpn,[],[],dayz_myBackpack] call fn_addCargo;
|
||||
} else {
|
||||
call _switchUnit;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user