Skip to content

Commit

Permalink
Fix vehicle coin saving.
Browse files Browse the repository at this point in the history
The previous method for saving coins only worked for static class names
and is checked everytime server_updateObject is referenced so it's quite
intensive.
Since there are too many vehicles to list, we'll just make a proper
server_updateObject function specific to saving coins on objects which
will be a lot less overhead.
  • Loading branch information
oiad committed Mar 15, 2017
1 parent 1543860 commit 4846420
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
31 changes: 26 additions & 5 deletions dayz_server/compile/server_updateObject.sqf
Expand Up @@ -66,8 +66,7 @@ _object_position = {
};

_object_inventory = {
private ["_inventory","_key","_isNormal","_coins","_forceUpdate"];
_forceUpdate = false;
private ["_inventory","_key","_isNormal","_coins"];
if (_object isKindOf "TrapItems") then {
_inventory = [["armed",_object getVariable ["armed",false]]];
} else {
Expand All @@ -83,15 +82,13 @@ _object_inventory = {
_inventory = _object getVariable ["doorfriends", []]; //We're replacing the inventory with UIDs for this item
};

if (Z_SingleCurrency && {typeOf (_object) in DZE_MoneyStorageClasses}) then { _forceUpdate = true; };

if (_isNormal) then {
_inventory = [getWeaponCargo _object, getMagazineCargo _object, getBackpackCargo _object];
};
};

_previous = str(_object getVariable["lastInventory",[]]);
if ((str _inventory != _previous) || {_forceUpdate}) then {
if (str _inventory != _previous) then {
_object setVariable["lastInventory",_inventory];
if (_objectID == "0") then {
_key = format["CHILD:309:%1:",_objectUID] + str _inventory + ":";
Expand Down Expand Up @@ -245,6 +242,27 @@ _object_variables = {
_key call server_hiveWrite;
};

_object_coins = {
private ["_inventory","_key","_coins"];
_inventory = [getWeaponCargo _object, getMagazineCargo _object, getBackpackCargo _object];
_object setVariable["lastInventory",_inventory];
if (_objectID == "0") then {
_key = format["CHILD:309:%1:",_objectUID] + str _inventory + ":";
} else {
_key = format["CHILD:303:%1:",_objectID] + str _inventory + ":";
};
if (Z_SingleCurrency) then {
_coins = _object getVariable [Z_MoneyVariable, -1]; //set to invalid value if getVariable fails to prevent overwriting of coins in DB
_key = _key + str _coins + ":";
};

#ifdef OBJECT_DEBUG
diag_log format["DELETE: Deleted by KEY: %1",_key];
#endif

_key call server_hiveWrite;
};

_object setVariable ["lastUpdate",diag_ticktime,true];
switch (_type) do {
case "all": {
Expand Down Expand Up @@ -273,4 +291,7 @@ switch (_type) do {
case "objWallDamage": {
call _objWallDamage;
};
case "coins": {
call _object_coins;
};
};
4 changes: 2 additions & 2 deletions scripts/zsc/zscInit.sqf
Expand Up @@ -37,7 +37,7 @@ BankDialogWithdrawAmount = {
ZSC_CurrentStorage setVariable[Z_MoneyVariable,(_bank - _amount),true];
call player_forceSave;

PVDZ_veh_Save = [ZSC_CurrentStorage,"gear"];
PVDZ_veh_Save = [ZSC_CurrentStorage,"coins"];
publicVariableServer "PVDZ_veh_Save";

format ["You have withdrawn %1 %2 out of the %3",[_amount] call BIS_fnc_numberText,CurrencyName,_displayName] call dayz_rollingMessages;
Expand Down Expand Up @@ -75,7 +75,7 @@ BankDialogDepositAmount = {
};

call player_forceSave;
PVDZ_veh_Save = [ZSC_CurrentStorage,"gear"];
PVDZ_veh_Save = [ZSC_CurrentStorage,"coins"];
publicVariableServer "PVDZ_veh_Save";
};

Expand Down

0 comments on commit 4846420

Please sign in to comment.