-
Notifications
You must be signed in to change notification settings - Fork 139
Expand file tree
/
Copy pathclient.lua
More file actions
111 lines (103 loc) · 3.61 KB
/
Copy pathclient.lua
File metadata and controls
111 lines (103 loc) · 3.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
local CurrentWeather = Config.StartWeather
local lastWeather = CurrentWeather
local baseTime = Config.BaseTime
local timeOffset = Config.TimeOffset
local freezeTime = Config.FreezeTime
local blackout = Config.Blackout
local blackoutVehicle = Config.BlackoutVehicle
local disable = Config.Disabled
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
TriggerServerEvent('qb-weathersync:server:RequestStateSync')
end)
RegisterNetEvent('qb-weathersync:client:EnableSync', function()
disable = false
TriggerServerEvent('qb-weathersync:server:RequestStateSync')
end)
RegisterNetEvent('qb-weathersync:client:DisableSync', function()
disable = true
SetRainLevel(0.0)
SetWeatherTypePersist('CLEAR')
SetWeatherTypeNow('CLEAR')
SetWeatherTypeNowPersist('CLEAR')
NetworkOverrideClockTime(18, 0, 0)
end)
RegisterNetEvent('qb-weathersync:client:SyncWeather', function(NewWeather, newblackout)
CurrentWeather = NewWeather
blackout = newblackout
end)
RegisterNetEvent('qb-weathersync:client:SyncTime', function(base, offset, freeze)
freezeTime = freeze
timeOffset = offset
baseTime = base
end)
CreateThread(function()
while true do
if not disable then
if lastWeather ~= CurrentWeather then
lastWeather = CurrentWeather
SetWeatherTypeOverTime(CurrentWeather, 15.0)
Wait(15000)
end
Wait(100) -- Wait 0 seconds to prevent crashing.
SetArtificialLightsState(blackout)
SetArtificialLightsStateAffectsVehicles(blackoutVehicle)
ClearOverrideWeather()
ClearWeatherTypePersist()
SetWeatherTypePersist(lastWeather)
SetWeatherTypeNow(lastWeather)
SetWeatherTypeNowPersist(lastWeather)
if lastWeather == 'XMAS' then
SetForceVehicleTrails(true)
SetForcePedFootstepsTracks(true)
else
SetForceVehicleTrails(false)
SetForcePedFootstepsTracks(false)
end
if lastWeather == 'RAIN' then
SetRainLevel(0.3)
elseif lastWeather == 'THUNDER' then
SetRainLevel(0.5)
else
SetRainLevel(0.0)
end
else
Wait(1000)
end
end
end)
CreateThread(function()
local hour
local minute = 0
local second = 0 --Add seconds for shadow smoothness
local timeIncrement = Config.RealTimeSync and 0.25 or 1
local tick = GetGameTimer()
while true do
if not disable then
Wait(0)
local _, _, _, hours, minutes, _ = GetLocalTime()
local newBaseTime = baseTime
if tick - (Config.RealTimeSync and 500 or 22) > tick then
second = second + timeIncrement
tick = GetGameTimer()
end
if freezeTime then
timeOffset = timeOffset + baseTime - newBaseTime
second = 0
end
baseTime = newBaseTime
if Config.RealTimeSync then
hour = hours
minute = minutes
else
hour = math.floor(((baseTime + timeOffset) / 60) % 24)
if minute ~= math.floor((baseTime + timeOffset) % 60) then --Reset seconds to 0 when new minute
minute = math.floor((baseTime + timeOffset) % 60)
second = 0
end
end
NetworkOverrideClockTime(hour, minute, second) --Send hour included seconds to network clock time
else
Wait(1000)
end
end
end)