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

abnomegd

Активный
335
35
Почему не работает, некоторые функции в диалоге /dialog 5
script:
require "lib.moonloader"
local color_dialog = 0xDEB887

-- Для диалога с ID 12
local dialogArr = {"История ников", "Добавить в записную книгу", "Показать документы", "Действия", "Имущество"};
local dialogStr = ""

for _, str in ipairs(dialogArr) do
    dialogStr = dialogStr .. str .. "\n"
end

-- Для диалога с ID 13
local dialogArra = {"Паспорт", "Лицензии", "Медкарта", "МедДиплом", "Выписка из тира", "Трудовая книга", "Военный билет", "Повестка в армию", "Отчёт о работе"}
local dialogStra = ""

for _, stra in ipairs(dialogArra) do
    dialogStra = dialogStra .. stra .. "\n"
end

-- Для диалога с ID 14
local dialogArras = {"Дать денег", "Передать металл / патроны / наркотики / маски / аптечки", "Подарить цветы", "Жениться", "Предложить побег", "Поселить к себе", "Дать ключи от авто"};
local dialogStras = ""

for _, stras in ipairs(dialogArras) do
    dialogStras = dialogStras .. stras .. "\n"
end

-- Для диалога с ID 15
local dialogArrasa = {"Продать машину", "Продать дом", "Продать бизнес", "Обмен авто", "Обмен домами", "Обмен бизнесами"};
local dialogStrasa = ""

for _, strasa in ipairs(dialogArrasa) do
    dialogStrasa = dialogStrasa .. strasa .. "\n"
