You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
202 lines
8.3 KiB
202 lines
8.3 KiB
script_name("easy-cruise")
|
|
script_author("rubin")
|
|
script_version("22.10.26.1")
|
|
|
|
inicfg = require "inicfg"
|
|
dlstatus = require("moonloader").download_status
|
|
vkeys = require "vkeys"
|
|
encoding = require "encoding"
|
|
encoding.default = "CP1251"
|
|
u8 = encoding.UTF8
|
|
|
|
main_key_start = { "VK_LSHIFT" }
|
|
additional_key_start = { "VK_W", "VK_S", "VK_SPACE" }
|
|
cruise = false
|
|
|
|
function main()
|
|
repeat wait(0) until isSampAvailable()
|
|
lua_thread.create(script_update.main) -->> Удалить чтобы скрипт не проверял обновления
|
|
while true do
|
|
wait(0)
|
|
doCruise()
|
|
end
|
|
end
|
|
|
|
function doCruise()
|
|
local car = storeCarCharIsInNoSave(playerPed)
|
|
if not isCharInAnyCar(playerPed) or not isCarEngineOn(car) then
|
|
if cruise then
|
|
cruise = false
|
|
printStringNow('~R~cruise control - OFF', 1500)
|
|
end
|
|
return
|
|
end
|
|
if not sampIsChatInputActive() and not sampIsDialogActive() and not sampIsCursorActive() then
|
|
if not cruise and select(1, check_press_key(additional_key_start)) and select(1, check_press_key(main_key_start)) then
|
|
repeat
|
|
wait(100)
|
|
local result, text = check_press_key(additional_key_start)
|
|
printStringNow("~G~don't press "..text, 100)
|
|
until not result
|
|
cruise = true
|
|
printStringNow('~G~cruise control - ON', 1500)
|
|
elseif cruise and not isKeyDown(vkeys["VK_LSHIFT"]) and select(1, check_press_key(additional_key_start)) then
|
|
cruise = false
|
|
printStringNow('~R~cruise control - OFF', 1500)
|
|
end
|
|
end
|
|
if cruise then
|
|
setGameKeyState(16, 255)
|
|
end
|
|
end
|
|
|
|
function check_press_key(table)
|
|
local result = false
|
|
local result_key_text = ""
|
|
for i = 1, #table do
|
|
if isKeyDown(vkeys[table[i]]) then
|
|
result = true
|
|
result_key_text = table[i]:gsub("VK_", "")
|
|
break
|
|
end
|
|
end
|
|
return result, result_key_text
|
|
end
|
|
|
|
script_update = {
|
|
check_update = false,
|
|
check_update_url = "https://git.deadpoo.net/rubin/easy-cruise/raw/branch/master/version",
|
|
auto_update = false,
|
|
auto_update_url = "https://git.deadpoo.net/rubin/easy-cruise/raw/branch/master/easy-cruise.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 text = openURL(script_update.check_update_url, fpath)
|
|
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
|
|
script_update.menu.init()
|
|
end,
|
|
command = function()
|
|
lua_thread.create(function()
|
|
local fpath = os.tmpname()
|
|
local text = openURL(script_update.auto_update_url, fpath)
|
|
if 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("Обновление завершено, скрипт перезагружен!")
|
|
lua_thread.create(function() wait(500) thisScript():reload() end)
|
|
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
|
|
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..u8:decode(script_update.menu.text[i]).."\n"
|
|
end
|
|
sampShowDialog(2160,"rubin-mods update settings",text,"Enter","Exit",2)
|
|
end
|
|
}
|
|
}
|
|
|
|
function openURL(url, fpath)
|
|
local final_download = false
|
|
downloadUrlToFile(url, fpath, function(id, status, p1, p2)
|
|
if status == dlstatus.STATUS_ENDDOWNLOADDATA then
|
|
final_download = true
|
|
end
|
|
end)
|
|
|
|
repeat
|
|
wait(1000)
|
|
until final_download
|
|
|
|
local text = ""
|
|
local f = io.open(fpath, "r")
|
|
if f then
|
|
text = f:read("*a")
|
|
io.close(f)
|
|
end
|
|
os.remove(fpath)
|
|
return text
|
|
end
|
|
|
|
function addChatMessage(text)
|
|
local tag = string.format("{667dff}[%s]{FFFFFF} ", thisScript().name)
|
|
sampAddChatMessage(tag..u8:decode(text), 0xFFFFFFFF)
|
|
end |