Skip to content

Commit ed5c199

Browse files
Merge branch 'main' into main
2 parents 1b7f475 + a1257e7 commit ed5c199

File tree

3 files changed

+85
-10
lines changed

3 files changed

+85
-10
lines changed

fxmanifest.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ game 'gta5'
33
lua54 'yes'
44
author 'Kakarot'
55
description 'Syncs the time & weather for all players on the server and allows editing by command'
6-
version '2.1.0'
6+
version '2.1.1'
77

88
shared_scripts {
99
'config.lua',

locales/ua.lua

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
local Translations = {
2+
weather = {
3+
now_frozen = 'Погода заморожена.',
4+
now_unfrozen = 'Погода більше не заморожена.',
5+
invalid_syntax = 'Невірний синтаксис, правильний: /weather <типпогоди> ',
6+
invalid_syntaxc = 'Невірний синтаксис, використай /weather <типпогоди>!',
7+
updated = 'Погода оновлена.',
8+
invalid = 'Невірний тип погоди. Доступні типи: \nEXTRASUNNY CLEAR NEUTRAL SMOG FOGGY OVERCAST CLOUDS CLEARING RAIN THUNDER SNOW BLIZZARD SNOWLIGHT XMAS HALLOWEEN',
9+
invalidc = 'Невірний тип погоди. Доступні типи: \nEXTRASUNNY CLEAR NEUTRAL SMOG FOGGY OVERCAST CLOUDS CLEARING RAIN THUNDER SNOW BLIZZARD SNOWLIGHT XMAS HALLOWEEN',
10+
willchangeto = 'Погода зміниться на: %{value}.',
11+
accessdenied = 'Доступ до команди /weather заборонено.',
12+
},
13+
dynamic_weather = {
14+
disabled = 'Динамічна зміна погоди вимкнена.',
15+
enabled = 'Динамічна зміна погоди увімкнена.',
16+
},
17+
time = {
18+
frozenc = 'Час заморожено.',
19+
unfrozenc = 'Час більше не заморожено.',
20+
now_frozen = 'Час заморожено.',
21+
now_unfrozen = 'Час більше не заморожено.',
22+
morning = 'Час встановлено на ранок.',
23+
noon = 'Час встановлено на полудень.',
24+
evening = 'Час встановлено на вечір.',
25+
night = 'Час встановлено на ніч.',
26+
change = 'Час змінено на %{value}:%{value2}.',
27+
changec = 'Час змінено на: %{value}!',
28+
invalid = 'Невірний синтаксис. Правильний: time <година> <хвилина> !',
29+
invalidc = 'Невірний синтаксис. Використай /time <година> <хвилина>!',
30+
access = 'Доступ до команди /time заборонено.',
31+
},
32+
blackout = {
33+
enabled = 'Режим блекауту увімкнено.',
34+
enabledc = 'Режим блекауту увімкнено.',
35+
disabled = 'Режим блекауту вимкнено.',
36+
disabledc = 'Режим блекауту вимкнено.',
37+
},
38+
help = {
39+
weathercommand = 'Змінити погоду.',
40+
weathertype = 'типпогоди',
41+
availableweather = 'Доступні типи: extrasunny, clear, neutral, smog, foggy, overcast, clouds, clearing, rain, thunder, snow, blizzard, snowlight, xmas та halloween',
42+
timecommand = 'Змінити час.',
43+
timehname = 'години',
44+
timemname = 'хвилини',
45+
timeh = 'Число від 0 до 23',
46+
timem = 'Число від 0 до 59',
47+
freezecommand = 'Заморозити / розморозити час.',
48+
freezeweathercommand = 'Увімкнути/вимкнути динамічну зміну погоди.',
49+
morningcommand = 'Встановити час на 09:00',
50+
nooncommand = 'Встановити час на 12:00',
51+
eveningcommand = 'Встановити час на 18:00',
52+
nightcommand = 'Встановити час на 23:00',
53+
blackoutcommand = 'Увімкнути/вимкнути режим блекауту.',
54+
},
55+
}
56+
57+
if GetConvar('qb_locale', 'en') == 'ua' then
58+
Lang = Lang or Locale:new({
59+
phrases = Translations,
60+
warnOnMissing = true
61+
})
62+
end

server/server.lua

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,21 +120,24 @@ local function setDynamicWeather(state)
120120
return Config.DynamicWeather
121121
end
122122

123-
--- Retrieves the current time from worldtimeapi.org
124-
--- @return number - Unix time
123+
--- Retrieves the current time from api.timezonedb.com
125124
local function retrieveTimeFromApi(callback)
126125
Citizen.CreateThread(function()
127126
PerformHttpRequest("https://worldtimeapi.org/api/ip", function(statusCode, response)
128127
if statusCode == 200 then
128+
local apiKey = "REPLACE_ME_TO_YOUR_API" -- 🔐 Replace with your actual key from your email
129+
local zone = "America/Los_Angeles" -- 🔐 Replace with your actual TimeZone, ex: America/Los_Angeles
130+
local url = "http://api.timezonedb.com/v2.1/get-time-zone?key=" .. apiKey .. "&format=json&by=zone&zone=" .. zone
131+
-- print(response) -- 🛠️ Debug: uncomment to inspect raw API response
132+
PerformHttpRequest(url, function(statusCode, response)
133+
if statusCode == 200 and response then
129134
local data = json.decode(response)
130-
if data == nil or data.unixtime == nil then
131-
callback(nil)
132-
else
133-
callback(data.unixtime)
135+
if data and data.timestamp then
136+
callback(data.timestamp)
137+
return
134138
end
135-
else
136-
callback(nil)
137139
end
140+
callback(nil)
138141
end, "GET", nil, nil)
139142
end)
140143
end
@@ -283,7 +286,7 @@ CreateThread(function()
283286
local failedCount = 0
284287

285288
while true do
286-
Wait(0)
289+
Wait(60000) -- ⏱️ Sync server time every 1 minute with real time API. Falls back to OS time if failed.
287290
local newBaseTime = os.time(os.date("!*t")) / 2 + 360 --Set the server time depending of OS time
288291
if Config.RealTimeSync then
289292
newBaseTime = os.time(os.date("!*t")) --Set the server time depending of OS time
@@ -311,6 +314,16 @@ CreateThread(function()
311314
end
312315
baseTime = newBaseTime
313316
end
317+
retrieveTimeFromApi(function(unixTime)
318+
if unixTime then
319+
baseTime = unixTime
320+
else
321+
baseTime = os.time(os.date("!*t"))
322+
end
323+
end)
324+
else
325+
baseTime = os.time(os.date("!*t")) / 2 + 360
326+
end
314327
end
315328
end)
316329

0 commit comments

Comments
 (0)