Время

Seaside_

Участник
Автор темы
64
2
Версия MoonLoader
.026-beta
Как в скрипт вставить точное московское время. К примеру, вводят какую нибудь команду скрипта и он в чат выводит время и какие нибудь слова
что то типо этого
Lua:
function main()
         sampRegisterChatCommand('time', time)
         while true do
         wait(0)
         end
        end
        
        function time()
         sampAddChatMessage('Время' ..time)
        end
 
Решение
Lua:
local requests = require('requests')
local cjson = require('cjson')

local function getTime()
    local response_table = cjson.decode(requests.get('http://worldtimeapi.org/api/timezone/europe/moscow').text)
    local currentTime = response_table.datetime:match('.+T(.+)%.')
    if currentTime then sampAddChatMessage('Время: '..currentTime, -1) end
end

function main()
    repeat wait(0) until isSampAvailable()
    sampRegisterChatCommand('gettime', getTime)
    wait(-1)
end

sᴀxᴏɴ

#Mary
Всефорумный модератор
791
846
Lua:
local requests = require('requests')
local cjson = require('cjson')

local function getTime()
    local response_table = cjson.decode(requests.get('http://worldtimeapi.org/api/timezone/europe/moscow').text)
    local currentTime = response_table.datetime:match('.+T(.+)%.')
    if currentTime then sampAddChatMessage('Время: '..currentTime, -1) end
end

function main()
    repeat wait(0) until isSampAvailable()
    sampRegisterChatCommand('gettime', getTime)
    wait(-1)
end
 
  • Нравится
Реакции: kru_tin