|
|
|
@ -1,7 +1,7 @@ |
|
|
|
|
script_name("TruckHUD") |
|
|
|
|
script_author("Serhiy_Rubin") |
|
|
|
|
script_version("2209011") |
|
|
|
|
|
|
|
|
|
collectgarbage("stop") |
|
|
|
|
|
|
|
|
|
local inicfg = require "inicfg" |
|
|
|
|
local dlstatus = require("moonloader").download_status |
|
|
|
@ -205,9 +205,6 @@ function main() |
|
|
|
|
end |
|
|
|
|
mon_time = inifiles.tmonitor.time |
|
|
|
|
|
|
|
|
|
if inifiles.Settings.ad then |
|
|
|
|
check_version(false) |
|
|
|
|
end |
|
|
|
|
menu[3].run = inifiles.Settings.Report |
|
|
|
|
font = renderCreateFont(inifiles.Render.FontName, inifiles.Render.FontSize, inifiles.Render.FontFlag) |
|
|
|
|
|
|
|
|
@ -216,6 +213,7 @@ function main() |
|
|
|
|
lua_thread.create(fastmap) |
|
|
|
|
lua_thread.create(renderTruckers) |
|
|
|
|
lua_thread.create(luChecker.checker) |
|
|
|
|
lua_thread.create(script_update.main) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -831,7 +829,7 @@ function doDialog() |
|
|
|
|
end |
|
|
|
|
if str:find("Î÷èñòèòü íåèñïîëüçóåìóþ ïàìÿòü ñêðèïòà") then |
|
|
|
|
local mem_do = string.format('%0.2f MB', (tonumber(gcinfo()) / 1000)) |
|
|
|
|
collectgarbage() |
|
|
|
|
~() |
|
|
|
|
sampAddChatMessage('Ïàìÿòè î÷èùåíà. Áûëî: '..mem_do..'. Ñòàëî: '..string.format('%0.2f MB', (tonumber(gcinfo()) / 1000)), -1) |
|
|
|
|
ShowDialog1(1) |
|
|
|
|
end |
|
|
|
@ -2121,55 +2119,6 @@ function loadEvents() |
|
|
|
|
function sampev.onSendCommand(cmd) |
|
|
|
|
local command, params = string.match(cmd, "^%/([^ ]*)(.*)") |
|
|
|
|
if command ~= nil and params ~= nil and command:lower() == "truck" then |
|
|
|
|
if params:lower() == " ad" then |
|
|
|
|
inifiles.Settings.ad = not inifiles.Settings.ad |
|
|
|
|
settings_save() |
|
|
|
|
sampAddChatMessage( |
|
|
|
|
string.format( |
|
|
|
|
"Óâåäîìëåíèÿ îá îáíîâëåíèÿõ Truck HUD %s", |
|
|
|
|
(inifiles.Settings.ad and "âêëþ÷åíû" or "âûêëþ÷åíû") |
|
|
|
|
), |
|
|
|
|
0xFF2f72f7 |
|
|
|
|
) |
|
|
|
|
return false |
|
|
|
|
end |
|
|
|
|
if params:lower() == " version" then |
|
|
|
|
lua_thread.create( |
|
|
|
|
function() |
|
|
|
|
local fpath = os.getenv("TEMP") .. "\\TruckHUD-up.txt" |
|
|
|
|
downloadUrlToFile( |
|
|
|
|
"http://thprivate.deadpoo.net/download/changelog", |
|
|
|
|
fpath, |
|
|
|
|
function(id, status, p1, p2) |
|
|
|
|
if stop_downloading_3 then |
|
|
|
|
stop_downloading_3 = false |
|
|
|
|
return false |
|
|
|
|
end |
|
|
|
|
if status == dlstatus.STATUS_ENDDOWNLOADDATA then |
|
|
|
|
local f = io.open(fpath, "r") |
|
|
|
|
if f then |
|
|
|
|
local text = f:read("*a") |
|
|
|
|
if text ~= nil then |
|
|
|
|
sampShowDialog(222, "Ñïèñîê îáíîâëåíèé TruckHUD", "{FFFFFF}Ðàñøèôðîâêà âåðñèè: ÃîäÌåñÿöÄåíüÍîìåð\n/truck download [ver] - Çàãðóçèòü íóæíóþ âåðñèþ\n \n" ..text, "Çàêðûòü", "", 2) |
|
|
|
|
end |
|
|
|
|
io.close(f) |
|
|
|
|
os.remove(fpath) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
) |
|
|
|
|
end |
|
|
|
|
) |
|
|
|
|
return false |
|
|
|
|
end |
|
|
|
|
if params:lower() == " download" then |
|
|
|
|
check_version(true) |
|
|
|
|
return false |
|
|
|
|
end |
|
|
|
|
if params:lower():find(" download (%d+)") then |
|
|
|
|
check_version(true, params:lower():match(" download (%d+)")) |
|
|
|
|
return false |
|
|
|
|
end |
|
|
|
|
if params:lower() == " menu" then |
|
|
|
|
ShowDialog1(1) |
|
|
|
|
return false |
|
|
|
@ -2987,94 +2936,6 @@ function isTruckCar() |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
function check_version(update, downgrade_ver) |
|
|
|
|
local fpath = os.getenv("TEMP") .. "\\truck-version.txt" |
|
|
|
|
downloadUrlToFile( |
|
|
|
|
"http://thprivate.deadpoo.net/download/version", |
|
|
|
|
fpath, |
|
|
|
|
function(id, status, p1, p2) |
|
|
|
|
if status == dlstatus.STATUS_ENDDOWNLOADDATA then |
|
|
|
|
local f = io.open(fpath, "r") |
|
|
|
|
if f then |
|
|
|
|
local data = decodeJson(f:read("*a")) |
|
|
|
|
if data ~= nil then |
|
|
|
|
if data.latest ~= tostring(thisScript().version) or downgrade_ver ~= nil then |
|
|
|
|
if not update then |
|
|
|
|
sampAddChatMessage( ">> Âûøëî îáíîâëåíèå äëÿ TruckHUD, âåðñèÿ " .. data.latest .. ". Òåêóùàÿ âåðñèÿ " .. thisScript().version, 0xFF2f72f7) |
|
|
|
|
sampAddChatMessage( ">> Ïîñìîòðåòü ñïèñîê èçìåíåíèé: /truck version. Âêëþ÷èòü/Âûêëþ÷èòü óâåäîìëåíèÿ: /truck ad", 0xFF2f72f7) |
|
|
|
|
sampAddChatMessage( ">> Ñêà÷àòü íà îôèöèàëüíàîé ñòðàíèöå Truck HUD: https://vk.com/rubin.mods", 0xFF2f72f7) |
|
|
|
|
sampAddChatMessage( ">> ", 0xFF2f72f7) |
|
|
|
|
sampAddChatMessage( ">> Ëèáî îáíîâèòü îíëàéí êîìàíäîé: /truck download", 0xFF2f72f7) |
|
|
|
|
sampAddChatMessage( ">> Íå çàáûâàéòå çàëåòàòü êî ìíå â ãðóïïó =)", 0xFF2f72f7) |
|
|
|
|
else |
|
|
|
|
if downgrade_ver == nil then |
|
|
|
|
sampAddChatMessage( ">> Âûøëî îáíîâëåíèå äëÿ TruckHUD, âåðñèÿ " .. data.latest .. ". Òåêóùàÿ âåðñèÿ " .. thisScript().version, 0xFF2f72f7) |
|
|
|
|
sampAddChatMessage( ">> Ïûòàþñü îáíîâèòüñÿ!", 0xFF2f72f7) |
|
|
|
|
lua_thread.create(function(data) |
|
|
|
|
wait(1000) |
|
|
|
|
downloadUrlToFile(data.updateurl, thisScript().path, |
|
|
|
|
function(id3, status1, p13, p23) |
|
|
|
|
if status1 == dlstatus.STATUS_DOWNLOADINGDATA then |
|
|
|
|
sampAddChatMessage(string.format('Çàãðóæåíî %d èç %d.', p13, p23), 0xFF2f72f7) |
|
|
|
|
elseif status1 == dlstatus.STATUS_ENDDOWNLOADDATA then |
|
|
|
|
goupdatestatus = true |
|
|
|
|
sampAddChatMessage('Çàãðóçêà îáíîâëåíèÿ çàâåðøåíà.', 0xFF2f72f7) |
|
|
|
|
lua_thread.create(function() wait(500) thisScript():reload() end) |
|
|
|
|
end |
|
|
|
|
if status1 == dlstatus.STATUSEX_ENDDOWNLOAD then |
|
|
|
|
if goupdatestatus == nil then |
|
|
|
|
sampAddChatMessage('Îáíîâëåíèå ïðîøëî íåóäà÷íî. Çàïóñêàþ óñòàðåâøóþ âåðñèþ.', 0xFF2f72f7) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
) |
|
|
|
|
end, data) |
|
|
|
|
else |
|
|
|
|
sampAddChatMessage( ">> Âûïîëíÿþ ïîèñê âåðñèè " .. downgrade_ver .. ". Òåêóùàÿ âåðñèÿ " .. thisScript().version, 0xFF2f72f7) |
|
|
|
|
lua_thread.create(function(data) |
|
|
|
|
wait(1000) |
|
|
|
|
fpath = os.getenv("TEMP").."\\truck-update.txt" |
|
|
|
|
downloadUrlToFile("http://thprivate.deadpoo.net/download/"..downgrade_ver, fpath, |
|
|
|
|
function(id3, status1, p13, p23) |
|
|
|
|
if status1 == dlstatus.STATUS_ENDDOWNLOADDATA then |
|
|
|
|
local f = io.open(fpath, "r") |
|
|
|
|
if f then |
|
|
|
|
local data = f:read("*a") |
|
|
|
|
if data == "TRUCKHUD" then |
|
|
|
|
sampAddChatMessage('Òàêîé âåðñèè íåò â áàçå.', 0xFF2f72f7) |
|
|
|
|
else |
|
|
|
|
sampAddChatMessage('Çàãðóçêà çàâåðøåíà!', 0xFF2f72f7) |
|
|
|
|
local file, error = io.open(thisScript().path, "w") |
|
|
|
|
if file ~= nil then |
|
|
|
|
file:write(data) |
|
|
|
|
file:flush() |
|
|
|
|
io.close(file) |
|
|
|
|
lua_thread.create(function() wait(500) thisScript():reload() end) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
io.close(f) |
|
|
|
|
end |
|
|
|
|
os.remove(fpath) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
) |
|
|
|
|
end, data) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
else |
|
|
|
|
if update then |
|
|
|
|
sampAddChatMessage( ">> Ó Âàñ ïîñëåäíÿÿ âåðñèÿ TruckHUD!", 0xFF2f72f7) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
io.close(f) |
|
|
|
|
os.remove(fpath) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
function GetGruz() |
|
|
|
|
local gruz = 0 |
|
|
|
|
if isCharInModel(PLAYER_PED, 514) then |
|
|
|
@ -3769,7 +3630,7 @@ function get_time() |
|
|
|
|
msk_timestamp = msk_timestamp + (os.time() - _time) |
|
|
|
|
_time = os.time() |
|
|
|
|
if inifiles.Settings.AutoClear then |
|
|
|
|
collectgarbage() |
|
|
|
|
--collectgarbage() |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
@ -4429,4 +4290,168 @@ function samp_create_sync_data(sync_type, copy_from_player) |
|
|
|
|
end |
|
|
|
|
} |
|
|
|
|
return setmetatable({send = func_send}, mt) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
-->> UPDATE MODULE |
|
|
|
|
|
|
|
|
|
function openURL(url, fpath) |
|
|
|
|
local result = false |
|
|
|
|
local file_download = false |
|
|
|
|
local download_final = false |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if doesFileExist(fpath) then |
|
|
|
|
say("remove") |
|
|
|
|
os.remove(fpath) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
downloadUrlToFile(url, fpath, function(id, status, p1, p2) |
|
|
|
|
if status == dlstatus.STATUS_ENDDOWNLOADDATA then |
|
|
|
|
file_download = true |
|
|
|
|
end |
|
|
|
|
if status == dlstatus.STATUSEX_ENDDOWNLOAD then |
|
|
|
|
download_final = true |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
repeat |
|
|
|
|
wait(1000) |
|
|
|
|
until download_final or file_download |
|
|
|
|
|
|
|
|
|
if file_download then |
|
|
|
|
local text = "" |
|
|
|
|
local f = io.open(fpath, "r") |
|
|
|
|
if f then |
|
|
|
|
text = f:read("*a") |
|
|
|
|
io.close(f) |
|
|
|
|
end |
|
|
|
|
os.remove(fpath) |
|
|
|
|
else |
|
|
|
|
addChatMessage("Íå óäàëîñü ñêà÷àòü îáíîâëåíèå ïî ññûëêå:") |
|
|
|
|
addChatMessage(url) |
|
|
|
|
end |
|
|
|
|
return result, text |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function addChatMessage(text) |
|
|
|
|
local tag = string.format("{667dff}[%s]{FFFFFF} ", thisScript().name) |
|
|
|
|
sampAddChatMessage(tag..text, 0xFFFFFFFF) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
script_update = { |
|
|
|
|
check_update = false, |
|
|
|
|
check_update_url = "http://gith.deadpoo.net/rubin/TruckHUD/raw/branch/master/version", |
|
|
|
|
auto_update = false, |
|
|
|
|
auto_update_url = "http://gith.deadpoo.net/rubin/TruckHUD/raw/branch/master/TruckHUD.lua", |
|
|
|
|
address_ini = "rubin-mods-updates.ini", |
|
|
|
|
main = function() |
|
|
|
|
local name = thisScript().name |
|
|
|
|
local ini = inicfg.load({ |
|
|
|
|
[name] = { |
|
|
|
|
check_update = true, |
|
|
|
|
auto_update = true |
|
|
|
|
} |
|
|
|
|
}, script_update.address_ini) |
|
|
|
|
script_update.check_update = ini[name].check_update |
|
|
|
|
script_update.auto_update = ini[name].auto_update |
|
|
|
|
inicfg.save(ini, script_update.address_ini) |
|
|
|
|
if script_update.check_update or script_update.auto_update then |
|
|
|
|
local fpath = os.tmpname() |
|
|
|
|
local result, text = openURL(script_update.check_update_url, fpath) |
|
|
|
|
if result then |
|
|
|
|
if text ~= "" and not string.find(text, thisScript().version) then |
|
|
|
|
addChatMessage( string.format("Âûøëà íîâàÿ âåðñèÿ '%s'. Òåêóùàÿ: '%s'", text, thisScript().version) ) |
|
|
|
|
if script_update.auto_update then |
|
|
|
|
addChatMessage( string.format("Àâòî-Îáíîâëåíèå ñêðèïòà âêëþ÷åíî. Ïðîöåññ çàïóùåí!") ) |
|
|
|
|
script_update.command() |
|
|
|
|
else |
|
|
|
|
local command = thisScript().name:gsub(" ", "").."_update" |
|
|
|
|
sampRegisterChatCommand(command, script_update.command) |
|
|
|
|
addChatMessage( string.format("Àâòî-Îáíîâëåíèå ñêðèïòà âûêëþ÷åíî. Îáíîâèòü ñàìîìó: %s", command) ) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
script_update.menu.init() |
|
|
|
|
end, |
|
|
|
|
command = function() |
|
|
|
|
lua_thread.create(function() |
|
|
|
|
local fpath = os.tmpname() |
|
|
|
|
local result, text = openURL(script_update.auto_update_url, fpath) |
|
|
|
|
if result and text ~= "" and text:find(thisScript().name:gsub("%-", "%%-")) then |
|
|
|
|
local file, error = io.open(thisScript().path, "w") |
|
|
|
|
if file ~= nil then |
|
|
|
|
file:write(text) |
|
|
|
|
file:flush() |
|
|
|
|
io.close(file) |
|
|
|
|
addChatMessage("Îáíîâëåíèå çàâåðøåíî, ñêðèïò ïåðåçàãðóæåí!") |
|
|
|
|
wait(500) |
|
|
|
|
thisScript():reload() |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end) |
|
|
|
|
end, |
|
|
|
|
menu = { |
|
|
|
|
text = {}, |
|
|
|
|
dialog = {}, |
|
|
|
|
init = function() |
|
|
|
|
if not sampIsChatCommandDefined("rubin-mods") then |
|
|
|
|
sampRegisterChatCommand("rubin-mods",script_update.menu.show) |
|
|
|
|
while true do |
|
|
|
|
wait(0) |
|
|
|
|
local result, button, list, input = sampHasDialogRespond(2160) |
|
|
|
|
if result and button == 1 then |
|
|
|
|
if script_update.menu.text[list+1] ~= nil and script_update.menu.dialog[list+1] ~= nil then |
|
|
|
|
script_update.menu.dialog[list+1]() |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
else |
|
|
|
|
say("Êîìàíäà çàðåãàíà") |
|
|
|
|
end |
|
|
|
|
end, |
|
|
|
|
show = function() |
|
|
|
|
script_update.menu.text = {} |
|
|
|
|
script_update.menu.dialog = {} |
|
|
|
|
local ini = inicfg.load({}, script_update.address_ini) |
|
|
|
|
for k,v in pairs(ini) do |
|
|
|
|
script_update.menu.text[#script_update.menu.text+1] = string.format(" ") |
|
|
|
|
script_update.menu.dialog[#script_update.menu.dialog+1] = function() |
|
|
|
|
script_update.menu.show() |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
script_update.menu.text[#script_update.menu.text+1] = string.format("> %s", k) |
|
|
|
|
script_update.menu.dialog[#script_update.menu.dialog+1] = function() |
|
|
|
|
script_update.menu.show() |
|
|
|
|
end |
|
|
|
|
script_update.menu.text[#script_update.menu.text+1] = string.format("\tauto update %s", (ini[k].auto_update and "{59fc30}ON" or "{ff0000}OFF")) |
|
|
|
|
script_update.menu.dialog[#script_update.menu.dialog+1] = function() |
|
|
|
|
ini[k].auto_update = not ini[k].auto_update |
|
|
|
|
inicfg.save(ini, script_update.address_ini) |
|
|
|
|
script_update.menu.show() |
|
|
|
|
end |
|
|
|
|
if not ini[k].auto_update then |
|
|
|
|
script_update.menu.text[#script_update.menu.text+1] = string.format("\tcheck update %s", (ini[k].check_update and "{59fc30}ON" or "{ff0000}OFF")) |
|
|
|
|
script_update.menu.dialog[#script_update.menu.dialog+1] = function() |
|
|
|
|
ini[k].check_update = not ini[k].check_update |
|
|
|
|
inicfg.save(ini, script_update.address_ini) |
|
|
|
|
script_update.menu.show() |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
script_update.menu.text[#script_update.menu.text+1] = string.format("\tdelete update settings") |
|
|
|
|
script_update.menu.dialog[#script_update.menu.dialog+1] = function() |
|
|
|
|
ini[k] = nil |
|
|
|
|
inicfg.save(ini, script_update.address_ini) |
|
|
|
|
script_update.menu.show() |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
local text = "" |
|
|
|
|
for i = 1, #script_update.menu.text do |
|
|
|
|
text = text..script_update.menu.text[i].."\n" |
|
|
|
|
end |
|
|
|
|
sampShowDialog(2160,"rubin-mods update settings",text,"Enter","Exit",2) |
|
|
|
|
end |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|