- 63
- 1
- Версия SA-MP
-
- Любая
- Другая
Написал небольшой скрипт (просто некоторые разные вещи нужны). После добавления inicfg и добавления сохранения настроек не запускается самп. Когда я вручную создал файл NotHelper.ini самп загрузился. Когда скрипт попытался сохранить некоторое значение в файл, самп вылетел.
Ошибка вылета: Нарушение прав доступа
Ошибка вылета: Нарушение прав доступа
Сам код:
script_name("{fbff00}NotHelper")
script_author("{fbff00}NotBartu")
-- Либы
local RakLua = require 'lib.RakLua'
local sampev = require 'lib.samp.events'
local vkeys = require 'vkeys'
local imgui = require 'mimgui'
local wm = require 'windows.message'
local inicfg = require 'inicfg'
-- Константы
interiorId = getActiveInterior()
isSbivActive = true
isFarmActive = false
-- Помощь к Imgui
local imNew = imgui.new
local mainWindow = imNew.bool()
local infoWindow = imNew.bool()
local sizeX, sizeY = getScreenResolution()
-- Inicfg
local iniSettings = inicfg.load({
sbiv = {
isActive = nil
}
}, "NotHelper.ini")
local status = inicfg.load(settings, 'NotHelper.ini')
if not doesFileExist('moonloader/config/NotHelper.ini') then inicfg.save(settings, 'NotHelper.ini') end
-- При начале
imgui.OnInitialize(function()
imgui.DarkTheme()
end)
-- Основное меню
local mainFrame = imgui.OnFrame(
function() return mainWindow[0] and not isPauseMenuActive() and not sampIsScoreboardOpen() end,
function()
imgui.SetNextWindowPos(imgui.ImVec2(sizeX / 2, sizeY / 2), imgui.Cond.Once, imgui.ImVec2(0.5, 0.5))
imgui.SetNextWindowSize(imgui.ImVec2(250, 350), imgui.Cond.Always)
imgui.Begin("Main Window", mainWindow, imgui.WindowFlags.NoResize)
imgui.Text("Hello")
if imgui.Button("Info") then
mainWindow[0] = false
infoWindow[0] = true
end
imgui.End()
end
)
-- Окно с инфой
local infoFrame = imgui.OnFrame(
function() return infoWindow[0] and not isPauseMenuActive() and not sampIsScoreboardOpen() end,
function()
imgui.SetNextWindowPos(imgui.ImVec2(sizeX / 2, sizeY / 2), imgui.Cond.Once, imgui.ImVec2(0.5, 0.5))
imgui.SetNextWindowSize(imgui.ImVec2(350, 350), imgui.Cond.Always)
imgui.Begin("Info", infoWindow, imgui.WindowFlags.NoResize)
imgui.Text("Hello")
imgui.Text(string.format("Current interior: %s", getActiveInterior()))
imgui.End()
end
)
-- Маин функция
function main()
if not isSampLoaded() or not isSampfuncsLoaded() then return end
while not isSampAvailable() do wait(0) end
sampRegisterChatCommand("codeh", function() mainWindow[0] = not mainWindow[0] end)
sampRegisterChatCommand("sbiv", function() isSbivActive = not isSbivActive
iniSettings.sbiv.isActive = isSbivActive inicfg.save(settings, "NotHelper.ini")
sampAddChatMessage("{adadad} Сбив: " .. (isSbivActive and "{8cff00}Включён" or "{ff0000}Выключен"), -1)
end)
sampRegisterChatCommand("farmbot", function() isFarmActive = not isFarmActive
sampAddChatMessage("{adadad}Бот начальной фермы: " .. (isFarmActive and "{8cff00}Включён" or "{ff0000}Выключен"), -1) end)
wait(1000)
sampAddChatMessage("{fbff00}Загружены все скрипты! By NotBartu", -1)
-- Обработка клавиш
addEventHandler("onWindowMessage", function(msg, wparam, lparam)
if msg == wm.WM_KEYDOWN or msg == wm.WM_SYSKEYDOWN then
-- Основное меню
if wparam == vkeys.VK_NUMPAD0 then
mainWindow[0] = not mainWindow[0]
-- Бот фермы
elseif wparam == vkeys.VK_1 and isFarmActive and not sampIsChatInputActive() and not sampIsDialogActive() and not isPauseMenuActive() and not isSampfuncsConsoleActive() then
sendPacket({220, 18, 29, 0, 0, 0, 109, 105, 110, 105, 71, 97, 109, 101, 46, 107, 101, 121, 82, 101, 97, 99, 116, 105, 111, 110, 46, 102, 105, 110, 105, 115, 104, 124, 55, 0, 0, 0, 0})
sampAddChatMessage("{adadad} Отправлен пакет", -1)
-- Сбив
elseif wparam == vkeys.VK_Q and isSbivActive and not isCharInAnyCar(PLAYER_PED) and not sampIsChatInputActive() and not sampIsDialogActive() and not isPauseMenuActive() and not isSampfuncsConsoleActive() then
clearCharTasksImmediately(PLAYER_PED) freezeCharPosition(PLAYER_PED, false) setPlayerControl(player, true)
end
end
end)
while true do wait(0)
end
end
-- Функции
function sendPacket(packetData)
-- Создаем новый BitStream
local bs = RakLuaBitStream.new()
for _, byte in ipairs(packetData) do
bs:writeInt8(byte)
end
-- Отправляем пакет через RakNet
bs:sendPacket()
end
-- События
-- Тема
function imgui.DarkTheme()
imgui.SwitchContext()
local style = imgui.GetStyle()
local colors = style.Colors
local clr = imgui.Col
local ImVec4 = imgui.ImVec4
-->> Sizez
imgui.GetStyle().WindowPadding = imgui.ImVec2(5, 5)
imgui.GetStyle().FramePadding = imgui.ImVec2(5, 5)
imgui.GetStyle().ItemSpacing = imgui.ImVec2(5, 5)
imgui.GetStyle().ItemInnerSpacing = imgui.ImVec2(5, 5)
imgui.GetStyle().TouchExtraPadding = imgui.ImVec2(5, 5)
imgui.GetStyle().IndentSpacing = 21
imgui.GetStyle().ScrollbarSize = 14
imgui.GetStyle().GrabMinSize = 10
imgui.GetStyle().WindowBorderSize = 0
imgui.GetStyle().ChildBorderSize = 1
imgui.GetStyle().PopupBorderSize = 1
imgui.GetStyle().FrameBorderSize = 1
imgui.GetStyle().TabBorderSize = 0
imgui.GetStyle().WindowRounding = 5
imgui.GetStyle().ChildRounding = 5
imgui.GetStyle().PopupRounding = 5
imgui.GetStyle().FrameRounding = 5
imgui.GetStyle().ScrollbarRounding = 2.5
imgui.GetStyle().GrabRounding = 5
imgui.GetStyle().TabRounding = 5
imgui.GetStyle().WindowTitleAlign = imgui.ImVec2(0.50, 0.50)
-->> Colors
imgui.GetStyle().Colors[imgui.Col.Text] = imgui.ImVec4(1.00, 1.00, 1.00, 1.00)
imgui.GetStyle().Colors[imgui.Col.TextDisabled] = imgui.ImVec4(0.50, 0.50, 0.50, 1.00)
imgui.GetStyle().Colors[imgui.Col.WindowBg] = imgui.ImVec4(0.07, 0.07, 0.07, 1.00)
imgui.GetStyle().Colors[imgui.Col.ChildBg] = imgui.ImVec4(0.07, 0.07, 0.07, 1.00)
imgui.GetStyle().Colors[imgui.Col.PopupBg] = imgui.ImVec4(0.07, 0.07, 0.07, 1.00)
imgui.GetStyle().Colors[imgui.Col.Border] = imgui.ImVec4(0.25, 0.25, 0.26, 0.54)
imgui.GetStyle().Colors[imgui.Col.BorderShadow] = imgui.ImVec4(0.00, 0.00, 0.00, 0.00)
imgui.GetStyle().Colors[imgui.Col.FrameBg] = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
imgui.GetStyle().Colors[imgui.Col.FrameBgHovered] = imgui.ImVec4(0.25, 0.25, 0.26, 1.00)
imgui.GetStyle().Colors[imgui.Col.FrameBgActive] = imgui.ImVec4(0.25, 0.25, 0.26, 1.00)
imgui.GetStyle().Colors[imgui.Col.TitleBg] = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
imgui.GetStyle().Colors[imgui.Col.TitleBgActive] = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
imgui.GetStyle().Colors[imgui.Col.TitleBgCollapsed] = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
imgui.GetStyle().Colors[imgui.Col.MenuBarBg] = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
imgui.GetStyle().Colors[imgui.Col.ScrollbarBg] = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
imgui.GetStyle().Colors[imgui.Col.ScrollbarGrab] = imgui.ImVec4(0.2, 0.2, 0.2, 1.00)
imgui.GetStyle().Colors[imgui.Col.ScrollbarGrabHovered] = imgui.ImVec4(0.25, 0.25, 0.25, 1.00)
imgui.GetStyle().Colors[imgui.Col.ScrollbarGrabActive] = imgui.ImVec4(0.25, 0.25, 0.25, 1.00)
imgui.GetStyle().Colors[imgui.Col.CheckMark] = imgui.ImVec4(1.00, 1.00, 1.00, 1.00)
imgui.GetStyle().Colors[imgui.Col.SliderGrab] = imgui.ImVec4(0.21, 0.20, 0.20, 1.00)
imgui.GetStyle().Colors[imgui.Col.SliderGrabActive] = imgui.ImVec4(0.21, 0.20, 0.20, 1.00)
imgui.GetStyle().Colors[imgui.Col.Button] = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
imgui.GetStyle().Colors[imgui.Col.ButtonHovered] = imgui.ImVec4(0.21, 0.20, 0.20, 1.00)
imgui.GetStyle().Colors[imgui.Col.ButtonActive] = imgui.ImVec4(0.41, 0.41, 0.41, 1.00)
imgui.GetStyle().Colors[imgui.Col.Header] = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
imgui.GetStyle().Colors[imgui.Col.HeaderHovered] = imgui.ImVec4(0.20, 0.20, 0.20, 1.00)
imgui.GetStyle().Colors[imgui.Col.HeaderActive] = imgui.ImVec4(0.47, 0.47, 0.47, 1.00)
imgui.GetStyle().Colors[imgui.Col.Separator] = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
imgui.GetStyle().Colors[imgui.Col.SeparatorHovered] = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
imgui.GetStyle().Colors[imgui.Col.SeparatorActive] = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
imgui.GetStyle().Colors[imgui.Col.ResizeGrip] = imgui.ImVec4(1.00, 1.00, 1.00, 0.25)
imgui.GetStyle().Colors[imgui.Col.ResizeGripHovered] = imgui.ImVec4(1.00, 1.00, 1.00, 0.67)
imgui.GetStyle().Colors[imgui.Col.ResizeGripActive] = imgui.ImVec4(1.00, 1.00, 1.00, 0.95)
imgui.GetStyle().Colors[imgui.Col.Tab] = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
imgui.GetStyle().Colors[imgui.Col.TabHovered] = imgui.ImVec4(0.28, 0.28, 0.28, 1.00)
imgui.GetStyle().Colors[imgui.Col.TabActive] = imgui.ImVec4(0.30, 0.30, 0.30, 1.00)
imgui.GetStyle().Colors[imgui.Col.TabUnfocused] = imgui.ImVec4(0.07, 0.10, 0.15, 0.97)
imgui.GetStyle().Colors[imgui.Col.TabUnfocusedActive] = imgui.ImVec4(0.14, 0.26, 0.42, 1.00)
imgui.GetStyle().Colors[imgui.Col.PlotLines] = imgui.ImVec4(0.61, 0.61, 0.61, 1.00)
imgui.GetStyle().Colors[imgui.Col.PlotLinesHovered] = imgui.ImVec4(1.00, 0.43, 0.35, 1.00)
imgui.GetStyle().Colors[imgui.Col.PlotHistogram] = imgui.ImVec4(0.90, 0.70, 0.00, 1.00)
imgui.GetStyle().Colors[imgui.Col.PlotHistogramHovered] = imgui.ImVec4(1.00, 0.60, 0.00, 1.00)
imgui.GetStyle().Colors[imgui.Col.TextSelectedBg] = imgui.ImVec4(0.5, 0.5, 0.5, 0.35)
imgui.GetStyle().Colors[imgui.Col.DragDropTarget] = imgui.ImVec4(1.00, 1.00, 0.00, 0.90)
imgui.GetStyle().Colors[imgui.Col.NavHighlight] = imgui.ImVec4(0.26, 0.59, 0.98, 1.00)
imgui.GetStyle().Colors[imgui.Col.NavWindowingHighlight] = imgui.ImVec4(1.00, 1.00, 1.00, 0.70)
imgui.GetStyle().Colors[imgui.Col.NavWindowingDimBg] = imgui.ImVec4(0.80, 0.80, 0.80, 0.20)
imgui.GetStyle().Colors[imgui.Col.ModalWindowDimBg] = imgui.ImVec4(0.00, 0.00, 0.00, 0.70)
end