end

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
    sampRegisterChatCommand("dialog", cmd_dialog)
    sampAddChatMessage("[HelperARP]: {FFFFFF}Скрипт загружен!", 0x5CBCFF)

    while true do
        wait(0)

        local valid, ped = getCharPlayerIsTargeting(PLAYER_HANDLE)
        if valid and doesCharExist(ped) then
            local result, id = sampGetPlayerIdByCharHandle(ped)
            if result and isKeyJustPressed(VK_X) then
                playerid = id
                cmd_dialog(2)
            end
        end

        local result, button, list, input = sampHasDialogRespond(11)
        if result then
            if button == 1 then
                if list == 0 then
                    sampSendChat("/pay "..tostring(playerid)..' '..input)
                end
            end
        end

        local result, button, list, input = sampHasDialogRespond(12)
        if result then
            if button == 1 then
                if list == 0 then -- "История ников"
                    sampSendChat("/history "..sampGetPlayerNickname(tonumber(playerid)))
                elseif list == 1 then -- "Добавить в записную книгу"
                    sampSendChat("/add "..tostring(playerid))
                elseif list == 2 then -- "Показать документы"
                    cmd_dialog(3)
                elseif list == 3 then -- "Действия"
                    cmd_dialog(4)
                elseif list == 4 then -- "Имущество"
                    cmd_dialog(5)
                end
            end
        end

        local result, button, list, input = sampHasDialogRespond(13)
        if result then
            if button == 1 then
                if list == 0 then -- Паспорт
                    lua_thread.create(function()
                        sampSendChat("/do Папка с документами в руке.")
                        wait(1000)
                        sampSendChat("/me достает из папки паспорт")
                        wait(1000)
                        sampSendChat("/pass "..tostring(playerid))
                    end)
                elseif list == 1 then -- Лицензии
                    lua_thread.create(function()
                        sampSendChat("/do Папка с документами в руке.")
                        wait(1000)
                        sampSendChat("/me достает из папки лицензии")
                        wait(1000)
                        sampSendChat("/lic "..tostring(playerid))
                    end)
                elseif list == 2 then -- Медкарта
                    lua_thread.create(function()
                        sampSendChat("/do Папка с документами в руке.")
                        wait(1000)
                        sampSendChat("/me достает из папки медицинскую карту")
                        wait(1000)
                        sampSendChat("/me показывает медицинскую карту человеку напротив")
                        wait(1000)
                        sampSendChat("/med "..tostring(playerid))
                    end)
                elseif list == 3 then -- МедДиплом
                    lua_thread.create(function()
                        sampSendChat("/do Папка с документами в руке.")
                        wait(1000)
                        sampSendChat("/me достает из папки медицинский диплом")
                        wait(1000)
                        sampSendChat("/me показывает медицинский диплом человеку напротив")
                    end)
                elseif list == 4 then -- Выписка из тира
                    lua_thread.create(function()
                        sampSendChat("/do Папка с документами в руке.")
                        wait(1000)
                        sampSendChat("/me достает из папки выписку из тира")
                        wait(1000)
                        sampSendChat("/skill "..tostring(playerid))
                    end)
                elseif list == 5 then -- Трудовая книга
                    lua_thread.create(function()
                        sampSendChat("/do Папка с документами в руке.")
                        wait(1000)
                        sampSendChat("/me достает из папки трудовую книгу")
                        wait(1000)
                        sampSendChat("/wbook "..tostring(playerid))
                    end)
                elseif list == 6 then -- Военный билет
                    lua_thread.create(function()
                        sampSendChat("/do Папка с документами в руке.")
                        wait(1000)
                        sampSendChat("/me достает из папки военный билет")
                        wait(1000)
                        sampSendChat("/me показывает военный билет человеку напротив")
                    end)
                elseif list == 7 then -- Повестка в армию
                    lua_thread.create(function()
                        sampSendChat("/do Папка с документами в руке.")
                        wait(1000)
                        sampSendChat("/me достает из папки повестку")
                        wait(1000)
                        sampSendChat("/me показывает повестку в армию человеку напротив")
                    end)
                elseif list == 8 then -- Отчёт о работе
                    lua_thread.create(function()
                        sampSendChat("/do Папка с документами в руке.")
                        wait(1000)
                        sampSendChat("/me достает из папки отчёт о выполненой работе")
                        wait(1000)
                        sampSendChat("/team "..tostring(playerid))
                    end)
                end
            else
            end
        end

        local result, button, list, input = sampHasDialogRespond(14)
        if result then
            if button == 1 then
                if list == 0 then -- Дать денег
                    cmd_dialog(1)
                elseif list == 1 then -- Передать
                    sampSendChat("/give "..tostring(playerid))
                elseif list == 2 then -- Подарить цветы
                    lua_thread.create(function()
                        sampSendChat("В знак моего внимания к Вам,")
                        wait(1000)
                        sampSendChat("Прошу принять этот подарок")
                        wait(1000)
                        sampSendChat("/do Букет цветов в руках.")
                        wait(1000)
                        sampSendChat("/me передает букет в руки")
                        wait(1000)
                        sampSendChat("/present "..tostring(playerid))
                    end)
                elseif list == 3 then -- Жениться на
                    sampSendChat("/wedding "..tostring(playerid))
                elseif list == 4 then -- Предложить побег
                    sampSendChat("/jailbreak "..tostring(playerid))
                elseif list == 5 then -- Поселить к себе
                    sampSendChat("/live "..tostring(playerid))
                elseif list == 6 then -- Дать ключи от авто
                    sampSendChat("/allow "..tostring(playerid))
                end
            else
            end
        end

        local result, button, list, input = sampHasDialogRespond(15)
        if result then
            if button == 1 then
                if list == 0 then -- Продать авто
                    cmd_dialog(6)
                elseif list == 1 then -- Передать дом
                    cmd_dialog(7)
                elseif list == 2 then -- Подарить бизнес
                    cmd_dialog(8)
                elseif list == 3 then -- Обмен авто
                    cmd_dialog(9)
                elseif list == 4 then -- Обмен домами
                    cmd_dialog(10)
                elseif list == 5 then -- Обмен бизнесами
                    cmd_dialog(11)
                end
            else
            end
        end

        local result, button, list, input = sampHasDialogRespond(16)
        if result then
            if button == 1 then
                if list == 0 then
                    sampSendChat("/sellmycar "..tostring(playerid).." "..input)
                end
            end
        end

        local result, button, list, input = sampHasDialogRespond(17)
        if result then
            if button == 1 then
                if list == 0 then
                    sampSendChat("/sellmyhome "..tostring(playerid).." "..input)
                end
            end
        end

        local result, button, list, input = sampHasDialogRespond(18)
        if result then
            if button == 1 then
                if list == 0 then
                    sampSendChat("/sellmybiz "..tostring(playerid).." "..input)
                end
            end
        end

        local result, button, list, input = sampHasDialogRespond(19)
        if result then
            if button == 1 then
                if list == 0 then
                    sampSendChat("/changecar "..tostring(playerid).." "..input)
                end
            end
        end

        local result, button, list, input = sampHasDialogRespond(20)
        if result then
            if button == 1 then
                if list == 0 then
                    sampSendChat("/changehome "..tostring(playerid).." "..input)
                end
            end
        end

        local result, button, list, input = sampHasDialogRespond(21)
        if result then
            if button == 1 then
                if list == 0 then
                    sampSendChat("/changebiz "..tostring(playerid).." "..input)
                end
            end
        end
    end
