forked from DevTestingPizza/vSync
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathclient.lua
93 lines (85 loc) · 3.38 KB
/
client.lua
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
CurrentWeather = 'EXTRASUNNY'
local lastWeather = CurrentWeather
local baseTime = 0
local timeOffset = 0
local timer = 0
local freezeTime = false
local blackout = false
RegisterNetEvent('weathertimesync:updateWeather')
AddEventHandler('weathertimesync:updateWeather', function(NewWeather, newblackout)
CurrentWeather = NewWeather
blackout = newblackout
end)
Citizen.CreateThread(function()
while true do
if lastWeather ~= CurrentWeather then
lastWeather = CurrentWeather
SetWeatherTypeOverTime(CurrentWeather, 15.0)
Citizen.Wait(15000)
end
Citizen.Wait(100) -- Wait 0 seconds to prevent crashing.
SetBlackout(blackout)
ClearOverrideWeather()
ClearWeatherTypePersist()
SetWeatherTypePersist(lastWeather)
SetWeatherTypeNow(lastWeather)
SetWeatherTypeNowPersist(lastWeather)
if lastWeather == 'XMAS' then
SetForceVehicleTrails(true)
SetForcePedFootstepsTracks(true)
else
SetForceVehicleTrails(false)
SetForcePedFootstepsTracks(false)
end
end
end)
RegisterNetEvent('weathertimesync:updateTime')
AddEventHandler('weathertimesync:updateTime', function(base, offset, freeze)
freezeTime = freeze
timeOffset = offset
baseTime = base
end)
Citizen.CreateThread(function()
local hour = 0
local minute = 0
while true do
Citizen.Wait(0)
local newBaseTime = baseTime
if GetGameTimer() - 500 > timer then
newBaseTime = newBaseTime + 0.25
timer = GetGameTimer()
end
if freezeTime then
timeOffset = timeOffset + baseTime - newBaseTime
end
baseTime = newBaseTime
hour = math.floor(((baseTime+timeOffset)/60)%24)
minute = math.floor((baseTime+timeOffset)%60)
NetworkOverrideClockTime(hour, minute, 0)
end
end)
AddEventHandler('playerSpawned', function()
TriggerServerEvent('weathertimesync:requestSync')
end)
Citizen.CreateThread(function()
TriggerEvent('chat:addSuggestion', '/weather', 'Change the weather.', {{ name="weatherType", help="Available types: extrasunny, clear, neutral, smog, foggy, overcast, clouds, clearing, rain, thunder, snow, blizzard, snowlight, xmas & halloween"}})
TriggerEvent('chat:addSuggestion', '/time', 'Change the time.', {{ name="hours", help="A number between 0 - 23"}, { name="minutes", help="A number between 0 - 59"}})
TriggerEvent('chat:addSuggestion', '/freezetime', 'Freeze / unfreeze time.')
TriggerEvent('chat:addSuggestion', '/freezeweather', 'Enable/disable dynamic weather changes.')
TriggerEvent('chat:addSuggestion', '/morning', 'Set the time to 09:00')
TriggerEvent('chat:addSuggestion', '/noon', 'Set the time to 12:00')
TriggerEvent('chat:addSuggestion', '/evening', 'Set the time to 18:00')
TriggerEvent('chat:addSuggestion', '/night', 'Set the time to 23:00')
TriggerEvent('chat:addSuggestion', '/blackout', 'Toggle blackout mode.')
end)
-- Display a notification above the minimap.
function ShowNotification(text, blink)
if blink == nil then blink = false end
SetNotificationTextEntry("STRING")
AddTextComponentSubstringPlayerName(text)
DrawNotification(blink, false)
end
RegisterNetEvent('weathertimesync:notify')
AddEventHandler('weathertimesync:notify', function(message, blink)
ShowNotification(message, blink)
end)