added msk time module

update
rubin 2 years ago
parent fde9db0f24
commit 87600f0e0c
  1. 29
      mafia-tools.lua

@ -2,6 +2,8 @@ script_name('mafia-tools')
script_author("Serhiy_Rubin")
script_version("29.01.2023")
inspect = require("inspect")
sampev = require 'samp.events'
inicfg = require "inicfg"
dlstatus = require("moonloader").download_status
@ -26,6 +28,17 @@ function main()
end
end
-->> MSK TIME
msk_time = {}
msk_time.update = 0
msk_time.time = 0
msk_time.get = function()
if msk_time.update == 0 then
return os.time()
end
return msk_time.time + (os.time() - msk_time.update)
end
-->> REQUEST
request = {}
request.send = {}
@ -40,7 +53,8 @@ request.loop = function()
sender = getLocalPlayerNickname(),
server = getServerAddress(),
room = config.data.room,
send = request.send
send = request.send,
rand = os.clock()
}
request.send = {}
local url = string.format("http://mafia.deadpoo.net/%s", encodeJson(request_table))
@ -51,13 +65,20 @@ request.loop = function()
addChatMessage("Сервер 'mafia-tools' не отвечает!")
break
end
else
addChatMessage("pezdqa")
end
end
end
end
request.handler = function(text)
local info = decodeJson(text)
if info["time"] ~= nil then
msk_time.update = os.time()
msk_time.time = info["time"]
end
if info["result"] == "ok" then
setClipboardText(inspect(info))
for sender, sender_data in pairs(info["data"]) do
for key, v in pairs(sender_data) do
if ammo_timer.data[key] ~= nil then
@ -86,6 +107,7 @@ ammo_timer.onServerMessage = function(color, message)
key = ammo_timer.last_ammo,
text = message:match("^ Следующее ограбление будет доступно в (%d+:%d+:%d+)")
}
request.wait = 0
end
end
end
@ -102,7 +124,7 @@ ammo_timer.loop = function()
if ammo_timer.data[key]["time"] == 0 then
return string.format("{%s}%s:{%s} %s", config.data.font.color1, key:upper(), config.data.font.color2, ammo_timer.data[key]["text"])
else
local min = math.floor((os.time() - ammo_timer.data[key]["time"]) / 60)
local min = math.floor((msk_time.get() - ammo_timer.data[key]["time"]) / 60)
return string.format("{%s}%s:{%s} %s (%d min)", config.data.font.color1, key:upper(), config.data.font.color2, ammo_timer.data[key]["text"], min)
end
end
@ -237,6 +259,7 @@ end
-->> EVENTS
function sampev.onServerMessage(color, message)
timer_2min.onServerMessage(color, message)
ammo_timer.onServerMessage(color, message)
end
function sampev.onSendPickedUpPickup(id)
local X, Y, Z = getCharCoordinates(PLAYER_PED)
@ -248,7 +271,7 @@ function sampev.onSendPickedUpPickup(id)
for k, v in pairs(ammo) do
local distance = getDistanceBetweenCoords3d(X, Y, Z, v.x, v.y, v.z)
if distance <= 5 then
biz = k
ammo_timer.last_ammo = k
end
end --> by Benya
end

Loading…
Cancel
Save