end

function cmd_dialog(arg)
    if tonumber(arg) == 1 then
        sampShowDialog(11, "{00ff00}Дать денег", "", "Дать", "Не дать", 1)
    elseif tonumber(arg) == 2 then
        sampShowDialog(12, "{00ff00}Меню взаимодействия с игроком", dialogStr, "Выбрать", "Закрыть", 2)
    elseif tonumber(arg) == 3 then
        sampShowDialog(13, "{00ff00}Показать документы", dialogStra, "Выбрать", "Закрыть", 2)
    elseif tonumber(arg) == 4 then
        sampShowDialog(14, "{00ff00}Действия", dialogStras, "Выбрать", "Закрыть", 2)
    elseif tonumber(arg) == 5 then
        sampShowDialog(15, "{00ff00}Имущество", dialogStrasa, "Выбрать", "Закрыть", 2)
    elseif tonumber(arg) == 6 then
        sampShowDialog(16, "{00ff00}Продать авто", "Введите цену машины.", "Выбрать", "Закрыть", 1)  
    elseif tonumber(arg) == 7 then
        sampShowDialog(17, "{00ff00}Продать дом", "Введите цену дома.", "Выбрать", "Закрыть", 1)  
    elseif tonumber(arg) == 8 then
        sampShowDialog(18, "{00ff00}Продать бизнес", "Введите цену бизнеса.", "Выбрать", "Закрыть", 1)
    elseif tonumber(arg) == 9 then
        sampShowDialog(19, "{00ff00}Обмен авто", "Введите столько сколько должен доплатить человек напротив.", "Выбрать", "Закрыть", 1)    
    elseif tonumber(arg) == 10 then
        sampShowDialog(20, "{00ff00}Обмен домами", "Введите столько сколько должен доплатить человек напротив.", "Выбрать", "Закрыть", 1)
    elseif tonumber(arg) == 11 then
        sampShowDialog(21, "{00ff00}Обмен бизнесами", "Введите столько сколько должен доплатить человек напротив.", "Выбрать", "Закрыть", 1)
    end
end
up
 

Fluffy1560

Активный
276
34
Как используется defCallDelete(defCallId)? Тип как мне удалить дефкал или узнать его ид?
Еба, я узнал это своим сном!
Если прописать в defCallAdd(time, repeat, function() id = 1) а потом написать defCallDelete(1) он отключиться!
Распростроните а то нигде эт не найти
 

wulfandr

Известный
637
260
Еба, я узнал это своим сном!
Если прописать в defCallAdd(time, repeat, function() id = 1) а потом написать defCallDelete(1) он отключиться!
Распростроните а то нигде эт не найти
пророчество это хорошо, а лучше добавить где нибудь эту инфу , а то трудно будет найти https://www.blast.hk/threads/53145/
 

Sanchez.

Известный
704
187
Пример:
Lua:
local theme = imgui.ImInt(mainIni.config.thene)

--main()
while true do
   wait(0)
   if mainIni.config.theme == 1 and переменная окна.v then blue() end
   if mainIni.config.theme == 2 and переменная окна.v then red() end
end


--onDrawFrame
if imgui.Button(u8"Синяя тема") then mainIni.config.theme = 1 end
if imgui.Button(u8"Красная тема") then mainIni.config.theme = 2 end
inicfg.save(mainIni, directIni)

--themes
function blue()
--тип тут тема
end
function red()
--тип тут тоже тема
end
 
  • Нравится
Реакции: barjik

paulohardy

вы еще постите говно? тогда я иду к вам
Всефорумный модератор
1,891
1,254
Еба, я узнал это своим сном!
Если прописать в defCallAdd(time, repeat, function() id = 1) а потом написать defCallDelete(1) он отключиться!
Распростроните а то нигде эт не найти
А если два потока будет? defCallDelete(2)?
Для этого defCallAdd возвращает указатель на поток

