Вопросы по Lua скриптингу

Общая тема для вопросов по разработке скриптов на языке программирования Lua, в частности под MoonLoader.
  • Задавая вопрос, убедитесь, что его нет в списке частых вопросов и что на него ещё не отвечали (воспользуйтесь поиском).
  • Поищите ответ в теме посвященной разработке Lua скриптов в MoonLoader
  • Отвечая, убедитесь, что ваш ответ корректен.
  • Старайтесь как можно точнее выразить мысль, а если проблема связана с кодом, то обязательно прикрепите его к сообщению, используя блок [code=lua]здесь мог бы быть ваш код[/code].
  • Если вопрос связан с MoonLoader-ом первым делом желательно поискать решение на wiki.

Частые вопросы

Как научиться писать скрипты? С чего начать?
Информация - Гайд - Всё о Lua скриптинге для MoonLoader(https://blast.hk/threads/22707/)
Как вывести текст на русском? Вместо русского текста у меня какие-то каракули.
Изменить кодировку файла скрипта на Windows-1251. В Atom: комбинация клавиш Ctrl+Shift+U, в Notepad++: меню Кодировки -> Кодировки -> Кириллица -> Windows-1251.
Как получить транспорт, в котором сидит игрок?
Lua:
local veh = storeCarCharIsInNoSave(PLAYER_PED)
Как получить свой id или id другого игрока?
Lua:
local _, id = sampGetPlayerIdByCharHandle(PLAYER_PED) -- получить свой ид
local _, id = sampGetPlayerIdByCharHandle(ped) -- получить ид другого игрока. ped - это хендл персонажа
Как проверить, что строка содержит какой-то текст?
Lua:
if string.find(str, 'текст', 1, true) then
-- строка str содержит "текст"
end
Как эмулировать нажатие игровой клавиши?
Lua:
local game_keys = require 'game.keys' -- где-нибудь в начале скрипта вне функции main

setGameKeyState(game_keys.player.FIREWEAPON, -1) -- будет сэмулировано нажатие клавиши атаки
Все иды клавиш находятся в файле moonloader/lib/game/keys.lua.
Подробнее о функции setGameKeyState здесь: lua - setgamekeystate | BlastHack — DEV_WIKI(https://www.blast.hk/wiki/lua:setgamekeystate)
Как получить id другого игрока, в которого целюсь я?
Lua:
local valid, ped = getCharPlayerIsTargeting(PLAYER_HANDLE) -- получить хендл персонажа, в которого целится игрок
if valid and doesCharExist(ped) then -- если цель есть и персонаж существует
  local result, id = sampGetPlayerIdByCharHandle(ped) -- получить samp-ид игрока по хендлу персонажа
  if result then -- проверить, прошло ли получение ида успешно
    -- здесь любые действия с полученным идом игрока
  end
end
Как зарегистрировать команду чата SAMP?
Lua:
-- До бесконечного цикла/задержки
sampRegisterChatCommand("mycommand", function (param)
     -- param будет содержать весь текст введенный после команды, чтобы разделить его на аргументы используйте string.match()
    sampAddChatMessage("MyCMD", -1)
end)
Крашит игру при вызове sampSendChat. Как это исправить?
Это происходит из-за бага в SAMPFUNCS, когда производится попытка отправки пакета определенными функциями изнутри события исходящих RPC и пакетов. Исправления для этого бага нет, но есть способ не провоцировать его. Вызов sampSendChat изнутри обработчика исходящих RPC/пакетов нужно обернуть в скриптовый поток с нулевой задержкой:
Lua:
function onSendRpc(id)
  -- крашит:
  -- sampSendChat('Send RPC: ' .. id)

  -- норм:
  lua_thread.create(function()
    wait(0)
    sampSendChat('Send RPC: ' .. id)
  end)
end
 
Последнее редактирование:

samartinell1

Участник
98
14
Как сделать на имгуи кнопочку типа такой:
1 выбор
2 выбор
3 выбор
ну короче, как спрятать несколько кнопок под такой вот спойлер в имгуи?
 

S.Walston

Новичок
22
1
Разумеется создать текстдрав или ImgUi окно, дальше:
Lua:
_, pID = sampGetPlayerIdByCharHandle(playerPed)
sampGetPlayerNickname(pID) -- получить ник
sampGetPlayerScore(pID) -- получить уровень
А чтобы узнать АФК и онлайн счётчики запустить придется.
Можно пример, как запустить счетчики?)
 

wuwkun_Jlec

Новичок
13
3
почему не отправляет сообщение в смс человеку, которого я убил ?
Код:
-- СМСочка
if playerId ~= nil and active then
    if not isPlayerDead(PLAYER_HANDLE) and not damage ~= nil then
        hp = sampGetPlayerHealth(playerId)
        new_hp = hp - damage
        
        lua_thread.create(function()
            wait(0)
            if new_hp == 0 or new_hp < 0 then
                sampSendChat("/sms "..playerid.." qq!")
            elseif new_hp < load_settings.settings.cell_hp then
                sampSendChat("/sms "..playerid.." qq")
            end
        end)
    end
    playerId = nil
end
 

CaJlaT

Овощ
Модератор
2,808
2,609
почему не отправляет сообщение в смс человеку, которого я убил ?
Код:
-- СМСочка
if playerId ~= nil and active then
    if not isPlayerDead(PLAYER_HANDLE) and not damage ~= nil then
        hp = sampGetPlayerHealth(playerId)
        new_hp = hp - damage
       
        lua_thread.create(function()
            wait(0)
            if new_hp == 0 or new_hp < 0 then
                sampSendChat("/sms "..playerid.." qq!")
            elseif new_hp < load_settings.settings.cell_hp then
                sampSendChat("/sms "..playerid.." qq")
            end
        end)
    end
    playerId = nil
end
Lua:
-- СМСочка
if playerId ~= nil and active then
    if not isPlayerDead(PLAYER_HANDLE) and not damage ~= nil then
        hp = sampGetPlayerHealth(playerId)
        new_hp = hp - damage
        
        lua_thread.create(function()
            wait(0)
            if new_hp == 0 or new_hp < 0 then
                sampSendChat("/sms "..playerId.." qq!")
            elseif new_hp < load_settings.settings.cell_hp then
                sampSendChat("/sms "..playerId.." qq")
            end
        end)
    end
    playerId = nil
end
 

S.Walston

Новичок
22
1
C++:
----------------------------------------------------------------------------------------
require "lib.moonloader"
requests = require('requests')

local city = {
    [0] = "Village",
    [1] = "Los-Santos",
    [2] = "San-Fierro",
    [3] = "Las-Venturas"
}
local sampev = require 'lib.samp.events'
local active = true
local mem = require 'memory'
local main_color = 0xFFFFFF
local tag = "{FFD700}[INFOBAR]:"
local keys = require 'vkeys'
local playsec = 0
local playmin = 0
local playhours = 0
local tables
local imgui = require 'imgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
local limgui, imgui = pcall(require, 'imgui') assert(limgui, 'Library \'imgui\' not found.')
local limadd, imadd = pcall(require, 'imgui_addons') assert(limadd, 'Library \'imgui_addons\' not found.')
local lencoding, encoding = pcall(require, 'encoding') assert(lencoding, 'Library \'encoding\' not found.')

----------------------------------------------------------------------------------------

encoding.default = 'CP1251'
local u8 = encoding.UTF8

----------------------------------------------------------------------------------------

activate = false

----------------------------------------------------------------------------------------

local window = imgui.ImBool(false)

----------------------------------------------------------------------------------------

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
    imgui.ShowCursor = false
    imgui.SetMouseCursor(-1)
    sampAddChatMessage("[Fantasy] Скрипт загружен. Специально для Fantasy Empire", 0xFF27940C)
    sampAddChatMessage("[Fantasy] Скрипт загружен. Специально для Fantasy Empire", 0xFF27940C)
    sampRegisterChatCommand("poisk", function ()
        window.v = not window.v
    end)
    lua_thread.create(flooder)
    while true do
        wait(0)
            playsec = playsec + 1
            if playsec == 60 and playmin then
                playmin = playmin + 1
                playsec = 0
            end
            if playmin == 60 then
                playhours = playhours + 1
                playmin = 0
            end
        if main_window_state.v == false then
        imgui.Process = true
        end
        imgui.Process = window.v
    end
    wait(-1)
end

function imgui.OnDrawFrame()
    local iScreenWidth, iScreenHeight = getScreenResolution()
    local btn_size = imgui.ImVec2(-0.1, 0)
    activeB = imgui.ImBool(activate)
   
    if window.v then
       
        imgui.SetNextWindowPos(imgui.ImVec2(iScreenWidth / 2, iScreenHeight / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.SetNextWindowSize(imgui.ImVec2(500, 350), imgui.Cond.FirstUseEver)
     
        imgui.Begin(u8"Fantasy Empire", window, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse)
       
        imgui.Separator()
       
        if imgui.Button(u8 "Тест") then
            imgui.OpenPopup(u8 "Тест")
            lua_thread.create(function()
                sampSendChat("/aad Helpers | Хочешь быть хелпером?", -1)
                wait(1000)
                sampSendChat("/aad Helpers | Тогда скорее отпишись мне в репорт!")
                wait(1000)
                sampSendChat("/aad Helpers | Ожидаем всех!", -1)
                wait(1000)
                sampAddChatMessage("{FF0000}Удачного вам поиска =)", 0x01FAD2)
            end)
        end
        if imgui.Button(u8 "Тест") then
            imgui.OpenPopup(u8 "Тест")
            lua_thread.create(function()
                sampSendChat("/a Helpers | Происходит поиск ЗГСов Helpers", -1)
                wait(1000)
                sampSendChat("/a Helpers | Все подробности можете узнать в ВК у меня!")
                wait(1000)
                sampSendChat("/a Helpers | Все подробности ->Закрыто", -1)
                wait(1000)
                sampAddChatMessage("{FF0000}Удачни найти ЗГСов!", 0x01FAD2)
            end)
        end
        if imgui.Button(u8 "Тест") then
            imgui.OpenPopup(u8 "Тест")
            lua_thread.create(function()
                sampSendChat("/a Helpers | Уважаемые коллеги, хелперы, обращаюсь к вам", -1)
                wait(1000)
                sampSendChat("/a Helpers | Что бы повысить свой уровень хелперки, вам нужно ответь на репорты!")
                wait(1000)
                sampSendChat("/a Helpers | Чем больше отвечаете - тем больше ваш ЛВЛ!", -1)
                wait(1000)
                sampAddChatMessage("{FF0000}Эти бездельники предупреждены!!", 0x01FAD2)
            end)
        end
       
        imgui.Separator()
        imgui.NewLine()
       
        imgui.Text(u8 'Авто - Пиар Fantasy Empire в вип чат')
        if imadd.ToggleButton(u8 "Sprunk##", activeB) then activate = not activate if activate then sampAddChatMessage('Вы активировали скрипт', -1) else sampAddChatMessage('Вы деактивировали скрипт.', -1) end end
        imgui.SameLine(); imgui.Text(u8 'Нажми, если хочешь включить пиар')
    end
   
    imgui.End()
end

function flooder()
    while true do
        if activate then
            sampSendChat("/vr Проходит набор в империю Fantasy. Все улучшения, Discord, Беседа в ВК. Звоните/Пишите")
        end
        wait(300000)
    end
end

function black_grey()
    imgui.SwitchContext()
    local style = imgui.GetStyle()
    local colors = style.Colors
    local clr = imgui.Col
    local ImVec4 = imgui.ImVec4
    local ImVec2 = imgui.ImVec2

    style.WindowPadding = imgui.ImVec2(8, 8)
    style.WindowRounding = 6
    style.ChildWindowRounding = 5
    style.FramePadding = imgui.ImVec2(5, 3)
    style.FrameRounding = 3.0
    style.ItemSpacing = imgui.ImVec2(5, 4)
    style.ItemInnerSpacing = imgui.ImVec2(4, 4)
    style.IndentSpacing = 21
    style.ScrollbarSize = 10.0
    style.ScrollbarRounding = 13
    style.GrabMinSize = 8
    style.GrabRounding = 1
    style.WindowTitleAlign = imgui.ImVec2(0.5, 0.5)
    style.ButtonTextAlign = imgui.ImVec2(0.5, 0.5)

    colors[clr.Text] = ImVec4(1.00, 1.00, 1.00, 0.95)
    colors[clr.TextDisabled] = ImVec4(0.50, 0.50, 0.50, 1.00)
    colors[clr.WindowBg] = ImVec4(0.13, 0.12, 0.12, 1.00)
    colors[clr.ChildWindowBg] = ImVec4(0.13, 0.12, 0.12, 1.00)
    colors[clr.PopupBg] = ImVec4(0.05, 0.05, 0.05, 0.94)
    colors[clr.Border] = ImVec4(0.53, 0.53, 0.53, 0.46)
    colors[clr.BorderShadow] = ImVec4(0.00, 0.00, 0.00, 0.00)
    colors[clr.FrameBg] = ImVec4(0.00, 0.00, 0.00, 0.85)
    colors[clr.FrameBgHovered] = ImVec4(0.22, 0.22, 0.22, 0.40)
    colors[clr.FrameBgActive] = ImVec4(0.16, 0.16, 0.16, 0.53)
    colors[clr.TitleBg] = ImVec4(0.00, 0.00, 0.00, 1.00)
    colors[clr.TitleBgActive] = ImVec4(0.00, 0.00, 0.00, 1.00)
    colors[clr.TitleBgCollapsed] = ImVec4(0.00, 0.00, 0.00, 0.51)
    colors[clr.MenuBarBg] = ImVec4(0.12, 0.12, 0.12, 1.00)
    colors[clr.ScrollbarBg] = ImVec4(0.02, 0.02, 0.02, 0.53)
    colors[clr.ScrollbarGrab] = ImVec4(0.31, 0.31, 0.31, 1.00)
    colors[clr.ScrollbarGrabHovered] = ImVec4(0.41, 0.41, 0.41, 1.00)
    colors[clr.ScrollbarGrabActive] = ImVec4(0.48, 0.48, 0.48, 1.00)
    colors[clr.ComboBg] = ImVec4(0.24, 0.24, 0.24, 0.99)
    colors[clr.CheckMark] = ImVec4(0.79, 0.79, 0.79, 1.00)
    colors[clr.SliderGrab] = ImVec4(0.48, 0.47, 0.47, 0.91)
    colors[clr.SliderGrabActive] = ImVec4(0.56, 0.55, 0.55, 0.62)
    colors[clr.Button] = ImVec4(0.50, 0.50, 0.50, 0.63)
    colors[clr.ButtonHovered] = ImVec4(0.67, 0.67, 0.68, 0.63)
    colors[clr.ButtonActive] = ImVec4(0.26, 0.26, 0.26, 0.63)
    colors[clr.Header] = ImVec4(0.54, 0.54, 0.54, 0.58)
    colors[clr.HeaderHovered] = ImVec4(0.64, 0.65, 0.65, 0.80)
    colors[clr.HeaderActive] = ImVec4(0.25, 0.25, 0.25, 0.80)
    colors[clr.Separator] = ImVec4(0.58, 0.58, 0.58, 0.50)
    colors[clr.SeparatorHovered] = ImVec4(0.81, 0.81, 0.81, 0.64)
    colors[clr.SeparatorActive] = ImVec4(0.81, 0.81, 0.81, 0.64)
    colors[clr.ResizeGrip] = ImVec4(0.87, 0.87, 0.87, 0.53)
    colors[clr.ResizeGripHovered] = ImVec4(0.87, 0.87, 0.87, 0.74)
    colors[clr.ResizeGripActive] = ImVec4(0.87, 0.87, 0.87, 0.74)
    colors[clr.CloseButton] = ImVec4(0.45, 0.45, 0.45, 0.50)
    colors[clr.CloseButtonHovered] = ImVec4(0.70, 0.70, 0.90, 0.60)
    colors[clr.CloseButtonActive] = ImVec4(0.70, 0.70, 0.70, 1.00)
    colors[clr.PlotLines] = ImVec4(0.68, 0.68, 0.68, 1.00)
    colors[clr.PlotLinesHovered] = ImVec4(0.68, 0.68, 0.68, 1.00)
    colors[clr.PlotHistogram] = ImVec4(0.90, 0.77, 0.33, 1.00)
    colors[clr.PlotHistogramHovered] = ImVec4(0.87, 0.55, 0.08, 1.00)
    colors[clr.TextSelectedBg] = ImVec4(0.47, 0.60, 0.76, 0.47)
    colors[clr.ModalWindowDarkening] = ImVec4(0.88, 0.88, 0.88, 0.35)
end

function cmd_imgui(arg)
    main_window_state.v = not main_window_state.v
    imgui.Process = main_window_state.v or show_2_window.v
end

function imgui.OnDrawFrame()
    if not isCharInAnyCar(PLAYER_PED) then
        imgui.SetNextWindowPos(imgui.ImVec2(430, 824), imgui.Cond.FirstUseEver)
        imgui.ShowCursor = false
        imgui.SetMouseCursor(-1)
        _, id = sampGetPlayerIdByCharHandle(PLAYER_PED)
        server = sampGetCurrentServerName(PLAYER_HANDLE)
        ip = sampGetCurrentServerAddress(PLAYER_PED)
        weap = getCurrentCharWeapon(PLAYER_PED)
        weaponid = getWeapontypeModel(weap)
        ammo = getAmmoInCharWeapon(PLAYER_PED, weap)
        nick = sampGetPlayerNickname(id)
        fFps = mem.getfloat(0xB7CB50, 4, false)  
        ping = sampGetPlayerPing(id)
        time = (os.date("%H",os.time())..':'..os.date("%M",os.time())..':'..os.date("%S",os.time()))
        date = (os.date("%d",os.time())..'/'..os.date("%m",os.time())..'/'..os.date("%Y",os.time()))
        Health = getCharHealth(PLAYER_PED)
        Armor = getCharArmour(PLAYER_PED)
        Level = sampGetPlayerScore(id)
        pspeed = getCharSpeed(PLAYER_PED)
        x,y,z = getCharCoordinates(PLAYER_PED)
        Hours = (os.date("%H", os.time()))
        Minuts = (os.date("%M", os.time()))
        Seconds = (os.date("%S", os.time()))
        imgui.Begin("INFOBAR | Coded by NNC.", window, imgui.WindowFlags.NoTitleBar + imgui.WindowFlags.NoResize + imgui.WindowFlags.AlwaysAutoResize + imgui.WindowFlags.ShowBorders)
        imgui.Text("Server: " .. server, main_color)
        imgui.Text("NickName: " .. nick ..  " | ID: " .. id, main_color)
        imgui.Text("Ping: " .. ping .. " | Level: " .. Level .. " | FPS: " .. math.floor(fFps), main_color)
        imgui.Text("Time: " .. time .. " | Date: " .. date, main_color)
        imgui.Text("City: " .. city[getCityPlayerIsIn(PLAYER_HANDLE)] .. " | PlayerTime: " .. playhours .. ":" .. playmin .. ":" .. playsec, main_color)
        imgui.Text("Health: " .. Health .. " | Armour: " .. Armor .. " | Speed: " .. math.floor(pspeed), main_color)
        imgui.Text("Weapon: " .. weap.. " | Ammo: " .. ammo, main_color)
        imgui.Text("X: " .. math.floor(x) .. " | Y: " .. math.floor(y) .. " | Z: " .. math.floor(z), main_color)
        imgui.End()
    else
        imgui.SetNextWindowPos(imgui.ImVec2(430, 824), imgui.Cond.FirstUseEver)
        imgui.ShowCursor = false
        imgui.SetMouseCursor(-1)
        _, id = sampGetPlayerIdByCharHandle(PLAYER_PED)
        car = storeCarCharIsInNoSave(playerPed)
        carmodel = getCarModel(car)
        carname = getGxtText(getNameOfVehicleModel(carmodel))
        _, cid = sampGetVehicleIdByCarHandle(car)
        carhp = getCarHealth(car)
        cspeed = getCarSpeed(car)
        server = sampGetCurrentServerName(PLAYER_HANDLE)
        ip = sampGetCurrentServerAddress(PLAYER_PED)
        nick = sampGetPlayerNickname(id)
        fFps = mem.getfloat(0xB7CB50, 4, false)  
        ping = sampGetPlayerPing(id)
        time = (os.date("%H",os.time())..':'..os.date("%M",os.time())..':'..os.date("%S",os.time()))
        date = (os.date("%d",os.time())..'/'..os.date("%m",os.time())..'/'..os.date("%Y",os.time()))
        Health = getCharHealth(PLAYER_PED)
        Armor = getCharArmour(PLAYER_PED)
        Hours = (os.date("%H", os.time()))
        Minuts = (os.date("%M", os.time()))
        Seconds = (os.date("%S", os.time()))
        Level = sampGetPlayerScore(id)
        x,y,z = getCharCoordinates(PLAYER_PED)
        imgui.Begin("INFOBAR | Coded by NNC.", window, imgui.WindowFlags.NoTitleBar + imgui.WindowFlags.NoResize + imgui.WindowFlags.AlwaysAutoResize + imgui.WindowFlags.ShowBorders)
        imgui.Text("Server: " .. server, main_color)
        imgui.Text("NickName: " .. nick ..  " | ID: " .. id, main_color)
        imgui.Text("Ping: " .. ping .. " | Level: " .. Level .. " | FPS: " .. math.floor(fFps), main_color)
        imgui.Text("Time: " .. time .. " | Date: " .. date, main_color)
        imgui.Text("City: " .. city[getCityPlayerIsIn(PLAYER_HANDLE)] .. " | PlayerTime: " .. playhours .. ":" .. playmin .. ":" .. playsec, main_color)
        imgui.Text("Health: " .. Health .. " | Armour: " .. Armor .. " | Speed: " .. math.floor(cspeed * 2.5), main_color)
        imgui.Text("CarHP: " .. carhp .. " | CarID: " .. cid .. " | CarType: " .. carmodel, main_color)
        imgui.Text("X: " .. math.floor(x) .. " | Y: " .. math.floor(y) .. " | Z: " .. math.floor(z), main_color)
        imgui.End()  
    end
end
black_grey()
Что делать, если не выскакивает инфобар?
P.S Основное имгуи тоже не работает
 

Viem

Известный
49
5
Как у окна imgui.Begin(),полностью выключить поле заголовка?
 

CaJlaT

Овощ
Модератор
2,808
2,609
C++:
----------------------------------------------------------------------------------------
require "lib.moonloader"
requests = require('requests')

local city = {
    [0] = "Village",
    [1] = "Los-Santos",
    [2] = "San-Fierro",
    [3] = "Las-Venturas"
}
local sampev = require 'lib.samp.events'
local active = true
local mem = require 'memory'
local main_color = 0xFFFFFF
local tag = "{FFD700}[INFOBAR]:"
local keys = require 'vkeys'
local playsec = 0
local playmin = 0
local playhours = 0
local tables
local imgui = require 'imgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
local limgui, imgui = pcall(require, 'imgui') assert(limgui, 'Library \'imgui\' not found.')
local limadd, imadd = pcall(require, 'imgui_addons') assert(limadd, 'Library \'imgui_addons\' not found.')
local lencoding, encoding = pcall(require, 'encoding') assert(lencoding, 'Library \'encoding\' not found.')

----------------------------------------------------------------------------------------

encoding.default = 'CP1251'
local u8 = encoding.UTF8

----------------------------------------------------------------------------------------

activate = false

----------------------------------------------------------------------------------------

local window = imgui.ImBool(false)

----------------------------------------------------------------------------------------

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
    imgui.ShowCursor = false
    imgui.SetMouseCursor(-1)
    sampAddChatMessage("[Fantasy] Скрипт загружен. Специально для Fantasy Empire", 0xFF27940C)
    sampAddChatMessage("[Fantasy] Скрипт загружен. Специально для Fantasy Empire", 0xFF27940C)
    sampRegisterChatCommand("poisk", function ()
        window.v = not window.v
    end)
    lua_thread.create(flooder)
    while true do
        wait(0)
            playsec = playsec + 1
            if playsec == 60 and playmin then
                playmin = playmin + 1
                playsec = 0
            end
            if playmin == 60 then
                playhours = playhours + 1
                playmin = 0
            end
        if main_window_state.v == false then
        imgui.Process = true
        end
        imgui.Process = window.v
    end
    wait(-1)
end

function imgui.OnDrawFrame()
    local iScreenWidth, iScreenHeight = getScreenResolution()
    local btn_size = imgui.ImVec2(-0.1, 0)
    activeB = imgui.ImBool(activate)
  
    if window.v then
      
        imgui.SetNextWindowPos(imgui.ImVec2(iScreenWidth / 2, iScreenHeight / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.SetNextWindowSize(imgui.ImVec2(500, 350), imgui.Cond.FirstUseEver)
    
        imgui.Begin(u8"Fantasy Empire", window, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse)
      
        imgui.Separator()
      
        if imgui.Button(u8 "Тест") then
            imgui.OpenPopup(u8 "Тест")
            lua_thread.create(function()
                sampSendChat("/aad Helpers | Хочешь быть хелпером?", -1)
                wait(1000)
                sampSendChat("/aad Helpers | Тогда скорее отпишись мне в репорт!")
                wait(1000)
                sampSendChat("/aad Helpers | Ожидаем всех!", -1)
                wait(1000)
                sampAddChatMessage("{FF0000}Удачного вам поиска =)", 0x01FAD2)
            end)
        end
        if imgui.Button(u8 "Тест") then
            imgui.OpenPopup(u8 "Тест")
            lua_thread.create(function()
                sampSendChat("/a Helpers | Происходит поиск ЗГСов Helpers", -1)
                wait(1000)
                sampSendChat("/a Helpers | Все подробности можете узнать в ВК у меня!")
                wait(1000)
                sampSendChat("/a Helpers | Все подробности ->Закрыто", -1)
                wait(1000)
                sampAddChatMessage("{FF0000}Удачни найти ЗГСов!", 0x01FAD2)
            end)
        end
        if imgui.Button(u8 "Тест") then
            imgui.OpenPopup(u8 "Тест")
            lua_thread.create(function()
                sampSendChat("/a Helpers | Уважаемые коллеги, хелперы, обращаюсь к вам", -1)
                wait(1000)
                sampSendChat("/a Helpers | Что бы повысить свой уровень хелперки, вам нужно ответь на репорты!")
                wait(1000)
                sampSendChat("/a Helpers | Чем больше отвечаете - тем больше ваш ЛВЛ!", -1)
                wait(1000)
                sampAddChatMessage("{FF0000}Эти бездельники предупреждены!!", 0x01FAD2)
            end)
        end
      
        imgui.Separator()
        imgui.NewLine()
      
        imgui.Text(u8 'Авто - Пиар Fantasy Empire в вип чат')
        if imadd.ToggleButton(u8 "Sprunk##", activeB) then activate = not activate if activate then sampAddChatMessage('Вы активировали скрипт', -1) else sampAddChatMessage('Вы деактивировали скрипт.', -1) end end
        imgui.SameLine(); imgui.Text(u8 'Нажми, если хочешь включить пиар')
    end
  
    imgui.End()
end

function flooder()
    while true do
        if activate then
            sampSendChat("/vr Проходит набор в империю Fantasy. Все улучшения, Discord, Беседа в ВК. Звоните/Пишите")
        end
        wait(300000)
    end
end

function black_grey()
    imgui.SwitchContext()
    local style = imgui.GetStyle()
    local colors = style.Colors
    local clr = imgui.Col
    local ImVec4 = imgui.ImVec4
    local ImVec2 = imgui.ImVec2

    style.WindowPadding = imgui.ImVec2(8, 8)
    style.WindowRounding = 6
    style.ChildWindowRounding = 5
    style.FramePadding = imgui.ImVec2(5, 3)
    style.FrameRounding = 3.0
    style.ItemSpacing = imgui.ImVec2(5, 4)
    style.ItemInnerSpacing = imgui.ImVec2(4, 4)
    style.IndentSpacing = 21
    style.ScrollbarSize = 10.0
    style.ScrollbarRounding = 13
    style.GrabMinSize = 8
    style.GrabRounding = 1
    style.WindowTitleAlign = imgui.ImVec2(0.5, 0.5)
    style.ButtonTextAlign = imgui.ImVec2(0.5, 0.5)

    colors[clr.Text] = ImVec4(1.00, 1.00, 1.00, 0.95)
    colors[clr.TextDisabled] = ImVec4(0.50, 0.50, 0.50, 1.00)
    colors[clr.WindowBg] = ImVec4(0.13, 0.12, 0.12, 1.00)
    colors[clr.ChildWindowBg] = ImVec4(0.13, 0.12, 0.12, 1.00)
    colors[clr.PopupBg] = ImVec4(0.05, 0.05, 0.05, 0.94)
    colors[clr.Border] = ImVec4(0.53, 0.53, 0.53, 0.46)
    colors[clr.BorderShadow] = ImVec4(0.00, 0.00, 0.00, 0.00)
    colors[clr.FrameBg] = ImVec4(0.00, 0.00, 0.00, 0.85)
    colors[clr.FrameBgHovered] = ImVec4(0.22, 0.22, 0.22, 0.40)
    colors[clr.FrameBgActive] = ImVec4(0.16, 0.16, 0.16, 0.53)
    colors[clr.TitleBg] = ImVec4(0.00, 0.00, 0.00, 1.00)
    colors[clr.TitleBgActive] = ImVec4(0.00, 0.00, 0.00, 1.00)
    colors[clr.TitleBgCollapsed] = ImVec4(0.00, 0.00, 0.00, 0.51)
    colors[clr.MenuBarBg] = ImVec4(0.12, 0.12, 0.12, 1.00)
    colors[clr.ScrollbarBg] = ImVec4(0.02, 0.02, 0.02, 0.53)
    colors[clr.ScrollbarGrab] = ImVec4(0.31, 0.31, 0.31, 1.00)
    colors[clr.ScrollbarGrabHovered] = ImVec4(0.41, 0.41, 0.41, 1.00)
    colors[clr.ScrollbarGrabActive] = ImVec4(0.48, 0.48, 0.48, 1.00)
    colors[clr.ComboBg] = ImVec4(0.24, 0.24, 0.24, 0.99)
    colors[clr.CheckMark] = ImVec4(0.79, 0.79, 0.79, 1.00)
    colors[clr.SliderGrab] = ImVec4(0.48, 0.47, 0.47, 0.91)
    colors[clr.SliderGrabActive] = ImVec4(0.56, 0.55, 0.55, 0.62)
    colors[clr.Button] = ImVec4(0.50, 0.50, 0.50, 0.63)
    colors[clr.ButtonHovered] = ImVec4(0.67, 0.67, 0.68, 0.63)
    colors[clr.ButtonActive] = ImVec4(0.26, 0.26, 0.26, 0.63)
    colors[clr.Header] = ImVec4(0.54, 0.54, 0.54, 0.58)
    colors[clr.HeaderHovered] = ImVec4(0.64, 0.65, 0.65, 0.80)
    colors[clr.HeaderActive] = ImVec4(0.25, 0.25, 0.25, 0.80)
    colors[clr.Separator] = ImVec4(0.58, 0.58, 0.58, 0.50)
    colors[clr.SeparatorHovered] = ImVec4(0.81, 0.81, 0.81, 0.64)
    colors[clr.SeparatorActive] = ImVec4(0.81, 0.81, 0.81, 0.64)
    colors[clr.ResizeGrip] = ImVec4(0.87, 0.87, 0.87, 0.53)
    colors[clr.ResizeGripHovered] = ImVec4(0.87, 0.87, 0.87, 0.74)
    colors[clr.ResizeGripActive] = ImVec4(0.87, 0.87, 0.87, 0.74)
    colors[clr.CloseButton] = ImVec4(0.45, 0.45, 0.45, 0.50)
    colors[clr.CloseButtonHovered] = ImVec4(0.70, 0.70, 0.90, 0.60)
    colors[clr.CloseButtonActive] = ImVec4(0.70, 0.70, 0.70, 1.00)
    colors[clr.PlotLines] = ImVec4(0.68, 0.68, 0.68, 1.00)
    colors[clr.PlotLinesHovered] = ImVec4(0.68, 0.68, 0.68, 1.00)
    colors[clr.PlotHistogram] = ImVec4(0.90, 0.77, 0.33, 1.00)
    colors[clr.PlotHistogramHovered] = ImVec4(0.87, 0.55, 0.08, 1.00)
    colors[clr.TextSelectedBg] = ImVec4(0.47, 0.60, 0.76, 0.47)
    colors[clr.ModalWindowDarkening] = ImVec4(0.88, 0.88, 0.88, 0.35)
end

function cmd_imgui(arg)
    main_window_state.v = not main_window_state.v
    imgui.Process = main_window_state.v or show_2_window.v
end

function imgui.OnDrawFrame()
    if not isCharInAnyCar(PLAYER_PED) then
        imgui.SetNextWindowPos(imgui.ImVec2(430, 824), imgui.Cond.FirstUseEver)
        imgui.ShowCursor = false
        imgui.SetMouseCursor(-1)
        _, id = sampGetPlayerIdByCharHandle(PLAYER_PED)
        server = sampGetCurrentServerName(PLAYER_HANDLE)
        ip = sampGetCurrentServerAddress(PLAYER_PED)
        weap = getCurrentCharWeapon(PLAYER_PED)
        weaponid = getWeapontypeModel(weap)
        ammo = getAmmoInCharWeapon(PLAYER_PED, weap)
        nick = sampGetPlayerNickname(id)
        fFps = mem.getfloat(0xB7CB50, 4, false) 
        ping = sampGetPlayerPing(id)
        time = (os.date("%H",os.time())..':'..os.date("%M",os.time())..':'..os.date("%S",os.time()))
        date = (os.date("%d",os.time())..'/'..os.date("%m",os.time())..'/'..os.date("%Y",os.time()))
        Health = getCharHealth(PLAYER_PED)
        Armor = getCharArmour(PLAYER_PED)
        Level = sampGetPlayerScore(id)
        pspeed = getCharSpeed(PLAYER_PED)
        x,y,z = getCharCoordinates(PLAYER_PED)
        Hours = (os.date("%H", os.time()))
        Minuts = (os.date("%M", os.time()))
        Seconds = (os.date("%S", os.time()))
        imgui.Begin("INFOBAR | Coded by NNC.", window, imgui.WindowFlags.NoTitleBar + imgui.WindowFlags.NoResize + imgui.WindowFlags.AlwaysAutoResize + imgui.WindowFlags.ShowBorders)
        imgui.Text("Server: " .. server, main_color)
        imgui.Text("NickName: " .. nick ..  " | ID: " .. id, main_color)
        imgui.Text("Ping: " .. ping .. " | Level: " .. Level .. " | FPS: " .. math.floor(fFps), main_color)
        imgui.Text("Time: " .. time .. " | Date: " .. date, main_color)
        imgui.Text("City: " .. city[getCityPlayerIsIn(PLAYER_HANDLE)] .. " | PlayerTime: " .. playhours .. ":" .. playmin .. ":" .. playsec, main_color)
        imgui.Text("Health: " .. Health .. " | Armour: " .. Armor .. " | Speed: " .. math.floor(pspeed), main_color)
        imgui.Text("Weapon: " .. weap.. " | Ammo: " .. ammo, main_color)
        imgui.Text("X: " .. math.floor(x) .. " | Y: " .. math.floor(y) .. " | Z: " .. math.floor(z), main_color)
        imgui.End()
    else
        imgui.SetNextWindowPos(imgui.ImVec2(430, 824), imgui.Cond.FirstUseEver)
        imgui.ShowCursor = false
        imgui.SetMouseCursor(-1)
        _, id = sampGetPlayerIdByCharHandle(PLAYER_PED)
        car = storeCarCharIsInNoSave(playerPed)
        carmodel = getCarModel(car)
        carname = getGxtText(getNameOfVehicleModel(carmodel))
        _, cid = sampGetVehicleIdByCarHandle(car)
        carhp = getCarHealth(car)
        cspeed = getCarSpeed(car)
        server = sampGetCurrentServerName(PLAYER_HANDLE)
        ip = sampGetCurrentServerAddress(PLAYER_PED)
        nick = sampGetPlayerNickname(id)
        fFps = mem.getfloat(0xB7CB50, 4, false) 
        ping = sampGetPlayerPing(id)
        time = (os.date("%H",os.time())..':'..os.date("%M",os.time())..':'..os.date("%S",os.time()))
        date = (os.date("%d",os.time())..'/'..os.date("%m",os.time())..'/'..os.date("%Y",os.time()))
        Health = getCharHealth(PLAYER_PED)
        Armor = getCharArmour(PLAYER_PED)
        Hours = (os.date("%H", os.time()))
        Minuts = (os.date("%M", os.time()))
        Seconds = (os.date("%S", os.time()))
        Level = sampGetPlayerScore(id)
        x,y,z = getCharCoordinates(PLAYER_PED)
        imgui.Begin("INFOBAR | Coded by NNC.", window, imgui.WindowFlags.NoTitleBar + imgui.WindowFlags.NoResize + imgui.WindowFlags.AlwaysAutoResize + imgui.WindowFlags.ShowBorders)
        imgui.Text("Server: " .. server, main_color)
        imgui.Text("NickName: " .. nick ..  " | ID: " .. id, main_color)
        imgui.Text("Ping: " .. ping .. " | Level: " .. Level .. " | FPS: " .. math.floor(fFps), main_color)
        imgui.Text("Time: " .. time .. " | Date: " .. date, main_color)
        imgui.Text("City: " .. city[getCityPlayerIsIn(PLAYER_HANDLE)] .. " | PlayerTime: " .. playhours .. ":" .. playmin .. ":" .. playsec, main_color)
        imgui.Text("Health: " .. Health .. " | Armour: " .. Armor .. " | Speed: " .. math.floor(cspeed * 2.5), main_color)
        imgui.Text("CarHP: " .. carhp .. " | CarID: " .. cid .. " | CarType: " .. carmodel, main_color)
        imgui.Text("X: " .. math.floor(x) .. " | Y: " .. math.floor(y) .. " | Z: " .. math.floor(z), main_color)
        imgui.End() 
    end
end
black_grey()
Что делать, если не выскакивает инфобар?
P.S Основное имгуи тоже не работает
У тебя две функции imgui.OnDrawFrame
Как у окна imgui.Begin(),полностью выключить поле заголовка?
Lua:
imgui.Begin("", window, imgui.WindowFlags.NoTitleBar)
 

wulfandr

Известный
637
260
  • Нравится
Реакции: tinkoir

enyag

Известный
345
12
напомните, как сделать запуск скрипта после спавна игрока?