Skip to content

Commit

Permalink
feat: isNight globalstate
Browse files Browse the repository at this point in the history
add isNight and change some requires to lib.load
  • Loading branch information
FjamZoo authored Jul 7, 2024
2 parents f3de8fc + 4f6c055 commit 1951c19
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
6 changes: 3 additions & 3 deletions compatability/qb/server.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local Config = require 'config.weather'
local Config = lib.load('config.weather')

local globalState = GlobalState

Expand All @@ -9,11 +9,11 @@ local function exportHandler(exportName, func)
end

exportHandler('nextWeatherStage', function()
return print("RENEWED WEATHERSYNC - THIS EXPORT IS NOT SUPPORTED")
return print("RENEWED WEATHERSYNC - THIS EXPORT IS NOT SUPPORTED (nextWeatherStage)")
end)

exportHandler('setDynamicWeather', function()
return print("RENEWED WEATHERSYNC - THIS EXPORT IS NOT SUPPORTED")
return print("RENEWED WEATHERSYNC - THIS EXPORT IS NOT SUPPORTED (setDynamicWeather)")
end)


Expand Down
2 changes: 1 addition & 1 deletion config/time.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
return {
timeScale = 4000, -- How many milliseconds per minute in GTA time (2000ms is normal for a 48 minute day)

useNightScale = true, -- If true, the server will use timeScaleNight to alter the time during night
useNightScale = false, -- If true, the server will use timeScaleNight to alter the time during night
timeScaleNight = 8000, -- How many milliseconds per minute in GTA time DURING NIGHT

nightTime = {
Expand Down
8 changes: 6 additions & 2 deletions server/time.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local Config = require 'config.time'
local Config = lib.load('config.time')

local globalState = GlobalState

Expand All @@ -16,7 +16,7 @@ local hour = startTime.hour
-- Syncs the GlobalStates (does not replicate if the values are the same)
globalState.timeScale = currentScale
globalState.freezeTime = freezeTime

globalState.isNight = hour >= Config.nightTime.beginning or hour < Config.nightTime.ending

-- Loop that syncs the minute and hours of the servers to clients.
CreateThread(function()
Expand All @@ -43,6 +43,7 @@ end)

local nightScale = Config.timeScaleNight
local nightStart, nightEnd = Config.nightTime.beginning, Config.nightTime.ending

AddStateBagChangeHandler('currentTime', 'global', function(_, _, value)
if value then
hour = value.hour
Expand All @@ -58,6 +59,9 @@ AddStateBagChangeHandler('currentTime', 'global', function(_, _, value)
end
end
end

globalState.isNight = hour >= Config.nightTime.beginning or hour < Config.nightTime.ending

end)

AddStateBagChangeHandler('timeScale', 'global', function(_, _, value)
Expand Down
2 changes: 1 addition & 1 deletion server/weather.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local buildWeatherList = require 'server.weatherbuilder'

local useScheduledWeather = require 'config.weather'.useScheduledWeather
local useScheduledWeather = lib.load('config.weather').useScheduledWeather
local weatherList = buildWeatherList()

local overrideWeather = false
Expand Down
4 changes: 2 additions & 2 deletions server/weatherbuilder.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local Config = require 'config.weather'
local Config = lib.load('config.weather')

local currentMonth = tonumber(os.date('%m'))

Expand Down Expand Up @@ -68,7 +68,7 @@ local function isWeatherEventAllowed(chance, hasRain, minutesSinceRain, timeBefo
for i = weatherAmount - 5, weatherAmount do
if weatherList[i].weather == weather then
count += 1

if count > 1 then
return false
end
Expand Down

0 comments on commit 1951c19

Please sign in to comment.