Update sched_event.sqf

Optimizations.
This commit is contained in:
worldwidesorrow
2021-05-31 13:09:51 -05:00
parent e81bfad9ae
commit d60854c586

View File

@@ -4,15 +4,11 @@
*/ */
epoch_eventIsAny = { epoch_eventIsAny = {
private ["_boolReturn","_event","_date","_bool","_index"]; local _event = _this select 0;
_event = _this select 0; local _date = _this select 1;
_date = _this select 1; local _boolReturn = false;
local _index = 0;
_boolReturn = false;
_index = 0;
{ {
_bool = false;
if (typeName _x == "STRING") then { if (typeName _x == "STRING") then {
_boolReturn = true; _boolReturn = true;
} else { } else {
@@ -21,50 +17,41 @@ epoch_eventIsAny = {
if (!_boolReturn) exitWith {}; if (!_boolReturn) exitWith {};
_index = _index + 1; _index = _index + 1;
} count _event; } count _event;
_boolReturn _boolReturn
}; };
sched_event_init = { sched_event_init = {
diag_log("EPOCH EVENTS INIT"); diag_log formatText ["EPOCH EVENTS: %1 Events Scheduled",(count EpochEvents)];
"" ""
}; };
sched_event = { sched_event = {
private ["_date","_key","_result","_outcome","_handle","_datestr","_lastTime"];
// Find current time from server // Find current time from server
_lastTime = _this; local _lastTime = _this;
_key = "CHILD:307:"; local _key = "CHILD:307:";
_result = _key call server_hiveReadWrite; local _result = _key call server_hiveReadWrite;
_outcome = _result select 0; local _outcome = _result select 0;
if(_outcome == "PASS") then { if (_outcome == "PASS") then {
_date = _result select 1; local _date = _result select 1;
_datestr = str(_date); local _datestr = str(_date);
if (_lastTime != _datestr) then { if (_lastTime != _datestr) then {
// internal timestamp // internal timestamp
ServerCurrentTime = _date; ServerCurrentTime = _date;
// Once a minute.
_lastTime = _datestr; _lastTime = _datestr;
//diag_log ("EVENTS: Local Time is: " + _datestr);
if (count EpochEvents == 0) exitWith {};
{ {
// Run event at server start when minutes are set to -1 // Run event at server start when minutes are set to -1
if ((_x select 4) == -1) then { if ((_x select 4) == -1) then {
diag_log ("RUNNING EVENT: " + (_x select 5) + " on " + _datestr); diag_log ("RUNNING EVENT: " + (_x select 5) + " on " + _datestr);
_handle = [] execVM "\z\addons\dayz_server\modules\" + (_x select 5) + ".sqf"; local _handle = [] execVM "\z\addons\dayz_server\modules\" + (_x select 5) + ".sqf";
// Remove event from array so it doesn't run again. // Remove event from array so it doesn't run again.
_lastIndex = (count EpochEvents) - 1; EpochEvents = [EpochEvents,_forEachIndex] call fnc_deleteAt;
if (_lastIndex != _forEachIndex) then {EpochEvents set [_forEachIndex, EpochEvents select _lastIndex];};
EpochEvents resize _lastIndex;
} else { } else {
if([[(_x select 0),(_x select 1),(_x select 2),(_x select 3),(_x select 4)],_date] call epoch_eventIsAny) then { if([[(_x select 0),(_x select 1),(_x select 2),(_x select 3),(_x select 4)],_date] call epoch_eventIsAny) then {
diag_log ("RUNNING EVENT: " + (_x select 5) + " on " + _datestr); diag_log ("RUNNING EVENT: " + (_x select 5) + " on " + _datestr);
_handle = [] execVM "\z\addons\dayz_server\modules\" + (_x select 5) + ".sqf"; local _handle = [] execVM "\z\addons\dayz_server\modules\" + (_x select 5) + ".sqf";
}; };
}; };
} forEach EpochEvents; } forEach EpochEvents;