Re-add magazine refill fix when changing clothes

This is the code from 1.0.5.2 before it became 1.0.6, it contains the
fix for backpack wipes in 1.0.5.1. I lightly tested it with 1.0.6 but it
will need more testing before release.
This commit is contained in:
icomrade
2016-07-28 13:27:30 -04:00
parent 21019056c3
commit 82e2500cac
3 changed files with 208 additions and 83 deletions

View File

@@ -0,0 +1,72 @@
/*
count player magazines with ammo count
value = call player_countMagazines; //must be called from a spawned thread (|| use spawn)
return all player magazines with ammo count
Modified to save backpack magazine count by icomrade - Base for fix by Ziellos2k
*/
private ["_control","_item","_val","_max","_count","_magazineArray","_dialog"];
disableSerialization;
disableUserInput true;
_magazineArray = [[],[]];
_dialog = ["0"] call gearDialog_create;
if ((isNil "_dialog") || {isNull _dialog}) exitWith {disableUserInput false; (findDisplay 106) closeDisplay 0; closeDialog 0; _magazineArray};
//Main inventory
for "_i" from 109 to 120 do {
_control = _dialog displayCtrl _i;
_item = gearSlotData _control;
_val = gearSlotAmmoCount _control;
_max = getNumber (configFile >> "CfgMagazines" >> _item >> "count");
if (_item != "") then {
if (_val != _max) then {
(_magazineArray select 0) set [count (_magazineArray select 0),[_item,_val]];
} else {
(_magazineArray select 0) set [count (_magazineArray select 0),_item];
};
};
};
//Pistol/secondary ammo
for "_i" from 122 to 129 do {
_control = _dialog displayCtrl _i;
_item = gearSlotData _control;
_val = gearSlotAmmoCount _control;
_max = getNumber (configFile >> "CfgMagazines" >> _item >> "count");
if (_item != "") then {
if (_val != _max) then {
(_magazineArray select 0) set [count (_magazineArray select 0),[_item,_val]];
} else {
(_magazineArray select 0) set [count (_magazineArray select 0),_item];
};
};
};
//backpack items
if ((typeOf (unitBackPack player)) != "") then {
_count = getNumber (configFile >> "CfgVehicles" >> (typeOf (unitBackpack Player)) >> "transportMaxMagazines");
ctrlActivate (_dialog displayCtrl 157);
if (gear_done) then {
waitUntil {ctrlShown (_dialog displayCtrl 159)};
uisleep 0.001;
};
for "_i" from 5000 to (5000 + _count) do {
_control = _dialog displayCtrl _i;
_item = gearSlotData _control;
_val = gearSlotAmmoCount _control;
_max = getNumber (configFile >> "CfgMagazines" >> _item >> "count");
if (_item != "") then {
if (_val != _max) then {
(_magazineArray select 1) set [count (_magazineArray select 1),[_item,_val]];
} else {
(_magazineArray select 1) set [count (_magazineArray select 1),_item];
};
};
};
};
(findDisplay 106) closeDisplay 0;
if (gear_done) then {uisleep 0.001;};
_magazineArray;

View File

