|
|
|
@ -1,8 +1,9 @@ |
|
|
|
|
script_name('cornHUD') |
|
|
|
|
script_name('corn-hud') |
|
|
|
|
script_author("Serhiy_Rubin") |
|
|
|
|
script_version("22/09/2019") |
|
|
|
|
script_version("23.01.2023") |
|
|
|
|
require 'lib.sampfuncs' |
|
|
|
|
require 'lib.moonloader' |
|
|
|
|
local dlstatus = require("moonloader").download_status |
|
|
|
|
local vkeys = require "lib.vkeys" |
|
|
|
|
local sampev, inicfg = require 'lib.samp.events', require 'inicfg' |
|
|
|
|
local render, antiflood = false, 0 |
|
|
|
@ -21,6 +22,7 @@ local coord = { |
|
|
|
|
function main() |
|
|
|
|
if not isSampLoaded() or not isSampfuncsLoaded() then return end |
|
|
|
|
while not isSampAvailable() do wait(0) end |
|
|
|
|
lua_thread.create(script_update.main) |
|
|
|
|
repeat wait(0) until sampGetCurrentServerName() ~= "SA-MP" |
|
|
|
|
repeat wait(0) until sampGetCurrentServerName():find("Samp%-Rp.Ru") or sampGetCurrentServerName():find("SRP") |
|
|
|
|
server = sampGetCurrentServerName():gsub("|", "") |
|
|
|
@ -293,7 +295,6 @@ function drawClickableText(text, posX, posY, Color1, Color2) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-->> MENU |
|
|
|
|
menu = {} |
|
|
|
|
|
|
|
|
@ -431,4 +432,220 @@ function start_dialog(menu) -- module by trefa |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
return _dialog(menu, 1337, outs) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
-->> UPDATE MODULE |
|
|
|
|
function openURL(url, fpath) |
|
|
|
|
local text = "" |
|
|
|
|
local file_download = false |
|
|
|
|
local download_final = false |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if doesFileExist(fpath) then |
|
|
|
|
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 f = io.open(fpath, "r") |
|
|
|
|
if f then |
|
|
|
|
text = f:read("*a") |
|
|
|
|
io.close(f) |
|
|
|
|
end |
|
|
|
|
os.remove(fpath) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
if (text:find("Not found") and not text:find('"Not found"')) or text == "" then |
|
|
|
|
text = "" |
|
|
|
|
addChatMessage("Íå óäàëîñü ñêà÷àòü îáíîâëåíèå ïî ññûëêå:") |
|
|
|
|
addChatMessage(url) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
return text |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
function addChatMessage(text) |
|
|
|
|
local tag = string.format("{667dff}[%s]{FFFFFF} ", thisScript().name) |
|
|
|
|
sampAddChatMessage(tag..text, 0xFFFFFFFF) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
script_update = { |
|
|
|
|
version_url = "http://git.deadpoo.net/rubin/corn-hud/raw/branch/master/version", |
|
|
|
|
script_url = "http://git.deadpoo.net/rubin/corn-hud/raw/branch/master/corn-hud.lua", |
|
|
|
|
changelog_url = "http://git.deadpoo.net/rubin/corn-hud/raw/branch/master/changelog", |
|
|
|
|
address_ini = "rubin-mods-updates.ini", |
|
|
|
|
main = function() |
|
|
|
|
local name = thisScript().name |
|
|
|
|
local ini = inicfg.load({ |
|
|
|
|
[name] = { |
|
|
|
|
check_update = true, |
|
|
|
|
auto_update = true, |
|
|
|
|
server_version = "" |
|
|
|
|
} |
|
|
|
|
}, script_update.address_ini) |
|
|
|
|
ini[name].version_url = script_update.version_url |
|
|
|
|
ini[name].script_url = script_update.script_url |
|
|
|
|
ini[name].changelog_url = script_update.changelog_url |
|
|
|
|
ini[name].version = thisScript().version |
|
|
|
|
ini[name].script_name = thisScript().name |
|
|
|
|
local command = (thisScript().name:gsub(" ", "").."-update"):lower() |
|
|
|
|
sampRegisterChatCommand(command, script_update.command) |
|
|
|
|
if ini[name].check_update or ini[name].auto_update then |
|
|
|
|
local fpath = os.tmpname() |
|
|
|
|
local result, text = pcall(openURL, script_update.version_url, fpath) |
|
|
|
|
if result then |
|
|
|
|
ini[name].server_version = text |
|
|
|
|
if text ~= "" and not string.find(text, thisScript().version) then |
|
|
|
|
addChatMessage( string.format("Âûøëà íîâàÿ âåðñèÿ '%s'. Òåêóùàÿ: '%s'", text, thisScript().version) ) |
|
|
|
|
if ini[name].auto_update then |
|
|
|
|
addChatMessage( string.format("Àâòîîáíîâëåíèå ñêðèïòà âêëþ÷åíî. Ïðîöåññ çàïóùåí!") ) |
|
|
|
|
script_update.command() |
|
|
|
|
else |
|
|
|
|
addChatMessage( string.format("Àâòîîáíîâëåíèå ñêðèïòà âûêëþ÷åíî. Îáíîâèòü ñàìîìó: /%s", command) ) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
inicfg.save(ini, script_update.address_ini) |
|
|
|
|
script_update.menu.init() |
|
|
|
|
end, |
|
|
|
|
command = function() |
|
|
|
|
lua_thread.create(function() |
|
|
|
|
local fpath = os.tmpname() |
|
|
|
|
local result, text = pcall(openURL, script_update.version_url, fpath) |
|
|
|
|
if result then |
|
|
|
|
if text ~= "" and not string.find(text, thisScript().version) then |
|
|
|
|
addChatMessage( string.format("Âûøëà íîâàÿ âåðñèÿ '%s'. Òåêóùàÿ: '%s'", text, thisScript().version) ) |
|
|
|
|
local fpath = os.tmpname() |
|
|
|
|
local result, text = pcall(openURL, script_update.script_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 |
|
|
|
|
else |
|
|
|
|
addChatMessage("Ó Âàñ óñòàíîâëåíà ïîñëåäíÿÿ âåðñèÿ!") |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end) |
|
|
|
|
end, |
|
|
|
|
menu = { |
|
|
|
|
text = {}, |
|
|
|
|
dialog = {}, |
|
|
|
|
init = function() |
|
|
|
|
if not sampIsChatCommandDefined("rubin-mods") then |
|
|
|
|
sampAddChatMessage("{667dff}[RUBIN MODS]{FFFFFF} Óïðàâëåíèå îáíîâëåíèÿìè ñêðèïòîâ: /rubin-mods", 0xFFFFFFFF) |
|
|
|
|
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](script_update.menu.ini[list+1]) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
local result, button, list, input = sampHasDialogRespond(2162) |
|
|
|
|
if result then |
|
|
|
|
if button == 1 then |
|
|
|
|
if script_update.menu2.text[list+1] ~= nil and script_update.menu2.dialog[list+1] ~= nil then |
|
|
|
|
script_update.menu2.dialog[list+1]() |
|
|
|
|
end |
|
|
|
|
else |
|
|
|
|
script_update.menu.show() |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
local result, button, list, input = sampHasDialogRespond(2161) |
|
|
|
|
if result then |
|
|
|
|
script_update.menu2.show(script_update.menu2.data) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end, |
|
|
|
|
show = function() |
|
|
|
|
script_update.menu.text = {} |
|
|
|
|
script_update.menu.dialog = {} |
|
|
|
|
script_update.menu.ini = {} |
|
|
|
|
local ini = inicfg.load({}, script_update.address_ini) |
|
|
|
|
for k,v in pairs(ini) do |
|
|
|
|
script_update.menu.ini[#script_update.menu.ini+1] = v |
|
|
|
|
script_update.menu.text[#script_update.menu.text+1] = string.format("%s\t%s%s", k, (v.version == v.server_version and "{59fc30}" or "{ff0000}"),v.version) |
|
|
|
|
script_update.menu.dialog[#script_update.menu.dialog+1] = function(data) |
|
|
|
|
script_update.menu2.show(data) |
|
|
|
|
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","Ñêðèïò\tÂåðñèÿ\n"..text,"Âûáðàòü","Çàêðûòü",5) |
|
|
|
|
end |
|
|
|
|
}, |
|
|
|
|
menu2 = { |
|
|
|
|
data = {}, |
|
|
|
|
text = {}, |
|
|
|
|
dialog = {}, |
|
|
|
|
show = function(data) |
|
|
|
|
script_update.menu2.data = data |
|
|
|
|
script_update.menu2.text = {} |
|
|
|
|
script_update.menu2.dialog = {} |
|
|
|
|
local ini = inicfg.load({}, script_update.address_ini) |
|
|
|
|
local k = data.script_name |
|
|
|
|
script_update.menu2.text[#script_update.menu2.text+1] = string.format("Àâòîîáíîâëåíèå %s", (ini[k].auto_update and "{59fc30}ON" or "{ff0000}OFF")) |
|
|
|
|
script_update.menu2.dialog[#script_update.menu2.dialog+1] = function() |
|
|
|
|
ini[k].auto_update = not ini[k].auto_update |
|
|
|
|
inicfg.save(ini, script_update.address_ini) |
|
|
|
|
script_update.menu2.show(data) |
|
|
|
|
end |
|
|
|
|
if not ini[k].auto_update then |
|
|
|
|
script_update.menu2.text[#script_update.menu2.text+1] = string.format("Ïðîâåðÿòü îáíîâëåíèÿ %s", (ini[k].check_update and "{59fc30}ON" or "{ff0000}OFF")) |
|
|
|
|
script_update.menu2.dialog[#script_update.menu2.dialog+1] = function() |
|
|
|
|
ini[k].check_update = not ini[k].check_update |
|
|
|
|
inicfg.save(ini, script_update.address_ini) |
|
|
|
|
script_update.menu2.show(data) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
script_update.menu2.text[#script_update.menu2.text+1] = string.format("Ïîñëåäíèå èçìåíåíèÿ") |
|
|
|
|
script_update.menu2.dialog[#script_update.menu2.dialog+1] = function() |
|
|
|
|
script_update.changelog(ini[k].changelog_url) |
|
|
|
|
end |
|
|
|
|
script_update.menu2.text[#script_update.menu2.text+1] = string.format("Óäàëèòü èç ñïèñêà") |
|
|
|
|
script_update.menu2.dialog[#script_update.menu2.dialog+1] = function() |
|
|
|
|
ini[k] = nil |
|
|
|
|
inicfg.save(ini, script_update.address_ini) |
|
|
|
|
script_update.menu.show() |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
local text = "" |
|
|
|
|
for i = 1, #script_update.menu2.text do |
|
|
|
|
text = text..script_update.menu2.text[i].."\n" |
|
|
|
|
end |
|
|
|
|
sampShowDialog(2162,"Íàñòðîéêè îáíîâëåíèÿ äëÿ "..data.script_name,text,"Âûáðàòü","Íàçàä",2) |
|
|
|
|
end |
|
|
|
|
}, |
|
|
|
|
changelog = function(url, data) |
|
|
|
|
local fpath = os.tmpname() |
|
|
|
|
local result, text = pcall(openURL, url, fpath) |
|
|
|
|
if result then |
|
|
|
|
sampShowDialog(2161,"Changelog - "..thisScript().name,text,"Âûáðàòü","Íàçàä",4) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
} |