npuKoJLgec

juki

Участник
Автор темы
36
1
Версия SA-MP
  1. 0.3.7 (R1)
Lua:
local sampev = require("samp.events")
local imgui = require("mimgui")
local inicfg = require("inicfg")

local config_name = script.this.filename..".ini"
local config = nil
local window = nil
local stuff = nil

function string.split(text)
    result = {}

    for i in (text.."\n"):gmatch("(.-)\n") do
        table.insert(result, i)
    end

    return result
end

function load_settings()
    local struct = {
        LOGO = {
            auto = true,
            server = 0
        },
        OTHER = {
            decals = true,
            healme = true,
            find = true
        }
    }
    config = inicfg.load(struct, config_name)

    if not doesFileExist(getWorkingDirectory().."\\config\\"..config_name) then
        inicfg.save(config, config_name)
    end
end

function save_settings()
    local structure = {
        LOGO = {
            auto = window.settings.logo.auto[0],
            server = window.settings.logo.server[0]
        },
        OTHER = {
            healme = window.settings.other.healme[0],
            decals = window.settings.other.find[0],
            find = window.settings.other.decals[0]
        }
    }
    config = structure

    inicfg.save(config, config_name)
end

function switch_logo()
    sampTextdrawCreate(stuff.logo.textdraw_ids.to, "Advance_RP", 545, 4)

    if window.settings.logo.auto[0] then
        for i = 1, #stuff.logo.names do
            if not stuff.hostname:find(stuff.logo.names[i]) and stuff.hostname == "" then
                if sampGetCurrentServerName():find(stuff.logo.names[i]) then
                    window.settings.logo.server[0] = i - 1
                end
            end
        end
    end

    sampTextdrawSetLetterSizeAndColor(stuff.logo.textdraw_ids.to, 0.33, 1.5, stuff.logo.colors.text[window.settings.logo.server[0] + 1])
    sampTextdrawSetOutlineColor(stuff.logo.textdraw_ids.to, 1, stuff.logo.colors.outline[window.settings.logo.server[0] + 1])
end

load_settings()

window = {
    image,
    state = imgui.new.bool(),
    settings = {
        logo = {
            auto = imgui.new.bool(config.LOGO.auto),
            server = imgui.new.int(config.LOGO.server)
        },
        other = {
            healme = imgui.new.bool(config.OTHER.healme),
            find = imgui.new.bool(config.OTHER.find),
            decals = imgui.new.bool(config.OTHER.decals)
        }
    }
}

stuff = {
    hostname = "",
    logo = {
        names = {
            "Red",
            "Green",
            "Yellow",
            "Orange",
            "Blue",
            "White",
            "Silver",
            "Purple",
            "Chocolate",
            "Lime"
        },
        textdraw_ids = {
            from = 188,
            to = 201
        },
        colors = {
            text = {
                4290772992.0,
                4278229248.0,
                4294954240.0,
                4294933760.0,
                4278229503.0,
                4294967295.0,
                4288716960.0,
                4291585791.0,
                4287319552.0,
                4282181163.0
            },
            outline = {
                4283760640.0,
                4278206464.0,
                4292241408.0,
                4285540864.0,
                4278190199.0,
                4278190080.0,
                4278190080.0,
                4285005904.0,
                4280160256.0,
                4279985683.0
            }
        }
    },
    find = {
        dialog_id = 63,
        show = false,
        data = {}
    },
    objects = {
        366,
        1001,
        1005,
        1060,
        1113,
        1146,
        1163,
        1241,
        2047,
        2055,
        2061,
        2661,
        2691,
        2720,
        18699,
        19135,
        19198,
        19327,
        19476,
        19483,
        19573,
        19639,
        19846
    }
}

sampRegisterChatCommand("larp", function()
    window.state[0] = not window.state[0]
end)

function sampev.onInitGame(playerId, hostName, settings, vehicleModels, unknown)
    if not hostName:find("Advance RolePlay") then
        return thisScript():unload()
    end

    stuff.hostname = hostName

    switch_logo()
end

function imgui.onShowTextDraw(textdrawId, textdraw)
    if stuff.logo.textdraw_ids.from <= textdrawId and textdrawId <= stuff.logo.textdraw_ids.to then
        return false
    end
end