@@ -1,46 +1,44 @@
//private ["_class","_position","_dir","_group","_oldUnit","_newUnit","_currentWpn","_muzzles","_currentAnim","_playerUID","_weapons","_magazines","_primweapon","_secweapon","_newBackpackType","_backpackWpn","_backpackMag","_backpackWpnTypes","_backpackWpnQtys","_countr","_backpackmagTypes","_backpackmagQtys","_display","_createSafePos","_wpnType","_ismelee","_rndx","_rndy"];
private ["_class","_position","_dir","_currentAnim","_currentCamera","_playerUID","_weapons","_magazines","_primweapon","_secweapon","_newBackpackType","_backpackWpn","_backpackMag","_currentWpn","_muzzles","_display","_oldUnit","_newUnit","_oldBackpack","_backpackWpnTypes","_backpackWpnQtys","_countr","_backpackmagTypes","_backpackmagQtys","_backpackmag","_createSafePos","_rndx","_rndy","_playerObjName","_wpnType","_ismelee"];
_class = _this;
private ["_weapons","_backpackWpn","_backpackMag","_currentWpn","_isWeapon","_backpackWpnTypes","_backpackWpnQtys","_countr","_class","_position","_dir","_currentAnim","_playerUID","_countMags","_magazines","_primweapon","_secweapon","_newBackpackType","_muzzles","_oldUnit","_group","_newUnit","_oldGroup","_idc","_display","_switchUnit"];
disableSerialization;
//Old location system causes issues with players getting damaged during movement.
//_position = getPosATL player;
//New system testing needed.
_class = _this;
_position = player modeltoWorld [0,0,0];
_dir = getDir player;
_currentAnim = animationState player;
//_currentCamera = cameraView;
_playerUID = [player] call FNC_GetPlayerUID;
_weapons = weapons player;
_countMags = call player_countMagazinesWBackpack;
if (((typeName _countMags) != "ARRAY")) exitWith {localize "str_actions_switchmodel_fail" call dayz_rollingMessages;};
_magazines = _countMags select 0;
//BackUp Weapons and Mags
_weapons = weapons player;
_magazines = call player_countMagazines; //magazines player;
if ((_playerUID == dayz_playerUID) && (count _magazines == 0) && (count (magazines player) > 0)) exitWith {localize "str_actions_switchmodel_fail" call dayz_rollingMessages;};
if ((_playerUID == dayz_playerUID) && (count _magazines == 0) && (count (magazines player) > 0 )) exitWith {localize "str_actions_switchmodel_fail" call dayz_rollingMessages;};
_primweapon = primaryWeapon player;
_secweapon = secondaryWeapon player;
_primweapon = primaryWeapon player;
_secweapon = secondaryWeapon player;
if (!(_primweapon in _weapons) && _primweapon != "") then {
_weapons set [count _weapons, _primweapon];
if(!(_primweapon in _weapons) && _primweapon != "") then {
_weapons set [(count _weapons), _primweapon];
};
if (!(_secweapon in _weapons) && _secweapon != "") then {
_weapons set [count _weapons, _secweapon];
if(!(_secweapon in _weapons) && _secweapon != "") then {
_weapons set [(count _weapons), _secweapon];
};
//BackUp Backpack
dayz_myBackpack = unitBackpack player;
_newBackpackType = typeOf dayz_myBackpack;
if (_newBackpackType != "") then {
_newBackpackType = (typeOf dayz_myBackpack);
if(_newBackpackType != "") then {
_backpackWpn = getWeaponCargo unitBackpack player;
_backpackMag = getMagazineCargo unitBackpack player;
_backpackMag = _countMags select 1;
};
//Get Muzzle
_currentWpn = currentWeapon player;
_muzzles = getArray(configFile >> "cfgWeapons" >> _currentWpn >> "muzzles");
if (count _muzzles > 1) then {_currentWpn = currentMuzzle player;};
//Debug Message
if (count _muzzles > 1) then {
_currentWpn = currentMuzzle player;
};
// diag_log "Attempting to switch model";
// diag_log str(_weapons);
// diag_log str(_magazines);
@@ -54,78 +52,114 @@ if (count _muzzles > 1) then {_currentWpn = currentMuzzle player;};
_display = findDisplay 106;
_display closeDisplay 0;
_oldGroup = group player;
//BackUp Player Object
_oldUnit = player;
_oldGroup = group player;
/***********************************/
//DONT USE player AFTER THIS POINT
/***********************************/
/**********************************/
//DONT USE player AFTER THIS POINT//
/**********************************/
//Create New Character
//[player] joinSilent grpNull;
_group = createGroup west;
_newUnit = _group createUnit [_class,getMarkerPos "respawn_west",[],0,"NONE"];
_newUnit setDir _dir;
{_newUnit removeMagazine _x;} count magazines _newUnit;
removeAllWeapons _newUnit;
//Equip New Character
_group = createGroup west;
_newUnit = _group createUnit [_class,getMarkerPos "respawn_west",[],0,"NONE"];
_newUnit setDir _dir;
{_newUnit removeMagazine _x;} count magazines _newUnit;
removeAllWeapons _newUnit;
//Equip New Charactar
{
if (typeName _x == "ARRAY") then {_newUnit addMagazine [_x select 0,_x select 1] } else { _newUnit addMagazine _x };
if (typeName _x == "ARRAY") then {if ((count _x) > 0) then {_newUnit addMagazine [(_x select 0), (_x select 1)]; }; } else { _newUnit addMagazine _x; };
} count _magazines;
{_newUnit addWeapon _x;} count _weapons;
{
_newUnit addWeapon _x;
} count _weapons;
//Check and Compare it
if (str(_weapons) != str(weapons _newUnit)) then {
//Check && Compare it
if(str(_weapons) != str(weapons _newUnit)) then {
//Get Differecnce
{_weapons = _weapons - [_x];} count (weapons _newUnit);
{
_weapons = _weapons - [_x];
} count (weapons _newUnit);
//Add the Missing
{_newUnit addWeapon _x;} count _weapons;
{
_newUnit addWeapon _x;
} count _weapons;
};
if (_primweapon != (primaryWeapon _newUnit)) then {
_newUnit addWeapon _primweapon;
if(_primweapon != (primaryWeapon _newUnit)) then {
_newUnit addWeapon _primweapon;
};
if (_secweapon != (secondaryWeapon _newUnit) && _secweapon != "") then {
_newUnit addWeapon _secweapon;
if(_secweapon != (secondaryWeapon _newUnit) && _secweapon != "") then {
_newUnit addWeapon _secweapon;
};
//Add and Fill BackPack
_switchUnit = {
addSwitchableUnit _newUnit;
setPlayable _newUnit;
selectPlayer _newUnit;
//Switch the units
//_createSafePos = [(getMarkerPos "respawn_west"), 2, 100, 0, 1, 20, 0] call BIS_fnc_findSafePos;
_createSafePos = getMarkerPos "respawn_west";
_rndx = floor(random 100);
_rndy = floor(random 100);
_oldUnit setPosATL [(_createSafePos select 0) + _rndx, (_createSafePos select 1) + _rndy, 0];
_newUnit setPosATL _position;
removeAllWeapons _oldUnit;
{_oldUnit removeMagazine _x;} count magazines _oldUnit;
if !(isNull _oldUnit) then {deleteVehicle _oldUnit;};
deleteGroup _oldGroup;
if (_currentWpn != "") then {_newUnit selectWeapon _currentWpn;};
};
//Add && Fill BackPack
if (!isNil "_newBackpackType") then {
if (_newBackpackType != "") then {
_newUnit addBackpack _newBackpackType;
//_oldBackpack = dayz_myBackpack;
dayz_myBackpack = unitBackpack _newUnit;
//Weapons
_backpackWpnTypes = [];
_backpackWpnQtys = [];
if (count _backpackWpn > 0) then {
_backpackWpnTypes = _backpackWpn select 0;
_backpackWpnQtys = _backpackWpn select 1;
};
[] call _switchUnit;
uiSleep 0.001;
["1"] call gearDialog_create;
uiSleep 0.001;
//magazines
_countr = 0;
{
if ((typeName _x) != "STRING") then {
_isWeapon = (isClass(configFile >> "CfgWeapons" >> (_x select 0)));
} else {
_isWeapon = (isClass(configFile >> "CfgWeapons" >> _x));
};
if (!_isWeapon) then {
_countr = _countr + 1;
if ((typeName _x) != "STRING") then {
dayz_myBackpack addMagazineCargoGlobal [(_x select 0), 1];
_idc = 4999 + _countr;
_idc setIDCAmmoCount (_x select 1);
} else {
dayz_myBackpack addMagazineCargoGlobal [_x, 1];
};
};
} count _backpackMag;
(findDisplay 106) closeDisplay 0;
if (gear_done) then {uiSleep 0.001; disableUserInput false;};
_countr = 0;
{
dayz_myBackpack addWeaponCargoGlobal [_x,(_backpackWpnQtys select _countr)];
_countr = _countr + 1;
} count _backpackWpnTypes;
_backpackmagTypes = [];
_backpackmagQtys = [];
if (count _backpackmag > 0) then {
_backpackmagTypes = _backpackMag select 0;
_backpackmagQtys = _backpackMag select 1;
};
_countr = 0;
{
dayz_myBackpack addmagazineCargoGlobal [_x,(_backpackmagQtys select _countr)];
_countr = _countr + 1;
} count _backpackmagTypes;
};
};
} else { [] call _switchUnit; };
} else { [] call _switchUnit; };
//Debug Message
diag_log "Swichtable Unit Created. Equipment:";
@@ -134,20 +168,6 @@ diag_log format["Magazines: %1",magazines _newUnit];
diag_log format["Backpack weapons: %1",getWeaponCargo unitBackpack _newUnit];
diag_log format["Backpack magazines: %1",getMagazineCargo unitBackpack _newUnit];
//Make New Unit Playable (1 of these 3 commands causes crashes with gear dialog open)
//_oldUnit setPosATL [_position select 0 + cos(_dir) * 2, _position select 1 + sin(_dir) * 2, _position select 2];
addSwitchableUnit _newUnit;
setPlayable _newUnit;
selectPlayer _newUnit;
//Switch the units
//_createSafePos = [(getMarkerPos "respawn_west"), 2, 100, 0, 1, 20, 0] call BIS_fnc_findSafePos;
_createSafePos = getMarkerPos "respawn_west";
_rndx = floor(random 100);
_rndy = floor(random 100);
_oldUnit setPosATL [(_createSafePos select 0) + _rndx, (_createSafePos select 1) + _rndy, 0];
_newUnit setPosATL _position;
//Clear and delete old Unit
removeAllWeapons _oldUnit;
{_oldUnit removeMagazine _x;} count magazines _oldUnit;
@@ -156,15 +176,11 @@ deleteGroup _oldGroup;
// player switchCamera = _currentCamera;
if (_currentWpn != "") then {_newUnit selectWeapon _currentWpn;};
[objNull, player, rSwitchMove, _currentAnim] call RE;
//dayz_originalPlayer attachTo [_newUnit];
player disableConversation true;
player setVariable ["BIS_noCoreConversations",true];
// _playerUID=getPlayerUID player;
// _playerObjName = format["player%1",_playerUID];
// call compile format["%1 = player;",_playerObjName];
// publicVariable _playerObjName;
call dayz_meleeMagazineCheck;
{player reveal _x} count (nearestObjects [getPosATL player,["AllVehicles","WeaponHolder","Land_A_tent","BuiltItems","ModularItems","DZE_Base_Object"],75]);

View File

@@ -55,6 +55,7 @@ if (!isDedicated) then {
player_alertZombies = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\player_alertZombies.sqf";
player_fireMonitor = compile preprocessFileLineNumbers "\z\addons\dayz_code\system\fire_monitor.sqf";
player_countMagazines = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\player_countMagazines.sqf";
player_countMagazinesWBackpack = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\player_countMagazinesWBackpack.sqf";
player_forceSave = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\player_forceSave.sqf";
//player_destroyTent = compile preprocessFileLineNumbers "\z\addons\dayz_code\actions\player_destroyTent.sqf";
vehicle_getOut = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\vehicle_getOut.sqf";
@@ -357,6 +358,42 @@ if (!isDedicated) then {
//diag_log format ["%6, Nutrition add: %1, Nutrition Total: %7/%2, Thurst: %3, Hunger: %4, BloodRegen: %5",_this,r_player_Nutrition,_Thirst,_Hunger,_bloodregen,_type,_golbalNutrition];
};
gearDialog_create = {
private ["_i","_dialog"];
if (!isNull (findDisplay 106)) then {
(findDisplay 106) closeDisplay 0;
};
if (isNil "gear_done") then { gear_done = false; };
openMap false;
closeDialog 0;
if (gear_done) then {uisleep 0.001;};
player action ["Gear", player];
if (gear_done) then {uisleep 0.001;};
_dialog = findDisplay 106;
_i = 0;
while {isNull _dialog} do {//DO NOT CHANGE TO A FOR LOOP!
_i = _i + 1;
_dialog = findDisplay 106;
if (gear_done) then {uisleep 0.001;};
if (_i in [100,200,299]) then {
closeDialog 0;
player action ["Gear", player];
};
if (_i > 300) exitWith {};
};
if (gear_done) then {uisleep 0.001;};
_dialog = findDisplay 106;
if ((parseNumber(_this select 0)) != 0) then {
ctrlActivate (_dialog displayCtrl 157);
if (gear_done) then {
waitUntil {ctrlShown (_dialog displayCtrl 159)};
uisleep 0.001;
};
};
gear_done = true;
_dialog
};
gear_ui_offMenu = {
private["_control","_parent","_menu","_grpPos"];
disableSerialization;