Lua:
defCall = defCallAdd(1000, true, function()
    printLog('defCall repeated')
end)

defCallDelete(defCall)
 

chapo

🫡 В армии с 17.10.2023. В ЛС НЕ ОТВЕЧАЮ
Друг
8,771
11,214
как без говнокода сравнить 2 массива и добавить в первый недостающий элемент из второго?
например:
Lua:
local arr1 = {
    {
        {'привет', 1, 2, 3, 4},
    },
    {
        {'пока', 5, 6, 7, 8},
    },
}

local arr2 = {
    {
        {'привет', 1, 2, 3, 4},
        {'пошел нахуй', 9, 10, 11, 12},
    },
    {
        {'пока', 5, 6, 7, 8},
        {'еблан', 13, 14, 15, 16},
    },
}
в таком случае мне надо добавить недостающие элементы из массива arr2 в arr1 ("пока" и "еблан")
 

chapo

🫡 В армии с 17.10.2023. В ЛС НЕ ОТВЕЧАЮ
Друг
8,771
11,214
Как нарисовать линию к какому либо пикапу зная его айди? Тип как рендер
Lua:
local myX, myY, myZ = getCharCoordinates(PLAYER_PED) -- получаешь свои коорды
local x, y, z = getPickupCoordinates(Pickup pickup) -- получаешь коорды пикапа

local myrX, myrY convert3DCoordsToScreen(myX, myY, myZ) -- переводишшь свои корды из игрового мира в коорды на экране
local pX, pY convert3DCoordsToScreen(x, y, z) -- переводишшь корды пикапа из игрового мира в коорды на экране

renderDrawLine(myrX, myrY, pX, pY , 3, 0xFFff004d) -- рендеришь линию
 
  • Влюблен
Реакции: B_Votson Team <3

barjik

Известный
464
190
Что не так делаю?
Lua:
require 'lib.moonloader'

local imgui = require 'imgui'
local window = imgui.ImBool(false)
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8

------------INI CFG --------------
local inicfg = require 'inicfg'
imgui.ToggleButton = require('imgui_addons').ToggleButton
local ToggleButton1 = imgui.ImBool(cfg.settings.tp)

local cfg = inicfg.load({
    settings = {
        tp = true
        }
}, 'test cfg')
--inicfg.save(cfg, test cfg)
----------------------------------
function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
        while not isSampAvailable() do wait(100) end
         sampRegisterChatCommand('mw', mw)
        while true do
           wait(0)
    end
end

function mw()
    window.v = not window.v
    imgui.Process = window.v
end

function imgui.OnDrawFrame()
    if not window.v then
    imgui.Process = false
    end
    
    if window.v then
    if imgui.Begin(u8'Меню', window, imgui.WindowFlags.NoCollapse) then
    if imgui.ToggleButton("knopka", ToggleButton1) then
    cfg.settings.tp = not cfg.settings.tp
    inicfg.save(cfg, 'test cfg')
    end
end
    imgui.End()
    end
end
--[[
function onScriptTerminate(script, quitGame)
  if script == thisScript() then
    inicfg.save(cfg, 'test cfg')
    end
end
]]
ошибка:
attempt to index global 'cfg' (a nil value)
stack traceback:
 

kizn

О КУ)))
Всефорумный модератор
2,405
2,057
Что не так делаю?
Lua:
require 'lib.moonloader'

local imgui = require 'imgui'
local window = imgui.ImBool(false)
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8

------------INI CFG --------------
local inicfg = require 'inicfg'
imgui.ToggleButton = require('imgui_addons').ToggleButton
local ToggleButton1 = imgui.ImBool(cfg.settings.tp)

local cfg = inicfg.load({
    settings = {
        tp = true
        }
}, 'test cfg')
--inicfg.save(cfg, test cfg)
----------------------------------
function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
        while not isSampAvailable() do wait(100) end
         sampRegisterChatCommand('mw', mw)
        while true do
           wait(0)
    end
end

function mw()
    window.v = not window.v
    imgui.Process = window.v
end

function imgui.OnDrawFrame()
    if not window.v then
    imgui.Process = false
    end
   
    if window.v then
    if imgui.Begin(u8'Меню', window, imgui.WindowFlags.NoCollapse) then
    if imgui.ToggleButton("knopka", ToggleButton1) then
    cfg.settings.tp = not cfg.settings.tp
    inicfg.save(cfg, 'test cfg')
    end
