Вопросы по 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
 
Последнее редактирование:

Andrinall

Известный
689
533
Я хочу в func main скачать недостающие файлы если их нет в папке
В while true do сделал команды со скачиванием
Сразу после main пишутся local imgui, local themes = ...(их и надо скачать) и в итоге скрипт сразу видит что нет файла, но не скачивает его(то есть среагировал на импорт, а не на if not doesFileExist).

lua:
local dlstatus = require('moonloader').download_status
local download1 = false
local download2 = false
local download3 = false
 
 if not doesFileExist("moonloader/resource/fonts/fontawesome-webfont.ttf") then
        sampAddChatMessage('{FF0000}[Menu]{FFFFFF}: Шрифт с иконами не был найден, началось автоматическое скачивание', -1)
        download1 = true
        end
 if not doesFileExist("moonloader/lib/faIcons.lua") then
        sampAddChatMessage('{FF0000}[Menu]{FFFFFF}: Не был найден плагин для иконок, началось автоматическое скачивание', -1)
        download2 = true
        end
 if not doesFileExist("moonloader/resource/imgui_themes.lua") then
        sampAddChatMessage('{FF0000}[Menu]{FFFFFF}: Не были найдены стили для imgui, началось автоматическое скачивание', -1)
        download3 = true
        end
 
 while true do
     wait(0)
     if download1 then
        downloadUrlToFile("https://drive.google.com/uc?export=download&confirm=no_antivirus&id=1IRMZRh1kSQoE1Dhe84WCol22wIM0_d0r", getWorkingDirectory()..'/resource/fonts/fontawesome-webfont.ttf', function(id, status)
          if status == dlstatus.STATUS_ENDDOWNLOADDATA then sampAddChatMessage('{FF0000}[Menu]{FFFFFF}: Скачивание шрифта успешно завершено.', -1) end
        end)
    end
     if download2 then
        downloadUrlToFile("https://drive.google.com/uc?export=download&confirm=no_antivirus&id=1PG7NLVa0_EJFdJMp5YIr-EqrG0Y70AG6", getWorkingDirectory()..'/lib/faIcons.lua', function(id, status)
        if status == dlstatus.STATUS_ENDDOWNLOADDATA then sampAddChatMessage('{FF0000}[Menu]{FFFFFF}: Скачивание иконок успешно завершено.', -1) end
        end)
    end       
     if download3 then
        downloadUrlToFile("https://drive.google.com/uc?export=download&confirm=no_antivirus&id=1V2BKLWjInyKuAfLhWT5uLN2v967Q2Jq2", getWorkingDirectory()..'/resource/imgui_themes.lua', function(id, status)
        if status == dlstatus.STATUS_ENDDOWNLOADDATA then sampAddChatMessage('{FF0000}[Menu]{FFFFFF}: Скачивание стилей успешно завершено.', -1) end
        end)
    end

local imgui = require "imgui"
local mem = require "memory"
local themes = import "resource/imgui_themes.lua"
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
local sw, sh = getScreenResolution()
local main_window_state = imgui.ImBool(false)
local page = page
local anim = anim
local inicfg = require 'inicfg'
local directIni = "config//ReuzMenu.ini"
local ini = inicfg.load({
        Themes = {
        theme = 1
        },
        }, directIni)
inicfg.save(ini, directIni)
local checked_radio = imgui.ImInt(ini.Themes.theme)

В одном из скриптов у меня есть авто-обновление нужных ресурсов и делается это примерно так.
Lua:
-- где-то там
local download_states = { false, false, false }
local downloads_count = 0

-- в загрузке конфигов
if not doesFileExist(map_image_path) or ( map_ver > script_resource_versions.map_image ) then
	if doesFileExist(map_image_path) then os.remove(map_image_path) end

	download_states[3] = true
	log:write("Загружается ресурс : %s", map_image_path)

	downloadUrlToFile("--link--", map_image_path, function(_, status)
		if status == 6 then
			script_resource_versions.map_image = map_ver
			download_states[3] = false
			downloads_count = downloads_count + 1
			log:write("Загрузка завершена, версия карты : %.2f", script_resource_versions.map_image)
		end
	end)
end

-- в main
repeat wait(100) until not awaitDownloads() -- функа чекающая download_states на true

if downloads_count > 0 then
	local scfile = io.open(scfg_path, 'w')
	scfile:write(encodeJson(script_resource_versions, true))
	scfile:close()

	sampAddChatMessage(scriptname .. " Необходимые ресурсы загружены. Перезагрузка ...", -1)
	thisScript():reload()
end
 
  • Нравится
Реакции: qdIbp

Andrinall

Известный
689
533
как с помощью onGivePlayerWeapon выдать оружие?
Если ты про callback из samp.Lua, то он и так вызывается при выдаче оружия сервером.
Можешь попробовать подменить модель выдаваемого оружия, но сомневаюсь что античит одобрит.
 

Dmitriy Makarov