function sampev.onDisplayGameText(style, time, text)
    if window.settings.other.healme[0] and text:find("med_pack") then
        return { style, time, "~b~+60 hp" }
    end
end

function sampev.onCreateObject(objectId, object)
    if window.settings.other.decals[0] and object.attachToVehicleId ~= 65535 then
        for i = 1, #stuff.objects do
            if stuff.objects[i] == object.modelId then
                return false
            end
        end
    end
end

function sampev.onShowDialog(dialogId, style, title, button1, button2, text)
    if window.settings.other.find[0] and dialogId == stuff.find.dialog_id then
        local split = text:split()

        for i = 1, #split do
            local nickname, id, rang, phone = split[i]:match("%. (%S+)%[(%d+)%]\t(%d+) ранг%. .+\t(%d+)")

            if nickname ~= nil and id ~= nil and rang ~= nil and phone ~= nil then
                if split[i]:find("На паузе") then
                    nickname = nickname.."-AFK"
                end

                if phone:len() <= 6 then
                    phone = phone.."\t"
                end

                table.insert(stuff.find.data, id, {nickname = nickname,
                    rang = rang,
                    phone = phone})
            end
        end

        if button2 ~= "Закрыть" then
            sampSendDialogResponse(stuff.find.dialog_id, 0, 63, "")
        else
            stuff.find.show = true

            raknetSendRpc(155, raknetNewBitStream())
        end

        return false
    end
end

function sampev.onUpdateScoresAndPings(playerList)
    if window.settings.other.find[0] and stuff.find.show then
        stuff.find.show = false
        local text = "Уровень\tРанг\tТелефон\tИмя\n\n{FFFFFF}"

        for i = 0, 1001 do
            if stuff.find.data[i] then
                text = text..playerList[i].score.."\t\t"..
                       stuff.find.data[i].rang.."\t"..
                       stuff.find.data[i].phone.."\t"..
                       stuff.find.data[i].nickname.."\n"
            end
        end

        stuff.find.data = {}

        sampShowDialog(stuff.find.dialog_id, "{ffcf00}Члены организации онлайн", text, "Закрыть", "", 0)
    end
end