end
    imgui.End()
    end
end
--[[
function onScriptTerminate(script, quitGame)
  if script == thisScript() then
    inicfg.save(cfg, 'test cfg')
    end
end
]]
ошибка:
attempt to index global 'cfg' (a nil value)
stack traceback:
юзаешь кфг до его объявления
 
  • Нравится
Реакции: barjik

Sanchez.

Известный
704
187
Как правильно сделать? не шарю
Lua:
require 'lib.moonloader'

local imgui = require 'imgui'
local window = imgui.ImBool(false)
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8

------------INI CFG --------------
local inicfg = require 'inicfg'
imgui.ToggleButton = require('imgui_addons').ToggleButton

local cfg = inicfg.load({ -- тут объявляешь переменную
    settings = {
        tp = true
        }
}, 'test cfg')
--inicfg.save(cfg, test cfg)
----------------------------------

-- а ниже уже сами переменные, в котором присутствуют cfg
local ToggleButton1 = imgui.ImBool(cfg.settings.tp) 

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
        while not isSampAvailable() do wait(100) end
         sampRegisterChatCommand('mw', mw)
        while true do
           wait(0)
    end
end

function mw()
    window.v = not window.v
    imgui.Process = window.v
end

function imgui.OnDrawFrame()
    if not window.v then
    imgui.Process = false
    end
 
    if window.v then
    if imgui.Begin(u8'Меню', window, imgui.WindowFlags.NoCollapse) then
    if imgui.ToggleButton("knopka", ToggleButton1) then
    cfg.settings.tp = not cfg.settings.tp
    inicfg.save(cfg, 'test cfg')
    end
end
    imgui.End()
    end
end
--[[
function onScriptTerminate(script, quitGame)
  if script == thisScript() then
    inicfg.save(cfg, 'test cfg')
    end
end
]]
 

abnomegd

Активный
335
35
Почему не работает некоторые функции в диалоге с ид 15

Lua:
require "lib.moonloader"
local color_dialog = 0xDEB887

-- Для диалога с ID 12
local dialogArr = {"История ников", "Добавить в записную книгу", "Показать документы", "Действия", "Имущество"};
local dialogStr = ""

for _, str in ipairs(dialogArr) do
    dialogStr = dialogStr .. str .. "\n"
end

-- Для диалога с ID 13
local dialogArra = {"Паспорт", "Лицензии", "Медкарта", "МедДиплом", "Выписка из тира", "Трудовая книга", "Военный билет", "Повестка в армию", "Отчёт о работе"}
local dialogStra = ""

for _, stra in ipairs(dialogArra) do
    dialogStra = dialogStra .. stra .. "\n"
end

-- Для диалога с ID 14
local dialogArras = {"Дать денег", "Передать металл / патроны / наркотики / маски / аптечки", "Подарить цветы", "Жениться", "Предложить побег", "Поселить к себе", "Дать ключи от авто"};
local dialogStras = ""

for _, stras in ipairs(dialogArras) do
    dialogStras = dialogStras .. stras .. "\n"
end

-- Для диалога с ID 15
local dialogArrasa = {"Продать машину", "Продать дом", "Продать бизнес", "Обмен авто", "Обмен домами", "Обмен бизнесами"};
local dialogStrasa = ""

for _, strasa in ipairs(dialogArrasa) do
    dialogStrasa = dialogStrasa .. strasa .. "\n"
