added module dialog

master
rubin 2 years ago
parent 86530c8acd
commit 7f3108d22b
  1. 124
      easy-cruise.lua

@ -15,8 +15,9 @@ cruise = false
function main()
repeat wait(0) until isSampAvailable()
lua_thread.create(script_update.main)
config.init()
lua_thread.create(script_update.main)
lua_thread.create(menu.loop)
while true do
wait(0)
local car = storeCarCharIsInNoSave(playerPed)
@ -58,6 +59,69 @@ function check_press_key(table)
return result, result_key_text
end
-->> MENU DIALOG
menu = {}
menu.dialog = {}
menu.data = {}
menu.ffixcar_log = {}
menu.update = function()
menu.dialog = {
["main"] = {
settings = {title = "mafia-tools" ,style = 4 ,btn1 = "Выбрать" ,btn2 = "Закрыть" ,forward = "{ffffff}" ,backwards = "\n" ,score = false},
{
{
title = "Cruise\t"..(config.data.status and "вкл" or "выкл"),
click = function(button, list, input , outs)
if button ~= 1 then return end
config.data.status = not config.data.status
config.save(config.data)
menu.show = { true, "main" }
end
},
{
title = "Key\t"..config.data.key:gsub("VK_", ""),
click = function(button, list, input , outs)
if button ~= 1 then return end
wait(100)
local key = ""
repeat
wait(0)
if not sampIsDialogActive() then
sampShowDialog(222,"LUA Truck-HUD: Смена активации","Нажмите на любую клавишу","Выбрать","Закрыть",0)
end
for k, v in pairs(vkeys) do
if wasKeyPressed(v) and k ~= "VK_ESCAPE" and k ~= "VK_RETURN" then
key = k
end
end
until key ~= ""
config.data.key = key
config.save(config.data)
menu.show = { true, "main" }
end
},
}
}
}
end
menu.show = { false, "main" }
menu.loop = function()
sampRegisterChatCommand('cruise', function(param)
menu.show = { true, "main" }
end)
while true do
wait(0)
if menu.show[1] then
menu.show[1] = false
menu.update()
if menu.dialog[menu.show[2]] ~= nil then
wait(100)
start_dialog(menu.dialog[menu.show[2]], menu.show[4])
end
end
end
end
-->> CONFIG
config = {}
config.data = {}
@ -133,6 +197,49 @@ config.read = function()
end
end
function start_dialog(_menu, put) -- module by trefa & modify (put & list in [])
function _dialog(_menu, id, outs, put)
sampShowDialog(id, _menu.settings.title, tbl_split(_menu.settings.style, _menu, _menu.settings.forward ,_menu.settings.backwards ,_menu.settings.score), _menu.settings.btn1, (_menu.settings.btn2 ~= nil and _menu.settings.btn2 or _), _menu.settings.style)
repeat
wait(0)
if put ~= nil and sampIsDialogActive() then
sampSetCurrentDialogEditboxText(put)
put = nil
end
local result, button, list, input = sampHasDialogRespond(id)
if result then
local out, outs = _menu[((_menu.settings.style == 0 or _menu.settings.style == 1 or _menu.settings.style == 3) and 1 or ((list + 1) > #_menu[1] and 2 or 1))][((_menu.settings.style == 0 or _menu.settings.style == 1 or _menu.settings.style == 3) and 1 or ((list + 1) > #_menu[1] and (list - #_menu[1]) + 1 or list + 1))].click(button, list, input, outs)
if type(out) == "table" then
return _dialog(out, id - 1, outs, put)
elseif type(out) == "boolean" then
if not out then
return out
end
return _dialog(_menu, id, outs, put)
end
end
until result or menu.show[1]
end
function tbl_split(style, tbl, forward ,backwards ,score)
if style == 2 or style == 4 or style == 5 then
text = (style == 5 and tbl[1].text.."\n" or "")
for i, val in ipairs(tbl[1]) do
text = text..""..forward..""..(score and "["..(i-1).."] " or "")..""..val.title..""..backwards
end
if tbl[2] ~= nil then
for _, val in ipairs(tbl[2]) do
text = text..""..forward..""..val.title..""..backwards
end
end
return text
end
return tbl[1].text
end
return _dialog(_menu, 1337, outs, put)
end
-->> UPDATE MODULE
function openURL(url, fpath)
local text = ""
@ -357,3 +464,18 @@ script_update = {
end
end
}
-->> SCRIPT UTF-8
-->> utf8(table path, incoming variables encoding, outcoming variables encoding)
-->> table path example { "sampev", "onShowDialog" }
-->> encoding options nil | AnsiToUtf8 | Utf8ToAnsi
_utf8 = load([=[return function(utf8_func, in_encoding, out_encoding); if encoding == nil then; encoding = require("encoding"); encoding.default = "CP1251"; u8 = encoding.UTF8; end; if type(utf8_func) ~= "table" then; return false; end; if AnsiToUtf8 == nil or Utf8ToAnsi == nil then; AnsiToUtf8 = function(text); return u8(text); end; Utf8ToAnsi = function(text); return u8:decode(text); end; end; if _UTF8_FUNCTION_SAVE == nil then; _UTF8_FUNCTION_SAVE = {}; end; local change_var = "_G"; for s = 1, #utf8_func do; change_var = string.format('%s["%s"]', change_var, utf8_func[s]); end; if _UTF8_FUNCTION_SAVE[change_var] == nil then; _UTF8_FUNCTION = function(...); local pack = table.pack(...); readTable = function(t, enc); for k, v in next, t do; if type(v) == 'table' then; readTable(v, enc); else; if enc ~= nil and (enc == "AnsiToUtf8" or enc == "Utf8ToAnsi") then; if type(k) == "string" then; k = _G[enc](k); end; if type(v) == "string" then; t[k] = _G[enc](v); end; end; end; end; return t; end; return table.unpack(readTable({_UTF8_FUNCTION_SAVE[change_var](table.unpack(readTable(pack, in_encoding)))}, out_encoding)); end; local text = string.format("_UTF8_FUNCTION_SAVE['%s'] = %s; %s = _UTF8_FUNCTION;", change_var, change_var, change_var); load(text)(); _UTF8_FUNCTION = nil; end; return true; end]=])
function utf8(...)
pcall(_utf8(), ...)
end
utf8({ "sampShowDialog" }, "Utf8ToAnsi")
utf8({ "sampSendChat" }, "Utf8ToAnsi")
utf8({ "sampAddChatMessage" }, "Utf8ToAnsi")
utf8({ "print" }, "Utf8ToAnsi")
utf8({ "sampHasDialogRespond" }, nil, "AnsiToUtf8")
Loading…
Cancel
Save