local frame = imgui.OnFrame(
    function() return window.state[0] end,
    function(player)
        local function check_box(text, value)
            imgui.Checkbox(text, value)
            save_settings()
        end
        
        imgui.Begin("Legacy ARP", window.state, imgui.WindowFlags.AlwaysAutoResize)
        imgui.Image(window.image, imgui.ImVec2(400, 50))
        
        if imgui.CollapsingHeader("Logo") then
            if imgui.Checkbox("Auto", window.settings.logo.auto) then
                switch_logo()
                save_settings()
            end

            if imgui.Combo("Server", window.settings.logo.server, imgui.new["const char*"][#stuff.logo.names](stuff.logo.names), #stuff.logo.names) then
                window.settings.logo.auto[0] = false

                switch_logo()
                save_settings()
            end
        end

        if imgui.CollapsingHeader("Other") then
            check_box("Old /healme print", window.settings.other.healme)
            imgui.SameLine(130)
            check_box("Disable car decals", window.settings.other.decals)
            check_box("Old /find dialog", window.settings.other.find)
        end
        
        imgui.End()
    end
)

imgui.OnInitialize(function()
    window.image = imgui.CreateTextureFromFile(getWorkingDirectory().."\\resource\\ew\\etereon.png")
    imgui.SwitchContext()
    local style = imgui.GetStyle()
    local colors = style.Colors
    local col = imgui.Col
    style.WindowRounding = 3
    style.WindowBorderSize = 0
    style.WindowTitleAlign = imgui.ImVec2(0.5, 0.5)
    style.ChildRounding = 2
    style.FrameRounding = 2
    style.ItemSpacing = imgui.ImVec2(2, 2)
    style.ScrollbarSize = 15
    style.ScrollbarRounding = 1
    style.GrabMinSize = 9.6
    style.GrabRounding = 2
    style.WindowPadding = imgui.ImVec2(2, 2)
    style.AntiAliasedLines = true
    style.AntiAliasedFill = true
    style.FramePadding = imgui.ImVec2(2, 2)
    style.DisplayWindowPadding = imgui.ImVec2(27, 27)
    style.DisplaySafeAreaPadding = imgui.ImVec2(2, 2)
    style.ButtonTextAlign = imgui.ImVec2(0.5, 0.5)
    colors[col.FrameBg] = imgui.ImVec4(0.16, 0.48, 0.42, 0.54)
    colors[col.FrameBgHovered] = imgui.ImVec4(0.26, 0.98, 0.85, 0.4)
    colors[col.FrameBgActive] = imgui.ImVec4(0.26, 0.98, 0.85, 0.67)
    colors[col.TitleBg] = imgui.ImVec4(0.12, 0.36, 0.32, 1)
    colors[col.TitleBgActive] = imgui.ImVec4(0.16, 0.48, 0.42, 1)
    colors[col.TitleBgCollapsed] = imgui.ImVec4(0, 0, 0, 0.51)
    colors[col.CheckMark] = imgui.ImVec4(0.26, 0.98, 0.85, 1)
    colors[col.SliderGrab] = imgui.ImVec4(0.24, 0.88, 0.77, 1)
    colors[col.SliderGrabActive] = imgui.ImVec4(0.26, 0.98, 0.85, 1)
    colors[col.Button] = imgui.ImVec4(0.26, 0.98, 0.85, 0.4)
    colors[col.ButtonHovered] = imgui.ImVec4(0.26, 0.98, 0.85, 1)
    colors[col.ButtonActive] = imgui.ImVec4(0.06, 0.98, 0.82, 1)
    colors[col.Header] = imgui.ImVec4(0.26, 0.98, 0.85, 0.31)
    colors[col.HeaderHovered] = imgui.ImVec4(0.26, 0.98, 0.85, 0.8)
    colors[col.HeaderActive] = imgui.ImVec4(0.26, 0.98, 0.85, 1)
    colors[col.SeparatorHovered] = imgui.ImVec4(0.1, 0.75, 0.63, 0.78)
    colors[col.SeparatorActive] = imgui.ImVec4(0.1, 0.75, 0.63, 1)
    colors[col.ResizeGrip] = imgui.ImVec4(0.26, 0.98, 0.85, 0.25)
    colors[col.ResizeGripHovered] = imgui.ImVec4(0.26, 0.98, 0.85, 0.67)
    colors[col.ResizeGripActive] = imgui.ImVec4(0.26, 0.98, 0.85, 0.95)
    colors[col.PlotLines] = imgui.ImVec4(0.61, 0.61, 0.61, 1)
    colors[col.PlotLinesHovered] = imgui.ImVec4(1, 0.81, 0.35, 1)
    colors[col.TextSelectedBg] = imgui.ImVec4(0.26, 0.98, 0.85, 0.35)
    colors[col.Text] = imgui.ImVec4(1, 1, 1, 1)
    colors[col.TextDisabled] = imgui.ImVec4(0.5, 0.5, 0.5, 1)
    colors[col.WindowBg] = imgui.ImVec4(0.06, 0.06, 0.06, 0.94)
    colors[col.PopupBg] = imgui.ImVec4(0.08, 0.08, 0.08, 0.94)
    colors[col.Border] = imgui.ImVec4(0.43, 0.43, 0.5, 0.5)
    colors[col.BorderShadow] = imgui.ImVec4(0, 0, 0, 0)
    colors[col.MenuBarBg] = imgui.ImVec4(0.14, 0.14, 0.14, 1)
    colors[col.ScrollbarBg] = imgui.ImVec4(0.02, 0.02, 0.02, 0.53)
    colors[col.ScrollbarGrab] = imgui.ImVec4(0.31, 0.31, 0.31, 1)
    colors[col.ScrollbarGrabHovered] = imgui.ImVec4(0.41, 0.41, 0.41, 1)
    colors[col.ScrollbarGrabActive] = imgui.ImVec4(0.51, 0.51, 0.51, 1)
    colors[col.PlotHistogram] = imgui.ImVec4(0.9, 0.7, 0, 1)
    colors[col.PlotHistogramHovered] = imgui.ImVec4(1, 0.6, 0, 1)
end)
не знаю даже как описать, функция auto включена, но при заходе на другой сервер переменная server не меняется, толкьо после перезагрузки скрипта всё работает
 

[w0te]

Известный
819
543
в бесконечный цикл перепиши функцию, и у тебя тут перепутано кажется

Screenshot_10.png
 
  • Нравится
Реакции: juki