end

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
    sampRegisterChatCommand("dialog", cmd_dialog)
    sampAddChatMessage("[HelperARP]: {FFFFFF}Скрипт загружен!", 0x5CBCFF)

    while true do
        wait(0)

        local valid, ped = getCharPlayerIsTargeting(PLAYER_HANDLE)
        if valid and doesCharExist(ped) then
            local result, id = sampGetPlayerIdByCharHandle(ped)
            if result and isKeyJustPressed(VK_X) then
                playerid = id
                cmd_dialog(2)
            end
        end

        local result, button, list, input = sampHasDialogRespond(11)
        if result then
            if button == 1 then
                if list == 0 then
                    sampSendChat("/pay "..tostring(playerid)..' '..input)
                end
            end
        end

        local result, button, list, input = sampHasDialogRespond(12)
        if result then
            if button == 1 then
                if list == 0 then -- "История ников"
                    sampSendChat("/history "..sampGetPlayerNickname(tonumber(playerid)))
                elseif list == 1 then -- "Добавить в записную книгу"
                    sampSendChat("/add "..tostring(playerid))
                elseif list == 2 then -- "Показать документы"
                    cmd_dialog(3)
                elseif list == 3 then -- "Действия"
                    cmd_dialog(4)
                elseif list == 4 then -- "Имущество"
                    cmd_dialog(5)
                end
            end
        end

        local result, button, list, input = sampHasDialogRespond(13)
        if result then
            if button == 1 then
                if list == 0 then -- Паспорт
                    lua_thread.create(function()
                        sampSendChat("/do Папка с документами в руке.")
                        wait(1000)
                        sampSendChat("/me достает из папки паспорт")
                        wait(1000)
                        sampSendChat("/pass "..tostring(playerid))
                    end)
                elseif list == 1 then -- Лицензии
                    lua_thread.create(function()
                        sampSendChat("/do Папка с документами в руке.")
                        wait(1000)
                        sampSendChat("/me достает из папки лицензии")
                        wait(1000)
                        sampSendChat("/lic "..tostring(playerid))
                    end)
                elseif list == 2 then -- Медкарта
                    lua_thread.create(function()
                        sampSendChat("/do Папка с документами в руке.")
                        wait(1000)
                        sampSendChat("/me достает из папки медицинскую карту")
                        wait(1000)
                        sampSendChat("/me показывает медицинскую карту человеку напротив")
                        wait(1000)
                        sampSendChat("/med "..tostring(playerid))
                    end)
                elseif list == 3 then -- МедДиплом
                    lua_thread.create(function()
                        sampSendChat("/do Папка с документами в руке.")
                        wait(1000)
                        sampSendChat("/me достает из папки медицинский диплом")
                        wait(1000)
                        sampSendChat("/me показывает медицинский диплом человеку напротив")
                    end)
                elseif list == 4 then -- Выписка из тира
                    lua_thread.create(function()
                        sampSendChat("/do Папка с документами в руке.")
                        wait(1000)
                        sampSendChat("/me достает из папки выписку из тира")
                        wait(1000)
                        sampSendChat("/skill "..tostring(playerid))
                    end)
                elseif list == 5 then -- Трудовая книга
                    lua_thread.create(function()
                        sampSendChat("/do Папка с документами в руке.")
                        wait(1000)
                        sampSendChat("/me достает из папки трудовую книгу")
                        wait(1000)
                        sampSendChat("/wbook "..tostring(playerid))
                    end)
                elseif list == 6 then -- Военный билет
                    lua_thread.create(function()
                        sampSendChat("/do Папка с документами в руке.")
                        wait(1000)
                        sampSendChat("/me достает из папки военный билет")
                        wait(1000)
                        sampSendChat("/me показывает военный билет человеку напротив")
                    end)
                elseif list == 7 then -- Повестка в армию
                    lua_thread.create(function()
                        sampSendChat("/do Папка с документами в руке.")
                        wait(1000)
                        sampSendChat("/me достает из папки повестку")
                        wait(1000)
                        sampSendChat("/me показывает повестку в армию человеку напротив")
                    end)
                elseif list == 8 then -- Отчёт о работе
                    lua_thread.create(function()
                        sampSendChat("/do Папка с документами в руке.")
                        wait(1000)
                        sampSendChat("/me достает из папки отчёт о выполненой работе")
                        wait(1000)
                        sampSendChat("/team "..tostring(playerid))
                    end)
                end
            else
            end
        end

        local result, button, list, input = sampHasDialogRespond(14)
        if result then
            if button == 1 then
                if list == 0 then -- Дать денег
                    cmd_dialog(1)
                elseif list == 1 then -- Передать
                    sampSendChat("/give "..tostring(playerid))
                elseif list == 2 then -- Подарить цветы
                    lua_thread.create(function()
                        sampSendChat("В знак моего внимания к Вам,")
                        wait(1000)
                        sampSendChat("Прошу принять этот подарок")
                        wait(1000)
                        sampSendChat("/do Букет цветов в руках.")
                        wait(1000)
                        sampSendChat("/me передает букет в руки")
                        wait(1000)
                        sampSendChat("/present "..tostring(playerid))
                    end)
                elseif list == 3 then -- Жениться на
                    sampSendChat("/wedding "..tostring(playerid))
                elseif list == 4 then -- Предложить побег
                    sampSendChat("/jailbreak "..tostring(playerid))
                elseif list == 5 then -- Поселить к себе
                    sampSendChat("/live "..tostring(playerid))
                elseif list == 6 then -- Дать ключи от авто
                    sampSendChat("/allow "..tostring(playerid))
                end
            else
            end
        end

        local result, button, list, input = sampHasDialogRespond(15)
        if result then
            if button == 1 then
                if list == 0 then -- Продать авто
                    cmd_dialog(6)
                elseif list == 1 then -- Передать дом
                    cmd_dialog(7)
                elseif list == 2 then -- Подарить бизнес
                    cmd_dialog(8)
                elseif list == 3 then -- Обмен авто
                    cmd_dialog(9)
                elseif list == 4 then -- Обмен домами
                    cmd_dialog(10)
                elseif list == 5 then -- Обмен бизнесами
                    cmd_dialog(11)
                end
            else
            end
        end

        local result, button, list, input = sampHasDialogRespond(16)
        if result then
            if button == 1 then
                if list == 0 then
                    sampSendChat("/sellmycar "..tostring(playerid).." "..input)
                end
            end
        end

        local result, button, list, input = sampHasDialogRespond(17)
        if result then
            if button == 1 then
                if list == 0 then
                    sampSendChat("/sellmyhome "..tostring(playerid).." "..input)
                end
            end
        end

        local result, button, list, input = sampHasDialogRespond(18)
        if result then
            if button == 1 then
                if list == 0 then
                    sampSendChat("/sellmybiz "..tostring(playerid).." "..input)
                end
            end
        end

        local result, button, list, input = sampHasDialogRespond(19)
        if result then
            if button == 1 then
                if list == 0 then
                    sampSendChat("/changecar "..tostring(playerid).." "..input)
                end
            end
        end

        local result, button, list, input = sampHasDialogRespond(20)
        if result then
            if button == 1 then
                if list == 0 then
                    sampSendChat("/changehome "..tostring(playerid).." "..input)
                end
            end
        end

        local result, button, list, input = sampHasDialogRespond(21)
        if result then
            if button == 1 then
                if list == 0 then
                    sampSendChat("/changebiz "..tostring(playerid).." "..input)
                end
            end
        end
    end