25.05.2021
Проверенный
2,481
1,113
How do I make it so it types "/givelicense ID flying"?
and if you put the ID in there and press a button (with the script so it types on chat "/sx PlayerName (ID) at me)
Lua:
sampSendChat(string.format("/givelicense %s", ffi.string(buf))
-- /givelicense 123
sampSendChat(string.format("/sx %s %s", sampGetPlayerNickname(ffi.string(buf), ffi.string(buf))
-- /sx Nick_Name 123
 

sssilvian

Активный
230
25
Another thing, if you can help me. I can't figure out what it can come from. In other mods, the commands work properly, they don't show the message "Eroare: Comanda neconuscuta." which means in english "Error: Unknown command" recognized by the server.
Here is a video so you can understand:
(/recf is the imgui menu, /sih is the dialog)

Here is the code:
Lua:
local imgui = require 'mimgui'
local samp = require 'samp.events'
local sampev = require("lib.samp.events")
require "lib.moonloader"


local sw, sh = 400, 500
local active = imgui.new.bool(false)
local checkbox = imgui.new.bool(false)
local ffi = require "ffi"
local buf = imgui.new.char[24]()

function sampev.onSendCommand(text)
    if text:lower() == '/recf'--[[text:lower():find('/blm') or text:lower():find('/george_floyd')]] then
        active[0] = not active[0]
    end
end

imgui.OnInitialize(function()
    imgui.GetIO().IniFilename = nil
    imgui.StyleColorsDark()
end)

local mainFrame = imgui.OnFrame(function() return active[0] end, function(self)
    imgui.SetNextWindowSize(imgui.ImVec2(sw, sh), imgui.Cond.FirstUseEver)
    imgui.Begin('SFSI Helper', active)
    if imgui.BeginTabBar('Tabs') then
        if imgui.BeginTabItem('Flying') then
            imgui.Text('Licente')
        imgui.InputText("ID", buf, ffi.sizeof(buf), imgui.InputTextFlags.CharsDecimal)
if imgui.Button("Give", imgui.ImVec2(80, 30)) then
    if ffi.string(buf) ~= "" then
        sampSendChat("/givelicense "..ffi.string(buf))
    end
end
            imgui.EndTabItem()
        end
        if imgui.BeginTabItem('Sailing') then
            imgui.Text('Licente')
        imgui.SetCursorPos(imgui.ImVec2(10, 100))
    if imgui.Button('Give',imgui.ImVec2(80, 30)) then
    lua_thread.create(function()
        sampSendChat("/givelicense (do the ID here) ")
    end)
    end
            imgui.EndTabItem()
        end
        if imgui.BeginTabItem('Fishing') then
            imgui.Text('cf')
            imgui.Checkbox('Tab 3', checkbox)
            imgui.Checkbox('Tab 3##2', checkbox)
            imgui.EndTabItem()
        end
        if imgui.BeginTabItem('Weapon') then
            imgui.Text('Licente')
            imgui.Checkbox('Tab 3', checkbox)
            imgui.Checkbox('Tab 3##2', checkbox)
            imgui.EndTabItem()
        end
        if imgui.BeginTabItem('Materials') then
            imgui.Text('Materials')
           
            imgui.EndTabItem()
        end
        imgui.EndTabBar()
    end
    imgui.End()
end)

Also, how can I change the ImGui colors? I have a different script that works perfect with this preset, but doesn't work with this one.
Lua:
function apply_custom_style()
       imgui.SwitchContext()
       local style = imgui.GetStyle()
       local colors = style.Colors
       local clr = imgui.Col
       local ImVec4 = imgui.ImVec4
       local ImVec2 = imgui.ImVec2

    style.WindowPadding = ImVec2(15, 15)
    style.WindowRounding = 10.0
    style.FramePadding = ImVec2(5, 5)
    style.ItemSpacing = ImVec2(4, 6)
    style.ItemInnerSpacing = ImVec2(4, 6)
    style.IndentSpacing = 25.0
    style.ScrollbarSize = 15.0
    style.ScrollbarRounding = 15.0
    style.GrabMinSize = 7.0
    style.GrabRounding = 7.0
    style.ChildWindowRounding = 7.0
    style.FrameRounding = 6.0
 

    colors[clr.Text] = ImVec4(0.95, 0.96, 0.98, 1.00)
    colors[clr.TextDisabled] = ImVec4(0.36, 0.42, 0.47, 1.00)
    colors[clr.WindowBg] = ImVec4(0.11, 0.15, 0.17, 0.9)
    colors[clr.ChildWindowBg] = ImVec4(0.15, 0.18, 0.22, 0.0)
    colors[clr.PopupBg] = ImVec4(0.08, 0.08, 0.08, 0.94)
    colors[clr.Border] = ImVec4(0.43, 0.43, 0.50, 0.50)
    colors[clr.BorderShadow] = ImVec4(0.00, 0.00, 0.00, 0.00)
    colors[clr.FrameBg] = ImVec4(0.20, 0.25, 0.29, 0.05)
    colors[clr.FrameBgHovered] = ImVec4(0.12, 0.20, 0.28, 0.05)
    colors[clr.FrameBgActive] = ImVec4(0.09, 0.12, 0.14, 0.05)
    colors[clr.TitleBg] = ImVec4(0.09, 0.12, 0.14, 0.65)
    colors[clr.TitleBgCollapsed] = ImVec4(0.00, 0.00, 0.00, 0.51)
    colors[clr.TitleBgActive] = ImVec4(0.08, 0.10, 0.12, 1.00)
    colors[clr.MenuBarBg] = ImVec4(0.15, 0.18, 0.22, .00)
    colors[clr.ScrollbarBg] = ImVec4(0.02, 0.02, 0.02, 0.39)
    colors[clr.ScrollbarGrab] = ImVec4(0.20, 0.25, 0.29, 1.00)
    colors[clr.ScrollbarGrabHovered] = ImVec4(0.18, 0.22, 0.25, 1.00)
    colors[clr.ScrollbarGrabActive] = ImVec4(0.09, 0.21, 0.31, 1.00)
    colors[clr.ComboBg] = ImVec4(0.20, 0.25, 0.29, 1.00)
    colors[clr.CheckMark] = ImVec4(0.28, 0.56, 1.00, 1.00)
    colors[clr.SliderGrab] = ImVec4(0.28, 0.56, 1.00, 1.00)
    colors[clr.SliderGrabActive] = ImVec4(0.37, 0.61, 1.00, 1.00)
    colors[clr.Button] = ImVec4(0.20, 0.25, 0.29, 0.6)
    colors[clr.ButtonHovered] = ImVec4(0.28, 0.56, 1.00, 0.6)
    colors[clr.ButtonActive] = ImVec4(0.06, 0.53, 0.98, 0.6)
    colors[clr.Header] = ImVec4(0.20, 0.25, 0.29, 0.55)
    colors[clr.HeaderHovered] = ImVec4(0.26, 0.59, 0.98, 0.80)
    colors[clr.HeaderActive] = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.ResizeGrip] = ImVec4(0.26, 0.59, 0.98, 0.25)
    colors[clr.ResizeGripHovered] = ImVec4(0.26, 0.59, 0.98, 0.67)
    colors[clr.ResizeGripActive] = ImVec4(0.06, 0.05, 0.07, 1.00)
    colors[clr.CloseButton] = ImVec4(0.40, 0.39, 0.38, 0.16)
    colors[clr.CloseButtonHovered] = ImVec4(0.40, 0.39, 0.38, 0.39)
    colors[clr.CloseButtonActive] = ImVec4(0.40, 0.39, 0.38, 1.00)
    colors[clr.PlotLines] = ImVec4(1.61, 2.61, 0.61, 1.00)
    colors[clr.PlotLinesHovered] = ImVec4(1.00, 2.43, 0.35, 1.00)
    colors[clr.PlotHistogram] = ImVec4(0.90, 0.70, 0.00, 1.00)
    colors[clr.PlotHistogramHovered] = ImVec4(1.00, 0.60, 0.00, 1.00)
    colors[clr.TextSelectedBg] = ImVec4(0.25, 1.00, 0.00, 0.43)
    colors[clr.ModalWindowDarkening] = ImVec4(1.00, 0.98, 0.95, 0.0)
end
apply_custom_style()

Lua:
sampSendChat(string.format("/givelicense %s", ffi.string(buf))
-- /givelicense 123
sampSendChat(string.format("/sx %s %s", sampGetPlayerNickname(ffi.string(buf), ffi.string(buf))
-- /sx Nick_Name 123
Lua:
local mainFrame = imgui.OnFrame(function() return active[0] end, function(self)
    imgui.SetNextWindowSize(imgui.ImVec2(sw, sh), imgui.Cond.FirstUseEver)
    imgui.Begin('SFSI Helper', active)
    if imgui.BeginTabBar('Tabs') then
        if imgui.BeginTabItem('Flying') then
            imgui.Text('ID-ul clientului:')
        imgui.InputText("ID", buf, ffi.sizeof(buf), imgui.InputTextFlags.CharsDecimal)
                imgui.Text('Intrebi pe /sx daca clientul a fost acceptat de cineva.')
if imgui.Button("Give", imgui.ImVec2(80, 30)) then
    if ffi.string(buf) ~= "" then
    sampSendChat(string.format("/sx L-a acceptat cineva pe %s (%s) ?", sampGetPlayerNickname(ffi.string(buf), ffi.string(buf))
    end
end
[ML] (error) cvfain.lua: C:\Users\CRISTIAN\Desktop\samp clasik\moonloader\cvfain.lua:35: ')' expected (to close '(' at line 34) near 'end'
[ML] (error) cvfain.lua: Script died due to an error. (187D2164)
 
Последнее редактирование:

Dmitriy Makarov

25.05.2021
Проверенный
2,481
1,113
sampSendChat(string.format("/sx L-a acceptat cineva pe %s (%s) ?", sampGetPlayerNickname(ffi.string(buf), ffi.string(buf))
Lua:
sampSendChat(string.format("/sx L-a acceptat cineva pe %s (%s) ?", sampGetPlayerNickname(ffi.string(buf)), ffi.string(buf)))

Another thing, if you can help me. I can't figure out what it can come from. In other mods, the commands work properly, they don't show the message "Eroare: Comanda neconuscuta." which means in english "Error: Unknown command" recognized by the server.
Here is a video so you can understand:
Your command is sent to the server, because of this the server tells you that this is an unknown command:
function sampev.onSendCommand(text) if text:lower() == '/recf'--[[text:lower():find('/blm') or text:lower():find('/george_floyd')]] then active[0] = not active[0] end end
Try this.
Lua:
-- in main()
sampRegisterChatCommand("recf", function()
    active[0] = not active[0]
end)
 
Последнее редактирование:

[SA ARZ]

Известный
390
8
189034

Пытаюсь вытащить по методу /members, но увы - мб кто знает как? и мне желательно в imgui все ники вывести.
 

chapo

🫡 В армии с 17.10.2023. В ЛС НЕ ОТВЕЧАЮ
Друг
8,776
11,225
Lua:
sampSendChat(string.format("/sx L-a acceptat cineva pe %s (%s) ?", sampGetPlayerNickname(ffi.string(buf)), ffi.string(buf)))
1. можно же вместо string.format('text', var) писать сразу ('text'):format(var)
2. sampGetPlayerNickname вроде бы крашнется если передать в него строку
3. если игрока с идом нет в сети, но при этом ты юзнешь sampGetPlayerNickname, то скрипт вроде бы тоже крашнется
 
  • Нравится
Реакции: Dmitriy Makarov

sssilvian

Активный
230
25
Lua:
sampSendChat(string.format("/sx L-a acceptat cineva pe %s (%s) ?", sampGetPlayerNickname(ffi.string(buf)), ffi.string(buf)))


Your command is sent to the server, because of this the server tells you that this is an unknown command:

Try this.
Lua:
-- in main()
sampRegisterChatCommand("recf", function()
    active[0] = not active[0]
end)
Worked, all of them. Thanks
One more thing, how can I use this style configuration to edit the imGui colors? (in my code)
style config:
Lua:
function apply_custom_style()
       imgui.SwitchContext()
       local style = imgui.GetStyle()
       local colors = style.Colors
       local clr = imgui.Col
       local ImVec4 = imgui.ImVec4
       local ImVec2 = imgui.ImVec2

    style.WindowPadding = ImVec2(15, 15)
    style.WindowRounding = 10.0
    style.FramePadding = ImVec2(5, 5)
    style.ItemSpacing = ImVec2(4, 6)
    style.ItemInnerSpacing = ImVec2(4, 6)
    style.IndentSpacing = 25.0
    style.ScrollbarSize = 15.0
    style.ScrollbarRounding = 15.0
    style.GrabMinSize = 7.0
    style.GrabRounding = 7.0
    style.ChildWindowRounding = 7.0
    style.FrameRounding = 6.0
 

    colors[clr.Text] = ImVec4(0.95, 0.96, 0.98, 1.00)
    colors[clr.TextDisabled] = ImVec4(0.36, 0.42, 0.47, 1.00)
    colors[clr.WindowBg] = ImVec4(0.11, 0.15, 0.17, 0.9)
    colors[clr.ChildWindowBg] = ImVec4(0.15, 0.18, 0.22, 0.0)
    colors[clr.PopupBg] = ImVec4(0.08, 0.08, 0.08, 0.94)
    colors[clr.Border] = ImVec4(0.43, 0.43, 0.50, 0.50)
    colors[clr.BorderShadow] = ImVec4(0.00, 0.00, 0.00, 0.00)
    colors[clr.FrameBg] = ImVec4(0.20, 0.25, 0.29, 0.05)
    colors[clr.FrameBgHovered] = ImVec4(0.12, 0.20, 0.28, 0.05)
    colors[clr.FrameBgActive] = ImVec4(0.09, 0.12, 0.14, 0.05)
    colors[clr.TitleBg] = ImVec4(0.09, 0.12, 0.14, 0.65)
    colors[clr.TitleBgCollapsed] = ImVec4(0.00, 0.00, 0.00, 0.51)
    colors[clr.TitleBgActive] = ImVec4(0.08, 0.10, 0.12, 1.00)
    colors[clr.MenuBarBg] = ImVec4(0.15, 0.18, 0.22, .00)
    colors[clr.ScrollbarBg] = ImVec4(0.02, 0.02, 0.02, 0.39)
    colors[clr.ScrollbarGrab] = ImVec4(0.20, 0.25, 0.29, 1.00)
    colors[clr.ScrollbarGrabHovered] = ImVec4(0.18, 0.22, 0.25, 1.00)
    colors[clr.ScrollbarGrabActive] = ImVec4(0.09, 0.21, 0.31, 1.00)
    colors[clr.ComboBg] = ImVec4(0.20, 0.25, 0.29, 1.00)
    colors[clr.CheckMark] = ImVec4(0.28, 0.56, 1.00, 1.00)
    colors[clr.SliderGrab] = ImVec4(0.28, 0.56, 1.00, 1.00)
    colors[clr.SliderGrabActive] = ImVec4(0.37, 0.61, 1.00, 1.00)
    colors[clr.Button] = ImVec4(0.20, 0.25, 0.29, 0.6)
    colors[clr.ButtonHovered] = ImVec4(0.28, 0.56, 1.00, 0.6)
    colors[clr.ButtonActive] = ImVec4(0.06, 0.53, 0.98, 0.6)
    colors[clr.Header] = ImVec4(0.20, 0.25, 0.29, 0.55)
    colors[clr.HeaderHovered] = ImVec4(0.26, 0.59, 0.98, 0.80)
    colors[clr.HeaderActive] = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.ResizeGrip] = ImVec4(0.26, 0.59, 0.98, 0.25)
    colors[clr.ResizeGripHovered] = ImVec4(0.26, 0.59, 0.98, 0.67)
    colors[clr.ResizeGripActive] = ImVec4(0.06, 0.05, 0.07, 1.00)
    colors[clr.CloseButton] = ImVec4(0.40, 0.39, 0.38, 0.16)
    colors[clr.CloseButtonHovered] = ImVec4(0.40, 0.39, 0.38, 0.39)
    colors[clr.CloseButtonActive] = ImVec4(0.40, 0.39, 0.38, 1.00)
    colors[clr.PlotLines] = ImVec4(1.61, 2.61, 0.61, 1.00)
    colors[clr.PlotLinesHovered] = ImVec4(1.00, 2.43, 0.35, 1.00)
    colors[clr.PlotHistogram] = ImVec4(0.90, 0.70, 0.00, 1.00)
    colors[clr.PlotHistogramHovered] = ImVec4(1.00, 0.60, 0.00, 1.00)
    colors[clr.TextSelectedBg] = ImVec4(0.25, 1.00, 0.00, 0.43)
    colors[clr.ModalWindowDarkening] = ImVec4(1.00, 0.98, 0.95, 0.0)
end
apply_custom_style()
My code with the imGui menu in it:
Lua:
local imgui = require 'mimgui'
local samp = require 'samp.events'
local sampev = require("lib.samp.events")
require "lib.moonloader"


local sw, sh = 355, 425
local active = imgui.new.bool(false)
local checkbox = imgui.new.bool(false)
local ffi = require "ffi"
local buf = imgui.new.char[24]()
function main()
    wait(1000)
    sampAddChatMessage("{ff0078}[SFSI Helper]{ffffff} Loaded. Made by {ff0078}21Cristi", 0xff0078)
    sampAddChatMessage("{ff0078}[SFSI Helper]{ffffff} Scrie {ff0078}/sfsi{ffffff} pentru a deschide meniul interactiv.", 0xff0078)
    while true do
        wait(0)
    end
end
function sampev.onSendCommand(text)
sampRegisterChatCommand("sfsi", function()
        active[0] = not active[0]
    end)
end

imgui.OnInitialize(function()
    imgui.GetIO().IniFilename = nil
    imgui.StyleColorsDark()
end)

local mainFrame = imgui.OnFrame(function() return active[0] end, function(self)
    imgui.SetNextWindowSize(imgui.ImVec2(sw, sh), imgui.Cond.FirstUseEver)
    imgui.SetNextWindowPos(imgui.ImVec2(1385, 550), imgui.Cond.FirstUseEver, imgui.ImVec2(-0.3, 0.5))
    imgui.Begin('SFSI Helper', active)
    if imgui.BeginTabBar('Tabs') then
        if imgui.BeginTabItem('Flying') then
            imgui.Text('ID-ul clientului:')
        imgui.InputText("ID", buf, ffi.sizeof(buf), imgui.InputTextFlags.CharsDecimal)
                imgui.Text('Intrebi pe /sx daca clientul a fost acceptat de altcineva')
        imgui.SetCursorPos(imgui.ImVec2(10, 115))
if imgui.Button("Intreaba", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
sampSendChat(string.format("/sx L-a acceptat cineva pe %s (%s) ?", sampGetPlayerNickname(ffi.string(buf)), ffi.string(buf)))
    end
end
imgui.Text('Anunta pe /f ca ai preluat un client')
        imgui.SetCursorPos(imgui.ImVec2(10, 160))
if imgui.Button("Anunta", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
sampSendChat(string.format("/f %s (%s) la mine pentru licenta de Flying.", sampGetPlayerNickname(ffi.string(buf)), ffi.string(buf)))
    end
end

imgui.Text('Incepe lectia cu clientul')
        imgui.SetCursorPos(imgui.ImVec2(10, 205))
if imgui.Button("Startlesson", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
sampSendChat(string.format("/startlesson %s flying", sampGetPlayerNickname(ffi.string(buf))))
    end
end

imgui.Text('Instructiunile pentru test')
        imgui.SetCursorPos(imgui.ImVec2(10, 250))
if imgui.Button("Instructiuni", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
    sampSendChat("Condu Maverick-ul pe orice aeroport doresti, apoi aterizezi.")
    sampSendChat("Odata ajuns, reia zborul si intoarce-te de unde am plecat.")
    sampSendChat("Daca Maverick-ul atinge sub 950.0HP, esti picat. Poti verifica cu /dl HP-ul.")
end
end
imgui.Text('Acorda licenta clientului (in caz ca a trecut testul)')

        imgui.SetCursorPos(imgui.ImVec2(10, 295))
if imgui.Button("Acorda", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
       sampSendChat("/say Felicitari, ai trecut testul pentru licenta de Flying.")
       sampSendChat(string.format("/givelicense %s flying", sampGetPlayerNickname(ffi.string(buf))))
end
end
imgui.Text('Anunti clientul ca a picat testul de licenta')
        imgui.SetCursorPos(imgui.ImVec2(10, 340))
if imgui.Button("Picat", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
       sampSendChat("Din pacate, ai picat testul pentru licenta de Flying.")
end
end

imgui.Text('Opreste lectia cu clientul')
        imgui.SetCursorPos(imgui.ImVec2(10, 385))
if imgui.Button("Stoplesson", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
        sampSendChat("/stoplesson "..ffi.string(buf))
end
end

            imgui.EndTabItem()
        end
                if imgui.BeginTabItem('Sailing') then
            imgui.Text('ID-ul clientului:')
        imgui.InputText("ID", buf, ffi.sizeof(buf), imgui.InputTextFlags.CharsDecimal)
                imgui.Text('Intrebi pe /sx daca clientul a fost acceptat de altcineva')
        imgui.SetCursorPos(imgui.ImVec2(10, 115))
if imgui.Button("Intreaba", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
sampSendChat(string.format("/sx L-a acceptat cineva pe %s (%s) ?", sampGetPlayerNickname(ffi.string(buf)), ffi.string(buf)))
    end
end
imgui.Text('Anunta pe /f ca ai preluat un client')
        imgui.SetCursorPos(imgui.ImVec2(10, 160))
if imgui.Button("Anunta", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
sampSendChat(string.format("/f %s (%s) la mine pentru licenta de sailing.", sampGetPlayerNickname(ffi.string(buf)), ffi.string(buf)))
    end
end

imgui.Text('Incepe lectia cu clientul')
        imgui.SetCursorPos(imgui.ImVec2(10, 205))
if imgui.Button("Startlesson", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
sampSendChat(string.format("/startlesson %s sailing", sampGetPlayerNickname(ffi.string(buf))))
    end
end

imgui.Text('Ghidarile pentru test')
        imgui.SetCursorPos(imgui.ImVec2(10, 250))
if imgui.Button("Sail LS", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
    sampSendChat("Condu barca pana la farul de pe plaja. Odata ajuns, te intorci inapoi.")
    sampSendChat("Daca barca atinge sub 950.0 HP, esti picat. Poti verifica HP-ul cu comanda /dl")
end
end
        imgui.SetCursorPos(imgui.ImVec2(95, 250))
if imgui.Button("Sail LV", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
    sampSendChat("Condu barca pana la fosta baza NG (vaporul de langa Aero SF). Odata ajuns, te intorci inapoi.")
    sampSendChat("Daca barca atinge sub 950.0 HP, esti picat. Poti verifica HP-ul cu comanda /dl")
end
end
        imgui.SetCursorPos(imgui.ImVec2(180, 250))
if imgui.Button("Sail SF", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
    sampSendChat("Condu barca pana la docurile din Bayside. Odata ajuns, te intorci inapoi.")
    sampSendChat("Daca barca atinge sub 950.0 HP, esti picat. Poti verifica HP-ul cu comanda /dl")
end
end
imgui.Text('Acorda licenta clientului (in caz ca a trecut testul)')

        imgui.SetCursorPos(imgui.ImVec2(10, 295))
if imgui.Button("Acorda", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
       sampSendChat("/say Felicitari, ai trecut testul pentru licenta de Sailing.")
       sampSendChat(string.format("/givelicense %s sailing", sampGetPlayerNickname(ffi.string(buf))))
end
end
imgui.Text('Anunti clientul ca a picat testul de licenta')
        imgui.SetCursorPos(imgui.ImVec2(10, 340))
if imgui.Button("Picat", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
       sampSendChat("Din pacate, ai picat testul pentru licenta de Sailing.")
end
end

imgui.Text('Opreste lectia cu clientul')
        imgui.SetCursorPos(imgui.ImVec2(10, 385))
if imgui.Button("Stoplesson", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
        sampSendChat("/stoplesson "..ffi.string(buf))
end
end

            imgui.EndTabItem()
        end
               if imgui.BeginTabItem('Fishing') then
            imgui.Text('ID-ul clientului:')
        imgui.InputText("ID", buf, ffi.sizeof(buf), imgui.InputTextFlags.CharsDecimal)
                imgui.Text('Intrebi pe /sx daca clientul a fost acceptat de altcineva')
        imgui.SetCursorPos(imgui.ImVec2(10, 115))
if imgui.Button("Intreaba", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
sampSendChat(string.format("/sx L-a acceptat cineva pe %s (%s) ?", sampGetPlayerNickname(ffi.string(buf)), ffi.string(buf)))
    end
end
imgui.Text('Anunta pe /f ca ai preluat un client')
        imgui.SetCursorPos(imgui.ImVec2(10, 160))
if imgui.Button("Anunta", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
sampSendChat(string.format("/f %s (%s) la mine pentru licenta de Fishing.", sampGetPlayerNickname(ffi.string(buf)), ffi.string(buf)))
    end
end

imgui.Text('Incepe lectia cu clientul')
        imgui.SetCursorPos(imgui.ImVec2(10, 205))
if imgui.Button("Startlesson", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
sampSendChat(string.format("/startlesson %s fishing", sampGetPlayerNickname(ffi.string(buf))))
    end
end

imgui.Text('Setul de intrebari pentru test')
        imgui.SetCursorPos(imgui.ImVec2(10, 250))
if imgui.Button("Intrebarea 1", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
       sampSendChat("/cw Cu ce comanda pescuiesti?")
end
end
        imgui.SetCursorPos(imgui.ImVec2(95, 250))
if imgui.Button("Intrebarea 2", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
       sampSendChat("/cw Unde pescuiesti?")
end
end
        imgui.SetCursorPos(imgui.ImVec2(180, 250))
if imgui.Button("Intrebarea 3", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
       sampSendChat("/cw Unde duci pestele prins?")
end
end
        imgui.SetCursorPos(imgui.ImVec2(265, 250))
if imgui.Button("Intrebarea 4", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
       sampSendChat("/cw Ce primesti daca pescuiesti fara licenta?")
end
end
imgui.Text('Acorda licenta clientului (in caz ca a trecut testul)')

        imgui.SetCursorPos(imgui.ImVec2(10, 295))
if imgui.Button("Acorda", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
       sampSendChat("/say Felicitari, ai trecut testul pentru licenta de Fishing.")
       sampSendChat(string.format("/givelicense %s fishing", sampGetPlayerNickname(ffi.string(buf))))
end
end
imgui.Text('Anunti clientul ca a picat testul de licenta')
        imgui.SetCursorPos(imgui.ImVec2(10, 340))
if imgui.Button("Picat", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
       sampSendChat("Din pacate, ai picat testul pentru licenta de Fishing.")
end
end

imgui.Text('Opreste lectia cu clientul')
        imgui.SetCursorPos(imgui.ImVec2(10, 385))
if imgui.Button("Stoplesson", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
        sampSendChat("/stoplesson "..ffi.string(buf))
end
end

            imgui.EndTabItem()
        end
                if imgui.BeginTabItem('Weapon') then
            imgui.Text('ID-ul clientului:')
        imgui.InputText("ID", buf, ffi.sizeof(buf), imgui.InputTextFlags.CharsDecimal)
                imgui.Text('Intrebi pe /sx daca clientul a fost acceptat de altcineva')
        imgui.SetCursorPos(imgui.ImVec2(10, 115))
if imgui.Button("Intreaba", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
sampSendChat(string.format("/sx L-a acceptat cineva pe %s (%s) ?", sampGetPlayerNickname(ffi.string(buf)), ffi.string(buf)))
    end
end
imgui.Text('Anunta pe /f ca ai preluat un client')
        imgui.SetCursorPos(imgui.ImVec2(10, 160))
if imgui.Button("Anunta", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
sampSendChat(string.format("/f %s (%s) la mine pentru licenta de Weapon.", sampGetPlayerNickname(ffi.string(buf)), ffi.string(buf)))
    end
end

imgui.Text('Incepe lectia cu clientul')
        imgui.SetCursorPos(imgui.ImVec2(10, 205))
if imgui.Button("Startlesson", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
sampSendChat(string.format("/startlesson %s weapon", sampGetPlayerNickname(ffi.string(buf))))
    end
end

imgui.Text('Setul de intrebari pentru test')
        imgui.SetCursorPos(imgui.ImVec2(10, 250))
if imgui.Button("Intrebarea 1", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
       sampSendChat("/cw Enumera-mi 10 arme ilegale cu foc din GTA San Andreas.")
end
end
        imgui.SetCursorPos(imgui.ImVec2(95, 250))
if imgui.Button("Intrebarea 2", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
       sampSendChat("/cw Enumera-mi 8 safezone-uri.")
end
end
        imgui.SetCursorPos(imgui.ImVec2(180, 250))
if imgui.Button("Intrebarea 3", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
       sampSendChat("/cw Ce este interzis sa faci in aceste zone?")
end
end
        imgui.SetCursorPos(imgui.ImVec2(265, 250))
if imgui.Button("Intrebarea 4", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
       sampSendChat("/cw Cu ce comanda pescuiesti?")
end
end
imgui.Text('Acorda licenta clientului (in caz ca a trecut testul)')

        imgui.SetCursorPos(imgui.ImVec2(10, 295))
if imgui.Button("Acorda", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
       sampSendChat("/say Felicitari, ai trecut testul pentru licenta de Weapon.")
       sampSendChat(string.format("/givelicense %s weapon", sampGetPlayerNickname(ffi.string(buf))))
end
end
imgui.Text('Anunti clientul ca a picat testul de licenta')
        imgui.SetCursorPos(imgui.ImVec2(10, 340))
if imgui.Button("Picat", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
       sampSendChat("Din pacate, ai picat testul pentru licenta de Weapon.")
end
end

imgui.Text('Opreste lectia cu clientul')
        imgui.SetCursorPos(imgui.ImVec2(10, 385))
if imgui.Button("Stoplesson", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
        sampSendChat("/stoplesson "..ffi.string(buf))
end
end

            imgui.EndTabItem()
        end
                if imgui.BeginTabItem('Materials') then
            imgui.Text('ID-ul clientului:')
        imgui.InputText("ID", buf, ffi.sizeof(buf), imgui.InputTextFlags.CharsDecimal)
                imgui.Text('Intrebi pe /sx daca clientul a fost acceptat de altcineva')
        imgui.SetCursorPos(imgui.ImVec2(10, 115))
if imgui.Button("Intreaba", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
sampSendChat(string.format("/sx L-a acceptat cineva pe %s (%s) ?", sampGetPlayerNickname(ffi.string(buf)), ffi.string(buf)))
    end
end
imgui.Text('Anunta pe /f ca ai preluat un client')
        imgui.SetCursorPos(imgui.ImVec2(10, 160))
if imgui.Button("Anunta", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
sampSendChat(string.format("/f %s (%s) la mine pentru licenta de Materials.", sampGetPlayerNickname(ffi.string(buf)), ffi.string(buf)))
    end
end

imgui.Text('Incepe lectia cu clientul')
        imgui.SetCursorPos(imgui.ImVec2(10, 205))
if imgui.Button("Startlesson", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
sampSendChat(string.format("/startlesson %s materials", sampGetPlayerNickname(ffi.string(buf))))
    end
end

imgui.Text('Setul de intrebari pentru test')
        imgui.SetCursorPos(imgui.ImVec2(10, 250))
if imgui.Button("Intrebarea 1", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
       sampSendChat("/cw Cu ce comanda cumperi materiale?")
end
end
        imgui.SetCursorPos(imgui.ImVec2(95, 250))
if imgui.Button("Intrebarea 2", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
       sampSendChat("/cw Unde nu ai voie sa vinzi arme?")
end
end
        imgui.SetCursorPos(imgui.ImVec2(180, 250))
if imgui.Button("Intrebarea 3", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
       sampSendChat("/cw Enumera-mi 5 safezone-uri.")
end
end
        imgui.SetCursorPos(imgui.ImVec2(265, 250))
if imgui.Button("Intrebarea 4", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
       sampSendChat("/cw Cu ce comanda vinzi o arma?")
end
end
imgui.Text('Acorda licenta clientului (in caz ca a trecut testul)')

        imgui.SetCursorPos(imgui.ImVec2(10, 295))
if imgui.Button("Acorda", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
       sampSendChat("/say Felicitari, ai trecut testul pentru licenta de Materials.")
       sampSendChat(string.format("/givelicense %s materials", sampGetPlayerNickname(ffi.string(buf))))
end
end
imgui.Text('Anunti clientul ca a picat testul de licenta')
        imgui.SetCursorPos(imgui.ImVec2(10, 340))
if imgui.Button("Picat", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
       sampSendChat("Din pacate, ai picat testul pentru licenta de Materials.")
end
end

imgui.Text('Opreste lectia cu clientul')
        imgui.SetCursorPos(imgui.ImVec2(10, 385))
if imgui.Button("Stoplesson", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
        sampSendChat("/stoplesson "..ffi.string(buf))
end
end

            imgui.EndTabItem()
        end
        imgui.EndTabBar()
    end
    imgui.End()
end)
 

Dmitriy Makarov

25.05.2021
Проверенный
2,481
1,113
1. можно же вместо string.format('text', var) писать сразу ('text'):format(var)
1. Да, можно и так. Мне просто первый вариант нравится слегка.
2. Не подумал об этом. Но, вроде как, у него всё:
Worked, all of them. Thanks
Надеюсь и остальное тоже.
3. И это тоже. Я ему как небольшой пример дал код. С доп. проверками, надеюсь, разберётся..


One more thing, how can I use this style configuration to edit the imGui colors? (in my code)
style config:
Lua:
-- in imgui.OnInitialize
apply_custom_style()
I think it's for ImGui. Look here (https://www.blast.hk/threads/25442/) for styles for mimgui.
function sampev.onSendCommand(text) sampRegisterChatCommand("sfsi", function() active[0] = not active[0] end) end
The command registration should be in main, not here. Delete it and move it:
Lua:
sampRegisterChatCommand("sfsi", function() active[0] = not active[0] end)
to main()
 
  • Влюблен
Реакции: sssilvian

sssilvian

Активный
230
25
1. Да, можно и так. Мне просто первый вариант нравится слегка.
2. Не подумал об этом. Но, вроде как, у него всё:

Надеюсь и остальное тоже.
3. И это тоже. Я ему как небольшой пример дал код. С доп. проверками, надеюсь, разберётся..



Lua:
-- in imgui.OnInitialize
apply_custom_style()
I think it's for ImGui. Look here (https://www.blast.hk/threads/25442/) for styles for mimgui.

The command registration should be in main, not here. Delete it and move it:
Lua:
sampRegisterChatCommand("sfsi", function() active[0] = not active[0] end)
to main()
I want to use this in my ImGui code, how do I do it?
Lua:
    ImGuiStyle& style = ImGui::GetStyle();
    ImGuiIO& io = ImGui::GetIO();

    // light style from Pacôme Danhiez (user itamago) https://github.com/ocornut/imgui/pull/511#issuecomment-175719267
    style.Alpha = 1.0f;
    style.FrameRounding = 3.0f;
    style.Colors[ImGuiCol_Text] = ImVec4(1.000f, 1.000f, 1.000f, 1.000f);
    style.Colors[ImGuiCol_TextDisabled] = ImVec4(0.000f, 0.543f, 0.983f, 1.000f);
    style.Colors[ImGuiCol_WindowBg] = ImVec4(0.000f, 0.000f, 0.000f, 0.895f);
    style.Colors[ImGuiCol_ChildWindowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
    style.Colors[ImGuiCol_PopupBg] = ImVec4(0.07f, 0.07f, 0.09f, 1.00f);
    style.Colors[ImGuiCol_Border] = ImVec4(0.184f, 0.878f, 0.000f, 0.500f);
    style.Colors[ImGuiCol_BorderShadow] = ImVec4(1.00f, 1.00f, 1.00f, 0.10f);
    style.Colors[ImGuiCol_FrameBg] = ImVec4(0.160f, 0.160f, 0.160f, 0.315f);
    style.Colors[ImGuiCol_FrameBgHovered] = ImVec4(0.160f, 0.160f, 0.160f, 0.315f);
    style.Colors[ImGuiCol_FrameBgActive] = ImVec4(0.210f, 0.210f, 0.210f, 0.670f);
    style.Colors[ImGuiCol_TitleBg] = ImVec4(0.026f, 0.597f, 0.000f, 1.000f);
    style.Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.099f, 0.315f, 0.000f, 0.000f);
    style.Colors[ImGuiCol_TitleBgActive] = ImVec4(0.026f, 0.597f, 0.000f, 1.000f);
    style.Colors[ImGuiCol_MenuBarBg] = ImVec4(0.86f, 0.86f, 0.86f, 1.00f);
    style.Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.000f, 0.000f, 0.000f, 0.801f);
    style.Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.238f, 0.238f, 0.238f, 1.000f);
    style.Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.238f, 0.238f, 0.238f, 1.000f);
    style.Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.004f, 0.381f, 0.000f, 1.000f);
    //style.Colors[ImGuiCol_ComboBg] = ImVec4(0.86f, 0.86f, 0.86f, 0.99f);
    style.Colors[ImGuiCol_CheckMark] = ImVec4(0.009f, 0.845f, 0.000f, 1.000f);
    style.Colors[ImGuiCol_SliderGrab] = ImVec4(0.139f, 0.508f, 0.000f, 1.000f);
    style.Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.139f, 0.508f, 0.000f, 1.000f);
    style.Colors[ImGuiCol_Button] = ImVec4(0.000f, 0.000f, 0.000f, 0.400f);
    style.Colors[ImGuiCol_ButtonHovered] = ImVec4(0.000f, 0.619f, 0.014f, 1.000f);
    style.Colors[ImGuiCol_ButtonActive] = ImVec4(0.06f, 0.53f, 0.98f, 1.00f);
    style.Colors[ImGuiCol_Header] = ImVec4(0.26f, 0.59f, 0.98f, 0.31f);
    style.Colors[ImGuiCol_HeaderHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.80f);
    style.Colors[ImGuiCol_HeaderActive] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
    style.Colors[ImGuiCol_Column] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f);
    style.Colors[ImGuiCol_ColumnHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.78f);
    style.Colors[ImGuiCol_ColumnActive] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
    style.Colors[ImGuiCol_ResizeGrip] = ImVec4(0.000f, 1.000f, 0.221f, 0.597f);
    style.Colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.67f);
    style.Colors[ImGuiCol_ResizeGripActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.95f);
    //style.Colors[ImGuiCol_CloseButton] = ImVec4(0.59f, 0.59f, 0.59f, 0.50f);
    //style.Colors[ImGuiCol_CloseButtonHovered] = ImVec4(0.98f, 0.39f, 0.36f, 1.00f);
    //style.Colors[ImGuiCol_CloseButtonActive] = ImVec4(0.98f, 0.39f, 0.36f, 1.00f);
    style.Colors[ImGuiCol_PlotLines] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f);
    style.Colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.43f, 0.35f, 1.00f);
    style.Colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
    style.Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f);
    style.Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.26f, 0.59f, 0.98f, 0.35f);
    style.Colors[ImGuiCol_ModalWindowDarkening] = ImVec4(0.20f, 0.20f, 0.20f, 0.35f);

    style.ItemSpacing = ImVec2(10, 8); //ItemSpacing(ImVec2(7.f));
    style.FramePadding = ImVec2(6, 4); //ItemSpacing(ImVec2(7.f));
    style.ItemInnerSpacing = ImVec2(5, 4); //ItemSpacing(ImVec2(7.f));

    style.ScrollbarSize = 16.f; //ItemSpacing(ImVec2(7.f));
    style.GrabMinSize = 8.f; //ItemSpacing(ImVec2(7.f));
    style.WindowBorderSize = 1.f; //ItemSpacing(ImVec2(7.f));
    style.FrameBorderSize = 1.f; //ItemSpacing(ImVec2(7.f));
    style.WindowRounding = 0.f; //ItemSpacing(ImVec2(7.f));
    style.FrameRounding = 1.f; //ItemSpacing(ImVec2(7.f));

    style.AntiAliasedLines = true;
    style.AntiAliasedFill = true;
I also updated my script with what you said, this is the result (it works, but the only thing left I need is the theme to work):
C++:
local imgui = require 'mimgui'
local samp = require 'samp.events'
local sampev = require("lib.samp.events")
require "lib.moonloader"


local sw, sh = 355, 425
local active = imgui.new.bool(false)
local checkbox = imgui.new.bool(false)
local ffi = require "ffi"
local buf = imgui.new.char[24]()
function main()
    wait(1000)
    sampRegisterChatCommand("sfsi", function() active[0] = not active[0] end)
    sampAddChatMessage("{ff0078}[SFSI Helper]{ffffff} Loaded. Made by {ff0078}21Cristi", 0xff0078)
    sampAddChatMessage("{ff0078}[SFSI Helper]{ffffff} Scrie {ff0078}/sfsi{ffffff} pentru a deschide meniul interactiv.", 0xff0078)
    while true do
        wait(0)
    end
end

imgui.OnInitialize(function()
    imgui.GetIO().IniFilename = nil
    imgui.StyleColorsDark()
end)

local mainFrame = imgui.OnFrame(function() return active[0] end, function(self)
local sw, sh = getScreenResolution()
    imgui.SetNextWindowSize(imgui.ImVec2(sw / 5.4, sh / 2.5), imgui.Cond.FirstUseEver)
    imgui.SetNextWindowPos(imgui.ImVec2(sw / 1.6, sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(-0.3, 0.5))
    imgui.Begin('SFSI Helper', active)
    if imgui.BeginTabBar('Tabs') then
        if imgui.BeginTabItem('Flying') then
            imgui.Text('ID-ul clientului (conectat pe server):')
        imgui.InputText("ID", buf, ffi.sizeof(buf), imgui.InputTextFlags.CharsDecimal)
                imgui.Text('Intrebi pe /sx daca clientul a fost acceptat de altcineva')
        imgui.SetCursorPos(imgui.ImVec2(10, 115))
if imgui.Button("Intreaba", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
sampSendChat(string.format("/sx L-a acceptat cineva pe %s (%s) ?", sampGetPlayerNickname(ffi.string(buf)), ffi.string(buf)))
    end
end
imgui.Text('Anunta pe /f ca ai preluat un client')
        imgui.SetCursorPos(imgui.ImVec2(10, 160))
if imgui.Button("Anunta", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
sampSendChat(string.format("/f %s (%s) la mine pentru licenta de Flying.", sampGetPlayerNickname(ffi.string(buf)), ffi.string(buf)))
    end
end

imgui.Text('Incepe lectia cu clientul')
        imgui.SetCursorPos(imgui.ImVec2(10, 205))
if imgui.Button("Startlesson", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
sampSendChat(string.format("/startlesson %s flying", sampGetPlayerNickname(ffi.string(buf))))
    end
end

imgui.Text('Instructiunile pentru test')
        imgui.SetCursorPos(imgui.ImVec2(10, 250))
if imgui.Button("Instructiuni", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
    sampSendChat("Condu Maverick-ul pe orice aeroport doresti, apoi aterizezi.")
    sampSendChat("Odata ajuns, reia zborul si intoarce-te de unde am plecat.")
    sampSendChat("Daca Maverick-ul atinge sub 950.0HP, esti picat. Poti verifica cu /dl HP-ul.")
end
end
imgui.Text('Acorda licenta clientului (in caz ca a trecut testul)')

        imgui.SetCursorPos(imgui.ImVec2(10, 295))
if imgui.Button("Acorda", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
       sampSendChat("/say Felicitari, ai trecut testul pentru licenta de Flying.")
       sampSendChat(string.format("/givelicense %s flying", sampGetPlayerNickname(ffi.string(buf))))
end
end
imgui.Text('Anunti clientul ca a picat testul de licenta')
        imgui.SetCursorPos(imgui.ImVec2(10, 340))
if imgui.Button("Picat", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
       sampSendChat("Din pacate, ai picat testul pentru licenta de Flying.")
end
end

imgui.Text('Opreste lectia cu clientul')
        imgui.SetCursorPos(imgui.ImVec2(10, 385))
if imgui.Button("Stoplesson", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
        sampSendChat("/stoplesson "..ffi.string(buf))
end
end

            imgui.EndTabItem()
        end
                if imgui.BeginTabItem('Sailing') then
            imgui.Text('ID-ul clientului (conectat pe server):')
        imgui.InputText("ID", buf, ffi.sizeof(buf), imgui.InputTextFlags.CharsDecimal)
                imgui.Text('Intrebi pe /sx daca clientul a fost acceptat de altcineva')
        imgui.SetCursorPos(imgui.ImVec2(10, 115))
if imgui.Button("Intreaba", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
sampSendChat(string.format("/sx L-a acceptat cineva pe %s (%s) ?", sampGetPlayerNickname(ffi.string(buf)), ffi.string(buf)))
    end
end
imgui.Text('Anunta pe /f ca ai preluat un client')
        imgui.SetCursorPos(imgui.ImVec2(10, 160))
if imgui.Button("Anunta", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
sampSendChat(string.format("/f %s (%s) la mine pentru licenta de sailing.", sampGetPlayerNickname(ffi.string(buf)), ffi.string(buf)))
    end
end

imgui.Text('Incepe lectia cu clientul')
        imgui.SetCursorPos(imgui.ImVec2(10, 205))
if imgui.Button("Startlesson", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
sampSendChat(string.format("/startlesson %s sailing", sampGetPlayerNickname(ffi.string(buf))))
    end
end

imgui.Text('Ghidarile pentru test')
        imgui.SetCursorPos(imgui.ImVec2(10, 250))
if imgui.Button("Sail LS", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
    sampSendChat("Condu barca pana la farul de pe plaja. Odata ajuns, te intorci inapoi.")
    sampSendChat("Daca barca atinge sub 950.0 HP, esti picat. Poti verifica HP-ul cu comanda /dl")
end
end
        imgui.SetCursorPos(imgui.ImVec2(95, 250))
if imgui.Button("Sail LV", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
    sampSendChat("Condu barca pana la fosta baza NG (vaporul de langa Aero SF). Odata ajuns, te intorci inapoi.")
    sampSendChat("Daca barca atinge sub 950.0 HP, esti picat. Poti verifica HP-ul cu comanda /dl")
end
end
        imgui.SetCursorPos(imgui.ImVec2(180, 250))
if imgui.Button("Sail SF", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
    sampSendChat("Condu barca pana la docurile din Bayside. Odata ajuns, te intorci inapoi.")
    sampSendChat("Daca barca atinge sub 950.0 HP, esti picat. Poti verifica HP-ul cu comanda /dl")
end
end
imgui.Text('Acorda licenta clientului (in caz ca a trecut testul)')

        imgui.SetCursorPos(imgui.ImVec2(10, 295))
if imgui.Button("Acorda", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
       sampSendChat("/say Felicitari, ai trecut testul pentru licenta de Sailing.")
       sampSendChat(string.format("/givelicense %s sailing", sampGetPlayerNickname(ffi.string(buf))))
end
end
imgui.Text('Anunti clientul ca a picat testul de licenta')
        imgui.SetCursorPos(imgui.ImVec2(10, 340))
if imgui.Button("Picat", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
       sampSendChat("Din pacate, ai picat testul pentru licenta de Sailing.")
end
end

imgui.Text('Opreste lectia cu clientul')
        imgui.SetCursorPos(imgui.ImVec2(10, 385))
if imgui.Button("Stoplesson", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
        sampSendChat("/stoplesson "..ffi.string(buf))
end
end

            imgui.EndTabItem()
        end
               if imgui.BeginTabItem('Fishing') then
            imgui.Text('ID-ul clientului (conectat pe server):')
        imgui.InputText("ID", buf, ffi.sizeof(buf), imgui.InputTextFlags.CharsDecimal)
                imgui.Text('Intrebi pe /sx daca clientul a fost acceptat de altcineva')
        imgui.SetCursorPos(imgui.ImVec2(10, 115))
if imgui.Button("Intreaba", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
sampSendChat(string.format("/sx L-a acceptat cineva pe %s (%s) ?", sampGetPlayerNickname(ffi.string(buf)), ffi.string(buf)))
    end
end
imgui.Text('Anunta pe /f ca ai preluat un client')
        imgui.SetCursorPos(imgui.ImVec2(10, 160))
if imgui.Button("Anunta", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
sampSendChat(string.format("/f %s (%s) la mine pentru licenta de Fishing.", sampGetPlayerNickname(ffi.string(buf)), ffi.string(buf)))
    end
end

imgui.Text('Incepe lectia cu clientul')
        imgui.SetCursorPos(imgui.ImVec2(10, 205))
if imgui.Button("Startlesson", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
sampSendChat(string.format("/startlesson %s fishing", sampGetPlayerNickname(ffi.string(buf))))
    end
end

imgui.Text('Setul de intrebari pentru test')
        imgui.SetCursorPos(imgui.ImVec2(10, 250))
if imgui.Button("Intrebarea 1", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
       sampSendChat("/cw Cu ce comanda pescuiesti?")
end
end
        imgui.SetCursorPos(imgui.ImVec2(95, 250))
if imgui.Button("Intrebarea 2", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
       sampSendChat("/cw Unde pescuiesti?")
end
end
        imgui.SetCursorPos(imgui.ImVec2(180, 250))
if imgui.Button("Intrebarea 3", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
       sampSendChat("/cw Unde duci pestele prins?")
end
end
        imgui.SetCursorPos(imgui.ImVec2(265, 250))
if imgui.Button("Intrebarea 4", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
       sampSendChat("/cw Ce primesti daca pescuiesti fara licenta?")
end
end
imgui.Text('Acorda licenta clientului (in caz ca a trecut testul)')

        imgui.SetCursorPos(imgui.ImVec2(10, 295))
if imgui.Button("Acorda", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
       sampSendChat("/say Felicitari, ai trecut testul pentru licenta de Fishing.")
       sampSendChat(string.format("/givelicense %s fishing", sampGetPlayerNickname(ffi.string(buf))))
end
end
imgui.Text('Anunti clientul ca a picat testul de licenta')
        imgui.SetCursorPos(imgui.ImVec2(10, 340))
if imgui.Button("Picat", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
       sampSendChat("Din pacate, ai picat testul pentru licenta de Fishing.")
end
end

imgui.Text('Opreste lectia cu clientul')
        imgui.SetCursorPos(imgui.ImVec2(10, 385))
if imgui.Button("Stoplesson", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
        sampSendChat("/stoplesson "..ffi.string(buf))
end
end

            imgui.EndTabItem()
        end
                if imgui.BeginTabItem('Weapon') then
            imgui.Text('ID-ul clientului (conectat pe server):')
        imgui.InputText("ID", buf, ffi.sizeof(buf), imgui.InputTextFlags.CharsDecimal)
                imgui.Text('Intrebi pe /sx daca clientul a fost acceptat de altcineva')
        imgui.SetCursorPos(imgui.ImVec2(10, 115))
if imgui.Button("Intreaba", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
sampSendChat(string.format("/sx L-a acceptat cineva pe %s (%s) ?", sampGetPlayerNickname(ffi.string(buf)), ffi.string(buf)))
    end
end
imgui.Text('Anunta pe /f ca ai preluat un client')
        imgui.SetCursorPos(imgui.ImVec2(10, 160))
if imgui.Button("Anunta", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
sampSendChat(string.format("/f %s (%s) la mine pentru licenta de Weapon.", sampGetPlayerNickname(ffi.string(buf)), ffi.string(buf)))
    end
end

imgui.Text('Incepe lectia cu clientul')
        imgui.SetCursorPos(imgui.ImVec2(10, 205))
if imgui.Button("Startlesson", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
sampSendChat(string.format("/startlesson %s weapon", sampGetPlayerNickname(ffi.string(buf))))
    end
end

imgui.Text('Setul de intrebari pentru test')
        imgui.SetCursorPos(imgui.ImVec2(10, 250))
if imgui.Button("Intrebarea 1", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
       sampSendChat("/cw Enumera-mi 10 arme ilegale cu foc din GTA San Andreas.")
end
end
        imgui.SetCursorPos(imgui.ImVec2(95, 250))
if imgui.Button("Intrebarea 2", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
       sampSendChat("/cw Enumera-mi 8 safezone-uri.")
end
end
        imgui.SetCursorPos(imgui.ImVec2(180, 250))
if imgui.Button("Intrebarea 3", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
       sampSendChat("/cw Ce este interzis sa faci in aceste zone?")
end
end
        imgui.SetCursorPos(imgui.ImVec2(265, 250))
if imgui.Button("Intrebarea 4", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
       sampSendChat("/cw Cu ce comanda pescuiesti?")
end
end
imgui.Text('Acorda licenta clientului (in caz ca a trecut testul)')

        imgui.SetCursorPos(imgui.ImVec2(10, 295))
if imgui.Button("Acorda", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
       sampSendChat("/say Felicitari, ai trecut testul pentru licenta de Weapon.")
       sampSendChat(string.format("/givelicense %s weapon", sampGetPlayerNickname(ffi.string(buf))))
end
end
imgui.Text('Anunti clientul ca a picat testul de licenta')
        imgui.SetCursorPos(imgui.ImVec2(10, 340))
if imgui.Button("Picat", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
       sampSendChat("Din pacate, ai picat testul pentru licenta de Weapon.")
end
end

imgui.Text('Opreste lectia cu clientul')
        imgui.SetCursorPos(imgui.ImVec2(10, 385))
if imgui.Button("Stoplesson", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
        sampSendChat("/stoplesson "..ffi.string(buf))
end
end

            imgui.EndTabItem()
        end
                if imgui.BeginTabItem('Materials') then
            imgui.Text('ID-ul clientului (conectat pe server):')
        imgui.InputText("ID", buf, ffi.sizeof(buf), imgui.InputTextFlags.CharsDecimal)
                imgui.Text('Intrebi pe /sx daca clientul a fost acceptat de altcineva')
        imgui.SetCursorPos(imgui.ImVec2(10, 115))
if imgui.Button("Intreaba", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
sampSendChat(string.format("/sx L-a acceptat cineva pe %s (%s) ?", sampGetPlayerNickname(ffi.string(buf)), ffi.string(buf)))
    end
end
imgui.Text('Anunta pe /f ca ai preluat un client')
        imgui.SetCursorPos(imgui.ImVec2(10, 160))
if imgui.Button("Anunta", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
sampSendChat(string.format("/f %s (%s) la mine pentru licenta de Materials.", sampGetPlayerNickname(ffi.string(buf)), ffi.string(buf)))
    end
end

imgui.Text('Incepe lectia cu clientul')
        imgui.SetCursorPos(imgui.ImVec2(10, 205))
if imgui.Button("Startlesson", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
sampSendChat(string.format("/startlesson %s materials", sampGetPlayerNickname(ffi.string(buf))))
    end
end

imgui.Text('Setul de intrebari pentru test')
        imgui.SetCursorPos(imgui.ImVec2(10, 250))
if imgui.Button("Intrebarea 1", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
       sampSendChat("/cw Cu ce comanda cumperi materiale?")
end
end
        imgui.SetCursorPos(imgui.ImVec2(95, 250))
if imgui.Button("Intrebarea 2", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
       sampSendChat("/cw Unde nu ai voie sa vinzi arme?")
end
end
        imgui.SetCursorPos(imgui.ImVec2(180, 250))
if imgui.Button("Intrebarea 3", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
       sampSendChat("/cw Enumera-mi 5 safezone-uri.")
end
end
        imgui.SetCursorPos(imgui.ImVec2(265, 250))
if imgui.Button("Intrebarea 4", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
       sampSendChat("/cw Cu ce comanda vinzi o arma?")
end
end
imgui.Text('Acorda licenta clientului (in caz ca a trecut testul)')

        imgui.SetCursorPos(imgui.ImVec2(10, 295))
if imgui.Button("Acorda", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
       sampSendChat("/say Felicitari, ai trecut testul pentru licenta de Materials.")
       sampSendChat(string.format("/givelicense %s materials", sampGetPlayerNickname(ffi.string(buf))))
end
end
imgui.Text('Anunti clientul ca a picat testul de licenta')
        imgui.SetCursorPos(imgui.ImVec2(10, 340))
if imgui.Button("Picat", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
       sampSendChat("Din pacate, ai picat testul pentru licenta de Materials.")
end
end

imgui.Text('Opreste lectia cu clientul')
        imgui.SetCursorPos(imgui.ImVec2(10, 385))
if imgui.Button("Stoplesson", imgui.ImVec2(80, 20)) then
    if ffi.string(buf) ~= "" then
        sampSendChat("/stoplesson "..ffi.string(buf))
end
end

            imgui.EndTabItem()
        end
        imgui.EndTabBar()
    end
    imgui.End()
end)
 

Less_Go

Новичок
12
1
Хай. Можете помочь сделать скрипт, который будет отправлять команды после того, когда в чате найдет текст "объявление". У работает, если я сам пишу "объявление" в чат. А если просто в чате, ничего не происходит. Вот код

Код:
local sampev = require 'lib.samp.events'
local activation = false


function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand("adlvnews", cmd)
end
function sampev.onServerMessage(color, text)
    if activation then
        if text:find("Объявление") then
            lua_thread.create(function()
                sampSendChat("/flood 2")
                wait(1000)
                sampSendChat("/ad LVn - Свободная строка объявлений - 103.3 FM")
                wait(2000)
                sampSendChat("/flood /adsend 0")
            end)
        end
    end
end
function sampev.onShowDialog(id, style, title, button1, button2, text)
    if activation then
        if title:find("Подтверждение") then
            sampSendDialogResponse(id, 1, 0, _)
            return false
        end
    end
end
function cmd()
    if activation then
        activation = false
        printStringNow("AdLvNews - OFF", 3000)
    else
        activation = true
        printStringNow("AdLvNews - ON", 3000)
    end
end