-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat(syncweather): use player states for disabling syncing, refactor …
…qb-compat
- Loading branch information
Showing
3 changed files
with
82 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,54 @@ | ||
local timeScale = GlobalState.timeScale | ||
local currentTime = GlobalState.currentTime | ||
local timeFrozen = GlobalState.freezeTime | ||
local playerState = LocalPlayer.state | ||
|
||
AddStateBagChangeHandler('currentTime', nil, function(bagName, _, value) | ||
if bagName == 'global' and value and next(value) then | ||
NetworkOverrideClockTime(value.hour, value.minute, 0) | ||
|
||
if playerState.syncWeather then | ||
NetworkOverrideClockTime(value.hour, value.minute, 0) | ||
end | ||
|
||
currentTime = value | ||
end | ||
end) | ||
|
||
AddStateBagChangeHandler('timeScale', nil, function(bagName, _, value) | ||
if bagName == 'global' and value then | ||
NetworkOverrideClockMillisecondsPerGameMinute(value) | ||
|
||
if playerState.syncWeather then | ||
NetworkOverrideClockMillisecondsPerGameMinute(value) | ||
end | ||
|
||
timeScale = value | ||
end | ||
end) | ||
|
||
AddStateBagChangeHandler('freezeTime', nil, function(bagName, _, value) | ||
if bagName == 'global' then | ||
NetworkOverrideClockMillisecondsPerGameMinute(value and 99999999 or timeScale) | ||
|
||
if playerState.syncWeather then | ||
NetworkOverrideClockMillisecondsPerGameMinute(value and 99999999 or timeScale) | ||
end | ||
|
||
timeFrozen = value | ||
end | ||
end) | ||
|
||
NetworkOverrideClockMillisecondsPerGameMinute(timeScale) | ||
|
||
AddStateBagChangeHandler('syncWeather', ('player:%s'):format(cache.serverId), function(_, _, value) | ||
if value then | ||
NetworkOverrideClockTime(currentTime.hour, currentTime.minute, 0) | ||
if not timeFrozen then | ||
NetworkOverrideClockMillisecondsPerGameMinute(timeScale) | ||
end | ||
else | ||
NetworkOverrideClockMillisecondsPerGameMinute(99999999) | ||
NetworkOverrideClockTime(18, 0, 0) | ||
end | ||
end) | ||
|
||
|
||
require 'compatability.qb.client' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,10 @@ | ||
if GetResourceState('qb-core') == 'missing' and GetResourceState('qbx_core') == 'missing' then return end | ||
local playerState = LocalPlayer.state | ||
|
||
local disablesync = false | ||
local currentTime = GlobalState.currentTime | ||
local currentWeather = GlobalState.weather | ||
|
||
AddStateBagChangeHandler('currentTime', nil, function(bagName, _, value) | ||
if bagName == 'global' and value and next(value) then | ||
currentTime = value | ||
end | ||
end) | ||
|
||
AddStateBagChangeHandler('weather', nil, function(bagName, _, value) | ||
if value and bagName == 'global' then | ||
currentWeather = value | ||
end | ||
RegisterNetEvent('qb-weathersync:client:DisableSync', function() | ||
playerState.syncWeather = false | ||
end) | ||
|
||
local function disabledSync() | ||
if not disablesync then | ||
disablesync = true | ||
NetworkOverrideClockMillisecondsPerGameMinute(99999999) | ||
CreateThread(function() | ||
while disablesync do | ||
SetRainLevel(0.0) | ||
SetWeatherTypePersist('CLEAR') | ||
SetWeatherTypeNow('CLEAR') | ||
SetWeatherTypeNowPersist('CLEAR') | ||
NetworkOverrideClockTime(18, 0, 0) | ||
Wait(5000) | ||
end | ||
end) | ||
end | ||
end | ||
|
||
local function enabledSync() | ||
if disablesync then | ||
NetworkOverrideClockTime(currentTime.hour, currentTime.minute, 0) | ||
|
||
if not GlobalState.freezeTime then | ||
NetworkOverrideClockMillisecondsPerGameMinute(GlobalState.timeScale) | ||
end | ||
|
||
SetWeatherTypePersist(currentWeather.weather) | ||
SetWeatherTypeNow(currentWeather.weather) | ||
SetWeatherTypeNowPersist(currentWeather.weather) | ||
|
||
disablesync = false | ||
end | ||
end | ||
|
||
RegisterNetEvent('qb-weathersync:client:DisableSync', disabledSync) | ||
RegisterNetEvent('qb-weathersync:client:EnableSync', enabledSync) | ||
RegisterNetEvent('qb-weathersync:client:EnableSync', function() | ||
playerState.syncWeather = true | ||
end) |