From 23d555a529990a7bc62a9dd966e00ba61ad9fa16 Mon Sep 17 00:00:00 2001 From: Zac Surplice Date: Mon, 23 Dec 2013 11:30:25 +1100 Subject: [PATCH 1/3] buildings before cars --- SQF/dayz_server/system/server_monitor.sqf | 360 ++++++++++++---------- 1 file changed, 199 insertions(+), 161 deletions(-) diff --git a/SQF/dayz_server/system/server_monitor.sqf b/SQF/dayz_server/system/server_monitor.sqf index ee7c3595a..08445012f 100644 --- a/SQF/dayz_server/system/server_monitor.sqf +++ b/SQF/dayz_server/system/server_monitor.sqf @@ -62,9 +62,11 @@ if (isServer and isNil "sm_done") then { diag_log ("HIVE: got " + str(count _objectArray) + " objects"); }; + dayz_BuildingQueue = []; + dayz_objectQueue = []; + // # START OF STREAMING # _countr = 0; - _totalvehicles = 0; { //Parse Array _countr = _countr + 1; @@ -78,172 +80,208 @@ if (isServer and isNil "sm_done") then { _hitPoints= _x select 6; _fuel = _x select 7; _damage = _x select 8; - - _dir = 0; - _pos = [0,0,0]; - _wsDone = false; - if (count _worldspace >= 2) then - { - _dir = _worldspace select 0; - if (count (_worldspace select 1) == 3) then { - _pos = _worldspace select 1; - _wsDone = true; - } - }; - if (!_wsDone) then { - if (count _worldspace >= 1) then { _dir = _worldspace select 0; }; - _pos = [getMarkerPos "center",0,4000,10,0,2000,0] call BIS_fnc_findSafePos; - if (count _pos < 3) then { _pos = [_pos select 0,_pos select 1,0]; }; - diag_log ("MOVED OBJ: " + str(_idKey) + " of class " + _type + " to pos: " + str(_pos)); - }; - - if (_damage < 1) then { - //diag_log format["OBJ: %1 - %2", _idKey,_type]; - - //Create it - _object = createVehicle [_type, _pos, [], 0, "CAN_COLLIDE"]; - _object setVariable ["lastUpdate",time]; - _object setVariable ["ObjectID", _idKey, true]; - - _lockable = 0; - if(isNumber (configFile >> "CfgVehicles" >> _type >> "lockable")) then { - _lockable = getNumber(configFile >> "CfgVehicles" >> _type >> "lockable"); + + _objArray = [_countr,_idKey,_type,_ownerID,_worldspace,_intentory,_hitPoints,_fuel,_damage]; + + switch true do { + case (_type isKindOf "ModularItems"): { + dayz_BuildingQueue set [(count dayz_BuildingQueue),_objArray]; }; - - // fix for leading zero issues on safe codes after restart - if (_lockable == 4) then { - _codeCount = (count (toArray _ownerID)); - if(_codeCount == 3) then { - _ownerID = format["0%1", _ownerID]; - }; - if(_codeCount == 2) then { - _ownerID = format["00%1", _ownerID]; - }; - if(_codeCount == 1) then { - _ownerID = format["000%1", _ownerID]; - }; + default { + dayz_objectQueue set [(count dayz_objectQueue),_objArray]; }; - - if (_lockable == 3) then { - _codeCount = (count (toArray _ownerID)); - if(_codeCount == 2) then { - _ownerID = format["0%1", _ownerID]; - }; - if(_codeCount == 1) then { - _ownerID = format["00%1", _ownerID]; - }; - }; - - _object setVariable ["CharacterID", _ownerID, true]; - - clearWeaponCargoGlobal _object; - clearMagazineCargoGlobal _object; - // _object setVehicleAmmo DZE_vehicleAmmo; - - if ((typeOf _object) in dayz_allowedObjects) then { - _object addMPEventHandler ["MPKilled",{_this call object_handleServerKilled;}]; - // Test disabling simulation server side on buildables only. - _object enableSimulation false; - // used for inplace upgrades and lock/unlock of safe - _object setVariable ["OEMPos", _pos, true]; - }; - - _object setdir _dir; - _object setposATL _pos; - _object setDamage _damage; - - if (count _intentory > 0) then { - if (_type in DZE_LockedStorage) then { - // Fill variables with loot - _object setVariable ["WeaponCargo", (_intentory select 0), true]; - _object setVariable ["MagazineCargo", (_intentory select 1), true]; - _object setVariable ["BackpackCargo", (_intentory select 2), true]; - } else { - - //Add weapons - _objWpnTypes = (_intentory select 0) select 0; - _objWpnQty = (_intentory select 0) select 1; - _countr = 0; - { - if(_x in (DZE_REPLACE_WEAPONS select 0)) then { - _x = (DZE_REPLACE_WEAPONS select 1) select ((DZE_REPLACE_WEAPONS select 0) find _x); - }; - _isOK = isClass(configFile >> "CfgWeapons" >> _x); - if (_isOK) then { - _block = getNumber(configFile >> "CfgWeapons" >> _x >> "stopThis") == 1; - if (!_block) then { - _object addWeaponCargoGlobal [_x,(_objWpnQty select _countr)]; - }; - }; - _countr = _countr + 1; - } forEach _objWpnTypes; - - //Add Magazines - _objWpnTypes = (_intentory select 1) select 0; - _objWpnQty = (_intentory select 1) select 1; - _countr = 0; - { - if (_x == "BoltSteel") then { _x = "WoodenArrow" }; // Convert BoltSteel to WoodenArrow - if (_x == "ItemTent") then { _x = "ItemTentOld" }; - _isOK = isClass(configFile >> "CfgMagazines" >> _x); - if (_isOK) then { - _block = getNumber(configFile >> "CfgMagazines" >> _x >> "stopThis") == 1; - if (!_block) then { - _object addMagazineCargoGlobal [_x,(_objWpnQty select _countr)]; - }; - }; - _countr = _countr + 1; - } forEach _objWpnTypes; - - //Add Backpacks - _objWpnTypes = (_intentory select 2) select 0; - _objWpnQty = (_intentory select 2) select 1; - _countr = 0; - { - _isOK = isClass(configFile >> "CfgVehicles" >> _x); - if (_isOK) then { - _block = getNumber(configFile >> "CfgVehicles" >> _x >> "stopThis") == 1; - if (!_block) then { - _object addBackpackCargoGlobal [_x,(_objWpnQty select _countr)]; - }; - }; - _countr = _countr + 1; - } forEach _objWpnTypes; - }; - }; - - if (_object isKindOf "AllVehicles") then { - { - _selection = _x select 0; - _dam = _x select 1; - if (_selection in dayZ_explosiveParts and _dam > 0.8) then {_dam = 0.8}; - [_object,_selection,_dam] call object_setFixServer; - } forEach _hitpoints; - - _object setFuel _fuel; - - if (!((typeOf _object) in dayz_allowedObjects)) then { - - //_object setvelocity [0,0,1]; - _object call fnc_veh_ResetEH; - - if(_ownerID != "0" and !(_object isKindOf "Bicycle")) then { - _object setvehiclelock "locked"; - }; - - _totalvehicles = _totalvehicles + 1; - - // total each vehicle - serverVehicleCounter set [count serverVehicleCounter,_type]; - }; - }; - - //Monitor the object - PVDZE_serverObjectMonitor set [count PVDZE_serverObjectMonitor,_object]; }; } forEach _objectArray; // # END OF STREAMING # + + // # NOW SPAWN OBJECTS # + _totalvehicles = 0; + { + _ObjArray = _x; + + { + _idKey = _x select 1; + _type = _x select 2; + _ownerID = _x select 3; + _worldspace = _x select 4; + _intentory= _x select 5; + _hitPoints= _x select 6; + _fuel = _x select 7; + _damage = _x select 8; + + _dir = 0; + _pos = [0,0,0]; + _wsDone = false; + if (count _worldspace >= 2) then + { + _dir = _worldspace select 0; + if (count (_worldspace select 1) == 3) then { + _pos = _worldspace select 1; + _wsDone = true; + } + }; + + if (!_wsDone) then { + if (count _worldspace >= 1) then { _dir = _worldspace select 0; }; + _pos = [getMarkerPos "center",0,4000,10,0,2000,0] call BIS_fnc_findSafePos; + if (count _pos < 3) then { _pos = [_pos select 0,_pos select 1,0]; }; + diag_log ("MOVED OBJ: " + str(_idKey) + " of class " + _type + " to pos: " + str(_pos)); + }; + + + if (_damage < 1) then { + //diag_log format["OBJ: %1 - %2", _idKey,_type]; + + //Create it + _object = createVehicle [_type, _pos, [], 0, "CAN_COLLIDE"]; + _object setVariable ["lastUpdate",time]; + _object setVariable ["ObjectID", _idKey, true]; + + _lockable = 0; + if(isNumber (configFile >> "CfgVehicles" >> _type >> "lockable")) then { + _lockable = getNumber(configFile >> "CfgVehicles" >> _type >> "lockable"); + }; + + // fix for leading zero issues on safe codes after restart + if (_lockable == 4) then { + _codeCount = (count (toArray _ownerID)); + if(_codeCount == 3) then { + _ownerID = format["0%1", _ownerID]; + }; + if(_codeCount == 2) then { + _ownerID = format["00%1", _ownerID]; + }; + if(_codeCount == 1) then { + _ownerID = format["000%1", _ownerID]; + }; + }; + + if (_lockable == 3) then { + _codeCount = (count (toArray _ownerID)); + if(_codeCount == 2) then { + _ownerID = format["0%1", _ownerID]; + }; + if(_codeCount == 1) then { + _ownerID = format["00%1", _ownerID]; + }; + }; + + _object setVariable ["CharacterID", _ownerID, true]; + + clearWeaponCargoGlobal _object; + clearMagazineCargoGlobal _object; + // _object setVehicleAmmo DZE_vehicleAmmo; + + if ((typeOf _object) in dayz_allowedObjects) then { + _object addMPEventHandler ["MPKilled",{_this call object_handleServerKilled;}]; + // Test disabling simulation server side on buildables only. + _object enableSimulation false; + // used for inplace upgrades and lock/unlock of safe + _object setVariable ["OEMPos", _pos, true]; + }; + + _object setdir _dir; + _object setposATL _pos; + _object setDamage _damage; + + if (count _intentory > 0) then { + if (_type in DZE_LockedStorage) then { + // Fill variables with loot + _object setVariable ["WeaponCargo", (_intentory select 0), true]; + _object setVariable ["MagazineCargo", (_intentory select 1), true]; + _object setVariable ["BackpackCargo", (_intentory select 2), true]; + } else { + + //Add weapons + _objWpnTypes = (_intentory select 0) select 0; + _objWpnQty = (_intentory select 0) select 1; + _countr = 0; + { + if(_x in (DZE_REPLACE_WEAPONS select 0)) then { + _x = (DZE_REPLACE_WEAPONS select 1) select ((DZE_REPLACE_WEAPONS select 0) find _x); + }; + _isOK = isClass(configFile >> "CfgWeapons" >> _x); + if (_isOK) then { + _block = getNumber(configFile >> "CfgWeapons" >> _x >> "stopThis") == 1; + if (!_block) then { + _object addWeaponCargoGlobal [_x,(_objWpnQty select _countr)]; + }; + }; + _countr = _countr + 1; + } forEach _objWpnTypes; + + //Add Magazines + _objWpnTypes = (_intentory select 1) select 0; + _objWpnQty = (_intentory select 1) select 1; + _countr = 0; + { + if (_x == "BoltSteel") then { _x = "WoodenArrow" }; // Convert BoltSteel to WoodenArrow + if (_x == "ItemTent") then { _x = "ItemTentOld" }; + _isOK = isClass(configFile >> "CfgMagazines" >> _x); + if (_isOK) then { + _block = getNumber(configFile >> "CfgMagazines" >> _x >> "stopThis") == 1; + if (!_block) then { + _object addMagazineCargoGlobal [_x,(_objWpnQty select _countr)]; + }; + }; + _countr = _countr + 1; + } forEach _objWpnTypes; + + //Add Backpacks + _objWpnTypes = (_intentory select 2) select 0; + _objWpnQty = (_intentory select 2) select 1; + _countr = 0; + { + _isOK = isClass(configFile >> "CfgVehicles" >> _x); + if (_isOK) then { + _block = getNumber(configFile >> "CfgVehicles" >> _x >> "stopThis") == 1; + if (!_block) then { + _object addBackpackCargoGlobal [_x,(_objWpnQty select _countr)]; + }; + }; + _countr = _countr + 1; + } forEach _objWpnTypes; + }; + }; + + if (_object isKindOf "AllVehicles") then { + { + _selection = _x select 0; + _dam = _x select 1; + if (_selection in dayZ_explosiveParts and _dam > 0.8) then {_dam = 0.8}; + [_object,_selection,_dam] call object_setFixServer; + } forEach _hitpoints; + + _object setFuel _fuel; + + if (!((typeOf _object) in dayz_allowedObjects)) then { + + //_object setvelocity [0,0,1]; + _object call fnc_veh_ResetEH; + + if(_ownerID != "0" and !(_object isKindOf "Bicycle")) then { + _object setvehiclelock "locked"; + }; + + _totalvehicles = _totalvehicles + 1; + + // total each vehicle + serverVehicleCounter set [count serverVehicleCounter,_type]; + }; + }; + + //Monitor the object + PVDZE_serverObjectMonitor set [count PVDZE_serverObjectMonitor,_object]; + }; + } forEach _ObjArray; + } forEach [dayz_BuildingQueue,dayz_objectQueue]; // Put arrays in order that you wish them to spawn + + dayz_BuildingQueue = nil; + dayz_objectQueue = nil; + + // # END SPAWN OBJECTS # + // preload server traders menu data into cache { From d5a0ec41b17f14b8676cdaeccf1c45ba68e15640 Mon Sep 17 00:00:00 2001 From: Zac Surplice Date: Mon, 23 Dec 2013 13:18:03 +1100 Subject: [PATCH 2/3] some optimisations (thanks skaro for advice) --- SQF/dayz_server/system/server_monitor.sqf | 55 +++++++---------------- 1 file changed, 17 insertions(+), 38 deletions(-) diff --git a/SQF/dayz_server/system/server_monitor.sqf b/SQF/dayz_server/system/server_monitor.sqf index 08445012f..36996a982 100644 --- a/SQF/dayz_server/system/server_monitor.sqf +++ b/SQF/dayz_server/system/server_monitor.sqf @@ -49,6 +49,9 @@ if (isServer and isNil "sm_done") then { _i = 99; // break }; }; + + _BuildingQueue = []; + _objectQueue = []; _objectArray = []; if ((_hiveResponse select 0) == "ObjectStreamStart") then { @@ -58,47 +61,26 @@ if (isServer and isNil "sm_done") then { _hiveResponse = _key call server_hiveReadWriteLarge; _objectArray set [_i - 1, _hiveResponse]; //diag_log (format["HIVE dbg %1 %2", typeName _hiveResponse, _hiveResponse]); + + _type = (_hiveResponse select _i) select 2; + + switch true do { + case (_type isKindOf "ModularItems"): { + _BuildingQueue set [(count _BuildingQueue),_hiveResponse]; + }; + default { + _objectQueue set [(count _objectQueue),_hiveResponse]; + }; + }; }; diag_log ("HIVE: got " + str(count _objectArray) + " objects"); }; - - dayz_BuildingQueue = []; - dayz_objectQueue = []; - // # START OF STREAMING # - _countr = 0; - { - //Parse Array - _countr = _countr + 1; - - _idKey = _x select 1; - _type = _x select 2; - _ownerID = _x select 3; - - _worldspace = _x select 4; - _intentory= _x select 5; - _hitPoints= _x select 6; - _fuel = _x select 7; - _damage = _x select 8; - - _objArray = [_countr,_idKey,_type,_ownerID,_worldspace,_intentory,_hitPoints,_fuel,_damage]; - - switch true do { - case (_type isKindOf "ModularItems"): { - dayz_BuildingQueue set [(count dayz_BuildingQueue),_objArray]; - }; - default { - dayz_objectQueue set [(count dayz_objectQueue),_objArray]; - }; - }; - } forEach _objectArray; - // # END OF STREAMING # + _spawnSort = [_BuildingQueue,_objectQueue]; // Put arrays in order that you wish them to spawn // # NOW SPAWN OBJECTS # _totalvehicles = 0; { - _ObjArray = _x; - { _idKey = _x select 1; _type = _x select 2; @@ -274,11 +256,8 @@ if (isServer and isNil "sm_done") then { //Monitor the object PVDZE_serverObjectMonitor set [count PVDZE_serverObjectMonitor,_object]; }; - } forEach _ObjArray; - } forEach [dayz_BuildingQueue,dayz_objectQueue]; // Put arrays in order that you wish them to spawn - - dayz_BuildingQueue = nil; - dayz_objectQueue = nil; + } forEach _x; + } forEach _spawnSort; // # END SPAWN OBJECTS # From 30c7af8d04165f802a0d502b0539156fe7f74df6 Mon Sep 17 00:00:00 2001 From: Zac Surplice Date: Mon, 23 Dec 2013 13:21:46 +1100 Subject: [PATCH 3/3] derp --- SQF/dayz_server/system/server_monitor.sqf | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/SQF/dayz_server/system/server_monitor.sqf b/SQF/dayz_server/system/server_monitor.sqf index 36996a982..0b684e3c1 100644 --- a/SQF/dayz_server/system/server_monitor.sqf +++ b/SQF/dayz_server/system/server_monitor.sqf @@ -1,4 +1,4 @@ -private ["_nul","_result","_pos","_wsDone","_dir","_block","_isOK","_countr","_objWpnTypes","_objWpnQty","_dam","_selection","_totalvehicles","_object","_idKey","_type","_ownerID","_worldspace","_intentory","_hitPoints","_fuel","_damage","_date","_key","_outcome","_vehLimit","_hiveResponse","_objectCount","_codeCount","_objectArray","_hour","_minute","_data","_status","_val","_traderid","_retrader","_traderData","_id","_lockable","_debugMarkerPosition","_vehicle_0"]; +private ["_nul","_result","_pos","_wsDone","_dir","_block","_isOK","_countr","_objWpnTypes","_objWpnQty","_dam","_selection","_totalvehicles","_object","_idKey","_type","_ownerID","_worldspace","_intentory","_hitPoints","_fuel","_damage","_date","_key","_outcome","_vehLimit","_hiveResponse","_objectCount","_codeCount","_hour","_minute","_data","_status","_val","_traderid","_retrader","_traderData","_id","_lockable","_debugMarkerPosition","_vehicle_0"]; dayz_versionNo = getText(configFile >> "CfgMods" >> "DayZ" >> "version"); dayz_hiveVersionNo = getNumber(configFile >> "CfgMods" >> "DayZ" >> "hiveVersion"); @@ -53,16 +53,14 @@ if (isServer and isNil "sm_done") then { _BuildingQueue = []; _objectQueue = []; - _objectArray = []; if ((_hiveResponse select 0) == "ObjectStreamStart") then { _objectCount = _hiveResponse select 1; diag_log ("HIVE: Commence Object Streaming..."); for "_i" from 1 to _objectCount do { _hiveResponse = _key call server_hiveReadWriteLarge; - _objectArray set [_i - 1, _hiveResponse]; //diag_log (format["HIVE dbg %1 %2", typeName _hiveResponse, _hiveResponse]); - _type = (_hiveResponse select _i) select 2; + _type = _hiveResponse select 2; switch true do { case (_type isKindOf "ModularItems"): { @@ -73,7 +71,8 @@ if (isServer and isNil "sm_done") then { }; }; }; - diag_log ("HIVE: got " + str(count _objectArray) + " objects"); + _count = (count _objectQueue) + (count _BuildingQueue); + diag_log ("HIVE: got " + str(_count) + " objects"); }; _spawnSort = [_BuildingQueue,_objectQueue]; // Put arrays in order that you wish them to spawn