end

function cmd_dialog(arg)
    if tonumber(arg) == 1 then
        sampShowDialog(11, "{00ff00}Дать денег", "", "Дать", "Не дать", 1)
    elseif tonumber(arg) == 2 then
        sampShowDialog(12, "{00ff00}Меню взаимодействия с игроком", dialogStr, "Выбрать", "Закрыть", 2)
    elseif tonumber(arg) == 3 then
        sampShowDialog(13, "{00ff00}Показать документы", dialogStra, "Выбрать", "Закрыть", 2)
    elseif tonumber(arg) == 4 then
        sampShowDialog(14, "{00ff00}Действия", dialogStras, "Выбрать", "Закрыть", 2)
    elseif tonumber(arg) == 5 then
        sampShowDialog(15, "{00ff00}Имущество", dialogStrasa, "Выбрать", "Закрыть", 2)
    elseif tonumber(arg) == 6 then
        sampShowDialog(16, "{00ff00}Продать авто", "Введите цену машины.", "Выбрать", "Закрыть", 1) 
    elseif tonumber(arg) == 7 then
        sampShowDialog(17, "{00ff00}Продать дом", "Введите цену дома.", "Выбрать", "Закрыть", 1) 
    elseif tonumber(arg) == 8 then
        sampShowDialog(18, "{00ff00}Продать бизнес", "Введите цену бизнеса.", "Выбрать", "Закрыть", 1)
    elseif tonumber(arg) == 9 then
        sampShowDialog(19, "{00ff00}Обмен авто", "Введите столько сколько должен доплатить человек напротив.", "Выбрать", "Закрыть", 1)   
    elseif tonumber(arg) == 10 then
        sampShowDialog(20, "{00ff00}Обмен домами", "Введите столько сколько должен доплатить человек напротив.", "Выбрать", "Закрыть", 1)
    elseif tonumber(arg) == 11 then
        sampShowDialog(21, "{00ff00}Обмен бизнесами", "Введите столько сколько должен доплатить человек напротив.", "Выбрать", "Закрыть", 1)
    end
end