local encoding = require 'encoding'
encoding.default = 'CP1251'
local u8 = encoding.UTF8
local function toCP1251(str)
return u8:decode(str)
end
local custom_weather = nil
local custom_hour = nil
local custom_minute = 0
function main()
while not isSampAvailable() do wait(100) end
sampAddChatMessage(toCP1251("[Weather/Time]: Скрипт успешно загружен! Команды: /setw [ID] и /sett [ч] [м]"), 0x0088FF)
sampRegisterChatCommand("setw", function(param)
local w = tonumber(param)
if w then
custom_weather = w
forceWeatherNow(w)
sampAddChatMessage(toCP1251(string.format("[Weather/Time]: Погода установлена на ID %d", w)), 0x00FF00)
else
sampAddChatMessage(toCP1251("[Weather/Time]: Использование: /setw [0-45]"), 0xFF0000)
end
end)
sampRegisterChatCommand("sett", function(param)
local h, m = param:match("(%d+)%s*(%d*)")
if h then
custom_hour = tonumber(h)
custom_minute = tonumber(m) or 0
setTimeOfDay(custom_hour, custom_minute)
sampAddChatMessage(toCP1251(string.format("[Weather/Time]: Время установлено на %02d:%02d", custom_hour, custom_minute)), 0x00FF00)
else
sampAddChatMessage(toCP1251("[Weather/Time]: Использование: /sett [0-23] [0-59]"), 0xFF0000)
end
end)
while true do
wait(250)
if custom_weather ~= nil then
forceWeatherNow(custom_weather)
end
if custom_hour ~= nil then
setTimeOfDay(custom_hour, custom_minute)
end
end
end