краш в попуте

bruskin

Участник
Автор темы
151
14
Версия MoonLoader
Другое
Lua:
if imgui.BeginPopupModal(u8'Повышение срока') then
            imgui.SetWindowSize(imgui.ImVec2(400, 100))
            imgui.InputText(u8'Уровень повышения', leveladdpunishpopup)
            imgui.InputText(u8'Причина', reasonaddpunishpopup)
            if imgui.Button(u8'Выдать') and leveladdpunishpopup ~= nil and reasonaddpunishpopup ~= nil then
                lua_thread.create(function()
                    sampSendChat('/do КПК лежит в правом кармане.')
                    wait(1000)
                    sampSendChat('/me взял в руки КПК, авторизовался в системе')
                    wait(1000)
                    sampSendChat('/me зашел в раздел "Заключенные", начал искать нужного')
                    wait(1000)
                    sampSendChat('/do Заключенный найден.')
                    wait(1000)
                    sampSendChat('/me открыл меню взаимодейтсвия, выбрал "Повысить срок"..')
                    wait(1000)
                    sampSendChat('/me ..ввел причину и подтвердил действие')
                    wait(1000)
                    sampSendChat('/do Данные о заключенном обнавлены.')
                    wait(1000)
                    sampSendChat('/punish '..idtarg..' '..leveladdpunishpopup..' 2 '..reasonaddpunishpopup)
                end)
            end
            imgui.SameLine()
            if imgui.Button(u8'Закрыть') then imgui.CloseCurrentPopup() end
            imgui.EndPopup()
Код:
[ML] (error) mdhelper.lua: ...izona Games Launcher\bin\arizona\moonloader\mdhelper.lua:262: attempt to concatenate upvalue 'reasonaddpunishpopup' (a userdata value)
[ML] (error) mdhelper.lua: Script died due to error. (285C9D6C)
крашится скрипт
 
Решение
ffi.string вроде для mimgui только. У тебя imgui.
Добавь просто сзади переменных leveladdpunishpopup и reasonaddpunishpopup.v:
leveladdpunishpopup.v, reasonaddpunishpopup.v
Screenshot_2.png

(Не трогай u8:decode)

Screenshot_1.png

Lua:
if imgui.Button(u8'Выдать') and leveladdpunishpopup.v ~= nil and reasonaddpunishpopup.v ~= nil then
    lua_thread.create(function()
        sampSendChat('/do КПК лежит в правом кармане.')
        wait(1000)
        sampSendChat('/me взял в руки КПК, авторизовался в системе')
        wait(1000)
        sampSendChat('/me зашел в раздел "Заключенные", начал искать нужного')
        wait(1000)
        sampSendChat('/do Заключенный найден.')
        wait(1000)...

bruskin

Участник
Автор темы
151
14
в ту строку где у тебя ошибка, вместо reasonaddpunichpopup
[ML] (error) mdhelper.lua: ...izona Games Launcher\bin\arizona\moonloader\mdhelper.lua:263: attempt to concatenate upvalue 'leveladdpunishpopup' (a userdata value)
[ML] (error) mdhelper.lua: Script died due to error. (2B5A5D3C)
нифига не поменялось
 

bruskin

Участник
Автор темы
151
14
Lua:
require('lib.moonloader')
local imgui = require 'imgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
local sampev = require('lib.samp.events')
local inicfg = require 'inicfg'
local directIni = 'defendhelper.ini'
local ini = inicfg.load(nil, directIni)
local initwo = inicfg.save(ini, directIni)
local vkeys = require 'vkeys'
local rkeys = require 'rkeys'
local ffi = require 'ffi'

checked_stats = true
active_dep = 'Не выбран.'

local SaveCfg = function()
    ini.main.enabled = false
    inicfg.save(ini, directIni)
end

--авто-доклад
hammer = false
autodoklader = false

--imgui
local main_window_state = imgui.ImBool(false)
local debug_window_state = imgui.ImBool(false)
local useditems_window_state = imgui.ImBool(false)
local vzaim_window_state = imgui.ImBool(false)

--imgui.InputText
local leveladdpunishpopup = imgui.ImBuffer(256)
local reasonaddpunishpopup = imgui.ImBuffer(255)

-- КД предметов
usedarmour = 0
usedmask = 0


function main()
    while not isSampAvailable() do wait(0) end
        sampAddChatMessage('{663300}[Defense Helper] {FFFFFF}Скрипт успешно запущен', -1)
        sampAddChatMessage('{663300}[Defense Helper] {FFFFFF}Автор: Mark Bruskin | Версия: 1.0.0', -1)
        sampRegisterChatCommand('probiv', probiv)
        sampRegisterChatCommand('fixdefhelp', fixprobiv)
        sampRegisterChatCommand('debugdh', function() debug_window_state.v = not debug_window_state.v end)
        sampRegisterChatCommand('settingsdh', function() settings_window_state.v = not settings_window_state.v end)
        sampRegisterChatCommand('startdoklad', startdoklad)
        sampRegisterChatCommand('autodoklad', autodoklad)
        sampRegisterChatCommand('useditems', function() useditems_window_state.v = not useditems_window_state.v end)
        sampRegisterChatCommand('frisk', frisk)
        sampRegisterChatCommand('cuff', cuff)
        sampRegisterChatCommand('carcer', carcer)
        sampRegisterChatCommand('uncarcer', uncarcer)
        sampRegisterChatCommand('setcarcer', setcarcer)
        sampRegisterChatCommand('addpunish', addpunish)
        sampRegisterChatCommand('rempunish', rempunish)
        sampRegisterChatCommand('unpunish', unpunish)
        sampRegisterChatCommand('gotome', gotome)
        sampRegisterChatCommand('uncuff', uncuff)
        --sampRegisterChatCommand('dep', function() dep_window_state.v = not dep_window_state.v end)
        main_window_state.v = not main_window_state.v
        asizex = sizex
        asizey = sizey
        _, id = sampGetPlayerIdByCharHandle(PLAYER_PED)
        mynick = sampGetPlayerNickname(id)
        rpnick = sampGetPlayerNickname(id):gsub('_', ' ')
    while true do
        wait(0)
        if isKeyJustPressed(0x48) and not sampIsCursorActive() then
            sampSendChat('/opengate')
        end
        imgui.Process = main_window_state.v or debug_window_state.v or useditems_window_state.v or vzaim_window_state.v --or dep_window_state.v
        if org == nil or org == '' then  
            fullorg = 'Неизвестно'
            checked_stats = true
        else
            fullorg = org
            checked_stats = false
        end
        if rang == nil or rang == '' then                    
            fullrang = 'Неизвестно'
            checked_stats = true
        else
            fullrang = rang
            checked_stats = false
        end
        if lastgun ~= getCurrentCharWeapon(PLAYER_PED) then
            local gun = getCurrentCharWeapon(PLAYER_PED)
            if gun == 24 then
                sampSendChat('/me достал(-а) пистолет Desert Eagle из кабуры')
            elseif gun == 31 then
                sampSendChat("/me достал(-а) карабин М4A1 из-за спины")
            elseif gun == 34 then
                sampSendChat('/me достал(-а) снайперскую винтовку из-за спины')
            elseif gun == 0 then
                sampSendChat('/me убрал(-а) оружие из рук')
            elseif gun == 3 then
                sampSendChat('/me снял(-а) дубинку с поясного держателя')
            elseif gun == 23 then
                sampSendChat('/me снял(-а) электрошокер с поясного держателя')
            elseif gun == 29 then
                sampSendChat('/me снял(-а) пистолет-пулемет "MP5" с поясного держателя')
            end
            lastgun = gun
        end
        myid = sampGetPlayerIdByNickname(mynick)
        if not checked_stats then
            check_stats = 'false'
        elseif checked_stats then
            check_stats = 'true'
        end
        if usedarmour == 0 then
            tusedarmour = 'USE'
        else
            tusedarmour = usedarmour
        end
        if usedmask == 0 then
            tusedmask = 'USE'
        else
            tusedmask = usedmask
        end
        if autodoklader then
            tautodoklader = 'Вкл.'
        else
            tautodoklader = 'Выкл.'
        end
        if org == 'Тюрьма строгого режима LV' then
            org = 'ТСР'
        end
        if sampIsLocalPlayerSpawned() and checked_stats then
            sampSendChat('/stats')
        end
        if isKeyDown(0x02) and isKeyJustPressed(0x47) and targeting then
            lua_thread.create(function()
                _, idtarg = sampGetPlayerIdByCharHandle(target)
                nicktarg = sampGetPlayerNickname(idtarg)
                wait(10)
                vzaim_window_state.v = true
            end)
        end
        targeting, target = getCharPlayerIsTargeting()
    end
end

function probiv()
    lua_thread.create(function()
        setVirtualKeyDown(116, true)
        wait(5000)
        setVirtualKeyDown(116, false)
        sampSendChat('/id '..mynick)
        sampAddChatMessage('Если пишет 0 id - введ /fixdefhelp', -1)
        wait(1000)
        sampSendChat('/stats')
        wait(250)
        sampSendChat('/stats')
        wait(3000)
        setVirtualKeyDown(27, true)
        wait(1)
        setVirtualKeyDown(27, false)
        wait(200)
        sampSendChat('/time')
        setVirtualKeyDown(9, true)
        wait(2000)
        setVirtualKeyDown(9, false)
        wait(2000)
        setVirtualKeyDown(27, true)
        wait(1)
        setVirtualKeyDown(27, false)
    end)
end

function fixprobiv()
    sampAddChatMessage('Успешно', -1)
    thisScript():reload()
end

function sampev.onShowDialog(dialogId, style, title, button1, button2, text)
    for line in text:gmatch("[^\n]+") do
        if line:find('Организация: %{......%}%[(.+)%]') then
            org = line:match('Организация: %{......%}%[(.+)%]')
        end
    end
    for line in text:gmatch("[^\n]+") do
        if line:find("Должность: %{......%}(.+)%((.+)%)") then
            rang, numberrang = line:match("Должность: %{......%}(.+)%((.+)%)")
        end
    end
    if dialogId == 235 and checked_stats then
        checked_stats = false
        lua_thread.create(function()
            wait(50)
            sampCloseCurrentDialogWithButton(0)
        end)
    end
end

function imgui.OnDrawFrame()
    if main_window_state.v then
        local scrX, scrY = getScreenResolution()
        imgui.SetNextWindowPos(imgui.ImVec2(scrX / 2, scrY / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(-4.3, 0.5));
        imgui.SetNextWindowSize(imgui.ImVec2(180,100), imgui.Cond.FirstUseEver)
        imgui.ShowCursor = false
        imgui.Begin(u8'Информация', main_window_state, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse + imgui.WindowFlags.NoTitleBar)
        imgui.Text(u8'Ник: '..u8(mynick))  
        imgui.Text(u8'Организация: '..u8(fullorg))  
        imgui.Text(u8'Должность: '..u8(fullrang))
        imgui.Text(u8'Авто-доклады: '..u8(tautodoklader))
        imgui.Text(os.date('%d %B %Y %X'))
        imgui.End()
    end
    if debug_window_state.v then
        local scrX, scrY = getScreenResolution()
        imgui.SetNextWindowPos(imgui.ImVec2(scrX / 2, scrY / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5));
        imgui.SetNextWindowSize(imgui.ImVec2(600,400), imgui.Cond.FirstUseEver)
        imgui.ShowCursor = true
        imgui.Begin('DEBUG', debug_window_state)
        imgui.Text('id = '..myid)
        imgui.Text('checked_stats = ' ..check_stats)
        imgui.Text('idcar = '..fullidcar)
        imgui.End()
    end
    if useditems_window_state.v then
        local scrX, scrY = getScreenResolution()
        imgui.SetNextWindowPos(imgui.ImVec2(scrX / 2, scrY / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(-3.3, 2));
        imgui.SetNextWindowSize(imgui.ImVec2(220,50), imgui.Cond.FirstUseEver)
        imgui.ShowCursor = false
        imgui.Begin(u8'Информация о предметах', useditems_window_state, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse + imgui.WindowFlags.NoTitleBar)
        imgui.Text(u8'КД бронежилета: '..tusedarmour)
        imgui.Text(u8'Время действия маски (минут): '..tusedmask)
        imgui.End()
    end
    if vzaim_window_state.v then
        local scrX, scrY = getScreenResolution()
        imgui.SetNextWindowPos(imgui.ImVec2(scrX / 2, scrY / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5));
        imgui.SetNextWindowSize(imgui.ImVec2(600,400), imgui.Cond.FirstUseEver)
        imgui.ShowCursor = true
        imgui.Begin(u8'Взаимодействие с игроком', vzaim_window_state)
        imgui.Text(u8'Взаимодействие с игроком: '..nicktarg..'['..idtarg..']')
        if imgui.Button(u8'Повысить срок', imgui.ImVec2(150,70)) then imgui.OpenPopup(u8'Повышение срока') end
        if imgui.BeginPopupModal(u8'Повышение срока') then
            imgui.SetWindowSize(imgui.ImVec2(400, 100))
            imgui.InputText(u8'Уровень повышения', leveladdpunishpopup)
            imgui.InputText(u8'Причина', reasonaddpunishpopup)
            if imgui.Button(u8'Выдать') and leveladdpunishpopup ~= nil and reasonaddpunishpopup ~= nil then
                lua_thread.create(function()
                    sampSendChat('/do КПК лежит в правом кармане.')
                    wait(1000)
                    sampSendChat('/me взял в руки КПК, авторизовался в системе')
                    wait(1000)
                    sampSendChat('/me зашел в раздел "Заключенные", начал искать нужного')
                    wait(1000)
                    sampSendChat('/do Заключенный найден.')
                    wait(1000)
                    sampSendChat('/me открыл меню взаимодейтсвия, выбрал "Повысить срок"..')
                    wait(1000)
                    sampSendChat('/me ..ввел причину и подтвердил действие')
                    wait(1000)
                    sampSendChat('/do Данные о заключенном обнавлены.')
                    wait(1000)
                    sampSendChat('/punish '..idtarg..' '..leveladdpunishpopup..' 2 '..u8:decode(reasonaddpunishpopup)))
                end)
            end
            imgui.SameLine()
            if imgui.Button(u8'Закрыть') then imgui.CloseCurrentPopup() end
            imgui.EndPopup()
        end
        imgui.End()
    end
end

function sampev.onServerMessage(color, text)
    if text:gsub('{%x%x%x%x%x%x}', ''):find('Подбирайте чекпоинты в течении 3 минут, иначе патрулирование будет завершено%.') and autodoklader then
        sampSendChat('/r Докладывает '..rang..' '..rpnick..': Начал патрулирование территории армии.')
    end
    if text:gsub('{%x%x%x%x%x%x}', ''):find('Патрулирование поста: (.+) завершено%.') and autodoklader then
        sampSendChat('/r Докладывает '..rang..' '..rpnick..': Закончил патрулирование территории армии.')
    end
    if text:gsub('{%x%x%x%x%x%x}', ''):find(mynick..'%['..myid..'%] надел бронежилет%.') then
        lua_thread.create(function()
            usedarmour = 60
            repeat
                wait(1000)
                usedarmour = usedarmour - 1
            until usedarmour == 0
        end)
    end
    if text:find('Время действия маски (%d+) минут, после исхода времени ее придётся выбросить%.') then
        usedmask = text:match('Время действия маски (%d+) минут, после исхода времени ее придётся выбросить%.')
        lua_thread.create(function()
            repeat
                wait(60000)
                if usedmask ~= 0 then
                usedmask = usedmask - 1
                end
            until usedmask == 0
        end)
    end
    if text:find('Вы успешно выкинули маску') then
        usedmask = 0
    end
end

function sampGetPlayerIdByNickname(nick)
    nick = tostring(nick)
    local _, myid = sampGetPlayerIdByCharHandle(PLAYER_PED)
    if nick == sampGetPlayerNickname(myid) then return myid end
    for i = 0, 1003 do
      if sampIsPlayerConnected(i) and sampGetPlayerNickname(i) == nick then
        return i
        end
    end
end

function autodoklad()
    autodoklader = not autodoklader
    sampAddChatMessage('{663300}[Defense Helper] {FFFFFF}Авто-доклад '..(autodoklader and 'включен.' or 'выключен.'), -1)
end

function sampev.onDisplayGameText(style, time, text)
    print(text)
    if text == 'GPS: ON' then
        return false
    end
end

function frisk(arg)
    if arg == nil or arg == '' then
        sampAddChatMessage('{663300}[Defense Helper] {FFFFFF}Используйте /frisk [id]', -1)
    else
        lua_thread.create(function()
            sampSendChat('/do В правом кармане лежат перчатки.')
            wait(1000)
            sampSendChat('/me взял в руки перчатки, начал прохлопывать верхний слой одежды')
            wait(1000)
            sampSendChat('/frisk '..arg)
        end)
    end
end

function cuff(arg)
    if arg == nil or arg == '' then
        sampAddChatMessage('{663300}[Defense Helper] {FFFFFF}Используйте /cuff [id]', -1)
    else
        lua_thread.create(function()
            sampSendChat('/do С пояса свисают наручники.')
            wait(1000)
            sampSendChat('/me снял с пояса наручники, начал одевать их на руки подозреваемого')
            wait(1000)
            sampSendChat('/cuff '..arg)
        end)
    end
end

function carcer(arg)
    id_carcer, camera_carcer, time_carcer, reason_carcer = string.match(arg, '(%d+) (%d+) (%d+) (.+)')
    if id_carcer == nil or id_carcer == '' or camera_carcer == nil or camera_carcer == '' or time_carcer == nil or time_carcer == '' or reason_carcer == nil or reason_carcer == '' then
        sampAddChatMessage('{663300}[Defense Helper] {FFFFFF}Используйте /carcer [id] [camera] [time] [reason]', -1)
    else
        lua_thread.create(function()
            sampSendChat('/do Ключ от карцера лежит в левом кармане.')
            wait(1000)
            sampSendChat('/me залез свободной рукой в карман, достал ключ')
            wait(1000)
            sampSendChat('/do Ключ в руках.')
            wait(1000)
            sampSendChat('/me вставил ключ в замок, провернул на 180 градусов')
            wait(1000)
            sampSendChat('/do Дверь открылась.')
            wait(1000)
            sampSendChat('/me затолкал подозреваемого в карцер, захлопнул дверь')
            wait(1000)
            sampSendChat('/carcer '..id_carcer..' '..camera_carcer..' '..time_carcer..' '..reason_carcer)
        end)
    end
end

function addpunish(arg)
    id_addpunish, level_addpunish, reason_addpunish = string.match(arg, '(%d+) (%d+) (.+)')
    if id_addpunish == nil or id_addpunish == '' or reason_addpunish == nil or reason_addpunish == '' or level_addpunish == nil or level_addpunish == '' then
        sampAddChatMessage('{663300}[Defense Helper] {FFFFFF}Используйте /addpunish [id] [level] [reason]', -1)
    else
        lua_thread.create(function()
            sampSendChat('/do КПК лежит в правом кармане.')
            wait(1000)
            sampSendChat('/me взял в руки КПК, авторизовался в системе')
            wait(1000)
            sampSendChat('/me зашел в раздел "Заключенные", начал искать нужного')
            wait(1000)
            sampSendChat('/do Заключенный найден.')
            wait(1000)
            sampSendChat('/me открыл меню взаимодейтсвия, выбрал "Повысить срок"..')
            wait(1000)
            sampSendChat('/me ..ввел причину и подтвердил действие')
            wait(1000)
            sampSendChat('/do Данные о заключенном обнавлены.')
            wait(1000)
            sampSendChat('/punish '..id_addpunish..' '..level_addpunish..' 2 '..reason_addpunish)
        end)
    end
end

function rempunish(arg)
    id_rempunish, level_rempunish, reason_rempunish = string.match(arg, '(%d+) (%d+) (.+)')
    if id_rempunish == nil or id_rempunish == '' or level_rempunish == nil or level_rempunish == '' or reason_rempunish == nil or reason_rempunish == '' then
        sampAddChatMessage('{663300}[Defense Helper] {FFFFFF}Используйте /rempunish [id] [level] [reason]', -1)
    else
        lua_thread.create(function()
            sampSendChat('/do КПК лежит в правом кармане.')
            wait(1000)
            sampSendChat('/me взял в руки КПК, авторизовался в системе')
            wait(1000)
            sampSendChat('/me зашел в раздел "Заключенные", начал искать нужного')
            wait(1000)
            sampSendChat('/do Заключенный найден.')
            wait(1000)
            sampSendChat('/me открыл меню взаимодейтсвия, выбрал "Понизить срок"..')
            wait(1000)
            sampSendChat('/me ..ввел причину и подтвердил действие')
            wait(1000)
            sampSendChat('/do Данные о заключенном обнавлены.')
            wait(1000)
            sampSendChat('/punish '..id_rempunish..' '..level_rempunish..' 1 '..reason_rempunish)
        end)
    end
end

function unpunish(arg)
    id_unpunish, money_unpunish = string.match(arg, '(.+) (.+)')
    if id_unpunish == nil or id_unpunish == '' or money_unpunish == nil or money_unpunish == '' then
        sampAddChatMessage('{663300}[Defense Helper] {FFFFFF}Используйте /unpunish [id] [money]', -1)
    else
        lua_thread.create(function()
        sampSendChat('/do КПК лежит в правом кармане.')
        wait(1000)
        sampSendChat('/me взял в руки КПК, авторизовался в системе')
        wait(1000)
        sampSendChat('/me зашел в раздел "Заключенные", начал искать нужного')
        wait(1000)
        sampSendChat('/do Заключенный найден.')
        wait(1000)
        sampSendChat('/me открыл меню взаимодейтсвия, выбрал "Аннулировать срок"')
        wait(1000)
        sampSendChat('/me подтвердил действие')
        wait(1000)
        sampSendChat('/do Заключенный удален из базы данных.')
        wait(1000)
        sampSendChat('/unpunish '..id_unpunish..' '..money_unpunish)
        end)
    end
end

function setcarcer(arg)
    id_setcarcer, camera_setcarcer = string.match(arg, '(.+) (.+)')
    if id_setcarcer == nil or id_setcarcer == '' or camera_setcarcer == nil or camera_setcarcer == '' then
        sampAddChatMessage('{663300}[Defense Helper] {FFFFFF}Используйте /setcarcer [id] [camera]', -1)
    else
        lua_thread.create(function()
            sampSendChat('/do Ключ от карцера лежит в левом кармане.')
            wait(1000)
            sampSendChat('/me залез свободной рукой в карман, достал ключ')
            wait(1000)
            sampSendChat('/do Ключ в руках.')
            wait(1000)
            sampSendChat('/me вставил ключ в замок, провернул на 180 градусов')
            wait(1000)
            sampSendChat('/do Дверь открылась.')
            wait(1000)
            sampSendChat('/me затолкал подозреваемого в карцер, захлопнул дверь')
            wait(1000)
            sampSendChat('/setcarcer '..id_setcarcer..' '..camera_setcarcer)
        end)
    end
end

function uncarcer(arg)
    if arg == nil or arg == '' then
        sampAddChatMessage('{663300}[Defense Helper] {FFFFFF}Используйте /uncarcer [id]', -1)
    else
        lua_thread.create(function()
            sampSendChat('/do Ключ от карцера лежит в левом кармане.')
            wait(1000)
            sampSendChat('/me залез свободной рукой в карман, достал ключ')
            wait(1000)
            sampSendChat('/do Ключ в руках.')
            wait(1000)
            sampSendChat('/me вставил ключ в замок, провернул на 180 градусов')
            wait(1000)
            sampSendChat('/do Дверь открылась.')
            wait(1000)
            sampSendChat('/me затолкал подозреваемого в карцер, захлопнул дверь')
            wait(1000)
            sampSendChat('/uncarcer '..arg)
        end)
    end
end

function gotome(arg)
    if arg == nil or arg == '' then
        sampAddChatMessage('{663300}[Defense Helper] {FFFFFF}Используйте /gotome [id]', -1)
    else
        lua_thread.create(function()
            sampSendChat('/me заломал руки человеку')
            wait(1000)
            sampSendChat('/do Руки человека заломаны.')
            wait(1000)
            sampSendChat('/gotome '..arg)
        end)
    end
end

function uncuff(arg)
    if arg == nil or arg == '' then
        sampAddChatMessage('{663300}[Defense Helper] {FFFFFF}Используйте /uncuff [id]', -1)
    else
        lua_thread.create(function()
            sampSendChat('/me ослабив хват, снял наручники с рук человека')
            wait(1000)
            sampSendChat('/do Наручники сняты.')
            wait(1000)
            sampSendChat('/uncuff '..arg)
        end)
    end
end

на тебе фулл, удачи в поиске
 

MrDorlik

Известный
953
384
Lua:
require('lib.moonloader')
local imgui = require 'imgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
local sampev = require('lib.samp.events')
local inicfg = require 'inicfg'
local directIni = 'defendhelper.ini'
local ini = inicfg.load(nil, directIni)
local initwo = inicfg.save(ini, directIni)
local vkeys = require 'vkeys'
local rkeys = require 'rkeys'
local ffi = require 'ffi'

checked_stats = true
active_dep = 'Не выбран.'

local SaveCfg = function()
    ini.main.enabled = false
    inicfg.save(ini, directIni)
end

--авто-доклад
hammer = false
autodoklader = false

--imgui
local main_window_state = imgui.ImBool(false)
local debug_window_state = imgui.ImBool(false)
local useditems_window_state = imgui.ImBool(false)
local vzaim_window_state = imgui.ImBool(false)

--imgui.InputText
local leveladdpunishpopup = imgui.ImBuffer(256)
local reasonaddpunishpopup = imgui.ImBuffer(255)

-- КД предметов
usedarmour = 0
usedmask = 0


function main()
    while not isSampAvailable() do wait(0) end
        sampAddChatMessage('{663300}[Defense Helper] {FFFFFF}Скрипт успешно запущен', -1)
        sampAddChatMessage('{663300}[Defense Helper] {FFFFFF}Автор: Mark Bruskin | Версия: 1.0.0', -1)
        sampRegisterChatCommand('probiv', probiv)
        sampRegisterChatCommand('fixdefhelp', fixprobiv)
        sampRegisterChatCommand('debugdh', function() debug_window_state.v = not debug_window_state.v end)
        sampRegisterChatCommand('settingsdh', function() settings_window_state.v = not settings_window_state.v end)
        sampRegisterChatCommand('startdoklad', startdoklad)
        sampRegisterChatCommand('autodoklad', autodoklad)
        sampRegisterChatCommand('useditems', function() useditems_window_state.v = not useditems_window_state.v end)
        sampRegisterChatCommand('frisk', frisk)
        sampRegisterChatCommand('cuff', cuff)
        sampRegisterChatCommand('carcer', carcer)
        sampRegisterChatCommand('uncarcer', uncarcer)
        sampRegisterChatCommand('setcarcer', setcarcer)
        sampRegisterChatCommand('addpunish', addpunish)
        sampRegisterChatCommand('rempunish', rempunish)
        sampRegisterChatCommand('unpunish', unpunish)
        sampRegisterChatCommand('gotome', gotome)
        sampRegisterChatCommand('uncuff', uncuff)
        --sampRegisterChatCommand('dep', function() dep_window_state.v = not dep_window_state.v end)
        main_window_state.v = not main_window_state.v
        asizex = sizex
        asizey = sizey
        _, id = sampGetPlayerIdByCharHandle(PLAYER_PED)
        mynick = sampGetPlayerNickname(id)
        rpnick = sampGetPlayerNickname(id):gsub('_', ' ')
    while true do
        wait(0)
        if isKeyJustPressed(0x48) and not sampIsCursorActive() then
            sampSendChat('/opengate')
        end
        imgui.Process = main_window_state.v or debug_window_state.v or useditems_window_state.v or vzaim_window_state.v --or dep_window_state.v
        if org == nil or org == '' then  
            fullorg = 'Неизвестно'
            checked_stats = true
        else
            fullorg = org
            checked_stats = false
        end
        if rang == nil or rang == '' then                    
            fullrang = 'Неизвестно'
            checked_stats = true
        else
            fullrang = rang
            checked_stats = false
        end
        if lastgun ~= getCurrentCharWeapon(PLAYER_PED) then
            local gun = getCurrentCharWeapon(PLAYER_PED)
            if gun == 24 then
                sampSendChat('/me достал(-а) пистолет Desert Eagle из кабуры')
            elseif gun == 31 then
                sampSendChat("/me достал(-а) карабин М4A1 из-за спины")
            elseif gun == 34 then
                sampSendChat('/me достал(-а) снайперскую винтовку из-за спины')
            elseif gun == 0 then
                sampSendChat('/me убрал(-а) оружие из рук')
            elseif gun == 3 then
                sampSendChat('/me снял(-а) дубинку с поясного держателя')
            elseif gun == 23 then
                sampSendChat('/me снял(-а) электрошокер с поясного держателя')
            elseif gun == 29 then
                sampSendChat('/me снял(-а) пистолет-пулемет "MP5" с поясного держателя')
            end
            lastgun = gun
        end
        myid = sampGetPlayerIdByNickname(mynick)
        if not checked_stats then
            check_stats = 'false'
        elseif checked_stats then
            check_stats = 'true'
        end
        if usedarmour == 0 then
            tusedarmour = 'USE'
        else
            tusedarmour = usedarmour
        end
        if usedmask == 0 then
            tusedmask = 'USE'
        else
            tusedmask = usedmask
        end
        if autodoklader then
            tautodoklader = 'Вкл.'
        else
            tautodoklader = 'Выкл.'
        end
        if org == 'Тюрьма строгого режима LV' then
            org = 'ТСР'
        end
        if sampIsLocalPlayerSpawned() and checked_stats then
            sampSendChat('/stats')
        end
        if isKeyDown(0x02) and isKeyJustPressed(0x47) and targeting then
            lua_thread.create(function()
                _, idtarg = sampGetPlayerIdByCharHandle(target)
                nicktarg = sampGetPlayerNickname(idtarg)
                wait(10)
                vzaim_window_state.v = true
            end)
        end
        targeting, target = getCharPlayerIsTargeting()
    end
end

function probiv()
    lua_thread.create(function()
        setVirtualKeyDown(116, true)
        wait(5000)
        setVirtualKeyDown(116, false)
        sampSendChat('/id '..mynick)
        sampAddChatMessage('Если пишет 0 id - введ /fixdefhelp', -1)
        wait(1000)
        sampSendChat('/stats')
        wait(250)
        sampSendChat('/stats')
        wait(3000)
        setVirtualKeyDown(27, true)
        wait(1)
        setVirtualKeyDown(27, false)
        wait(200)
        sampSendChat('/time')
        setVirtualKeyDown(9, true)
        wait(2000)
        setVirtualKeyDown(9, false)
        wait(2000)
        setVirtualKeyDown(27, true)
        wait(1)
        setVirtualKeyDown(27, false)
    end)
end

function fixprobiv()
    sampAddChatMessage('Успешно', -1)
    thisScript():reload()
end

function sampev.onShowDialog(dialogId, style, title, button1, button2, text)
    for line in text:gmatch("[^\n]+") do
        if line:find('Организация: %{......%}%[(.+)%]') then
            org = line:match('Организация: %{......%}%[(.+)%]')
        end
    end
    for line in text:gmatch("[^\n]+") do
        if line:find("Должность: %{......%}(.+)%((.+)%)") then
            rang, numberrang = line:match("Должность: %{......%}(.+)%((.+)%)")
        end
    end
    if dialogId == 235 and checked_stats then
        checked_stats = false
        lua_thread.create(function()
            wait(50)
            sampCloseCurrentDialogWithButton(0)
        end)
    end
end

function imgui.OnDrawFrame()
    if main_window_state.v then
        local scrX, scrY = getScreenResolution()
        imgui.SetNextWindowPos(imgui.ImVec2(scrX / 2, scrY / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(-4.3, 0.5));
        imgui.SetNextWindowSize(imgui.ImVec2(180,100), imgui.Cond.FirstUseEver)
        imgui.ShowCursor = false
        imgui.Begin(u8'Информация', main_window_state, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse + imgui.WindowFlags.NoTitleBar)
        imgui.Text(u8'Ник: '..u8(mynick))  
        imgui.Text(u8'Организация: '..u8(fullorg))  
        imgui.Text(u8'Должность: '..u8(fullrang))
        imgui.Text(u8'Авто-доклады: '..u8(tautodoklader))
        imgui.Text(os.date('%d %B %Y %X'))
        imgui.End()
    end
    if debug_window_state.v then
        local scrX, scrY = getScreenResolution()
        imgui.SetNextWindowPos(imgui.ImVec2(scrX / 2, scrY / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5));
        imgui.SetNextWindowSize(imgui.ImVec2(600,400), imgui.Cond.FirstUseEver)
        imgui.ShowCursor = true
        imgui.Begin('DEBUG', debug_window_state)
        imgui.Text('id = '..myid)
        imgui.Text('checked_stats = ' ..check_stats)
        imgui.Text('idcar = '..fullidcar)
        imgui.End()
    end
    if useditems_window_state.v then
        local scrX, scrY = getScreenResolution()
        imgui.SetNextWindowPos(imgui.ImVec2(scrX / 2, scrY / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(-3.3, 2));
        imgui.SetNextWindowSize(imgui.ImVec2(220,50), imgui.Cond.FirstUseEver)
        imgui.ShowCursor = false
        imgui.Begin(u8'Информация о предметах', useditems_window_state, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse + imgui.WindowFlags.NoTitleBar)
        imgui.Text(u8'КД бронежилета: '..tusedarmour)
        imgui.Text(u8'Время действия маски (минут): '..tusedmask)
        imgui.End()
    end
    if vzaim_window_state.v then
        local scrX, scrY = getScreenResolution()
        imgui.SetNextWindowPos(imgui.ImVec2(scrX / 2, scrY / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5));
        imgui.SetNextWindowSize(imgui.ImVec2(600,400), imgui.Cond.FirstUseEver)
        imgui.ShowCursor = true
        imgui.Begin(u8'Взаимодействие с игроком', vzaim_window_state)
        imgui.Text(u8'Взаимодействие с игроком: '..nicktarg..'['..idtarg..']')
        if imgui.Button(u8'Повысить срок', imgui.ImVec2(150,70)) then imgui.OpenPopup(u8'Повышение срока') end
        if imgui.BeginPopupModal(u8'Повышение срока') then
            imgui.SetWindowSize(imgui.ImVec2(400, 100))
            imgui.InputText(u8'Уровень повышения', leveladdpunishpopup)
            imgui.InputText(u8'Причина', reasonaddpunishpopup)
            if imgui.Button(u8'Выдать') and leveladdpunishpopup ~= nil and reasonaddpunishpopup ~= nil then
                lua_thread.create(function()
                    sampSendChat('/do КПК лежит в правом кармане.')
                    wait(1000)
                    sampSendChat('/me взял в руки КПК, авторизовался в системе')
                    wait(1000)
                    sampSendChat('/me зашел в раздел "Заключенные", начал искать нужного')
                    wait(1000)
                    sampSendChat('/do Заключенный найден.')
                    wait(1000)
                    sampSendChat('/me открыл меню взаимодейтсвия, выбрал "Повысить срок"..')
                    wait(1000)
                    sampSendChat('/me ..ввел причину и подтвердил действие')
                    wait(1000)
                    sampSendChat('/do Данные о заключенном обнавлены.')
                    wait(1000)
                    sampSendChat('/punish '..idtarg..' '..leveladdpunishpopup..' 2 '..u8:decode(reasonaddpunishpopup))
                end)
            end
            imgui.SameLine()
            if imgui.Button(u8'Закрыть') then imgui.CloseCurrentPopup() end
            imgui.EndPopup()
        end
        imgui.End()
    end
end

function sampev.onServerMessage(color, text)
    if text:gsub('{%x%x%x%x%x%x}', ''):find('Подбирайте чекпоинты в течении 3 минут, иначе патрулирование будет завершено%.') and autodoklader then
        sampSendChat('/r Докладывает '..rang..' '..rpnick..': Начал патрулирование территории армии.')
    end
    if text:gsub('{%x%x%x%x%x%x}', ''):find('Патрулирование поста: (.+) завершено%.') and autodoklader then
        sampSendChat('/r Докладывает '..rang..' '..rpnick..': Закончил патрулирование территории армии.')
    end
    if text:gsub('{%x%x%x%x%x%x}', ''):find(mynick..'%['..myid..'%] надел бронежилет%.') then
        lua_thread.create(function()
            usedarmour = 60
            repeat
                wait(1000)
                usedarmour = usedarmour - 1
            until usedarmour == 0
        end)
    end
    if text:find('Время действия маски (%d+) минут, после исхода времени ее придётся выбросить%.') then
        usedmask = text:match('Время действия маски (%d+) минут, после исхода времени ее придётся выбросить%.')
        lua_thread.create(function()
            repeat
                wait(60000)
                if usedmask ~= 0 then
                usedmask = usedmask - 1
                end
            until usedmask == 0
        end)
    end
    if text:find('Вы успешно выкинули маску') then
        usedmask = 0
    end
end

function sampGetPlayerIdByNickname(nick)
    nick = tostring(nick)
    local _, myid = sampGetPlayerIdByCharHandle(PLAYER_PED)
    if nick == sampGetPlayerNickname(myid) then return myid end
    for i = 0, 1003 do
      if sampIsPlayerConnected(i) and sampGetPlayerNickname(i) == nick then
        return i
        end
    end
end

function autodoklad()
    autodoklader = not autodoklader
    sampAddChatMessage('{663300}[Defense Helper] {FFFFFF}Авто-доклад '..(autodoklader and 'включен.' or 'выключен.'), -1)
end

function sampev.onDisplayGameText(style, time, text)
    print(text)
    if text == 'GPS: ON' then
        return false
    end
end

function frisk(arg)
    if arg == nil or arg == '' then
        sampAddChatMessage('{663300}[Defense Helper] {FFFFFF}Используйте /frisk [id]', -1)
    else
        lua_thread.create(function()
            sampSendChat('/do В правом кармане лежат перчатки.')
            wait(1000)
            sampSendChat('/me взял в руки перчатки, начал прохлопывать верхний слой одежды')
            wait(1000)
            sampSendChat('/frisk '..arg)
        end)
    end
end

function cuff(arg)
    if arg == nil or arg == '' then
        sampAddChatMessage('{663300}[Defense Helper] {FFFFFF}Используйте /cuff [id]', -1)
    else
        lua_thread.create(function()
            sampSendChat('/do С пояса свисают наручники.')
            wait(1000)
            sampSendChat('/me снял с пояса наручники, начал одевать их на руки подозреваемого')
            wait(1000)
            sampSendChat('/cuff '..arg)
        end)
    end
end

function carcer(arg)
    id_carcer, camera_carcer, time_carcer, reason_carcer = string.match(arg, '(%d+) (%d+) (%d+) (.+)')
    if id_carcer == nil or id_carcer == '' or camera_carcer == nil or camera_carcer == '' or time_carcer == nil or time_carcer == '' or reason_carcer == nil or reason_carcer == '' then
        sampAddChatMessage('{663300}[Defense Helper] {FFFFFF}Используйте /carcer [id] [camera] [time] [reason]', -1)
    else
        lua_thread.create(function()
            sampSendChat('/do Ключ от карцера лежит в левом кармане.')
            wait(1000)
            sampSendChat('/me залез свободной рукой в карман, достал ключ')
            wait(1000)
            sampSendChat('/do Ключ в руках.')
            wait(1000)
            sampSendChat('/me вставил ключ в замок, провернул на 180 градусов')
            wait(1000)
            sampSendChat('/do Дверь открылась.')
            wait(1000)
            sampSendChat('/me затолкал подозреваемого в карцер, захлопнул дверь')
            wait(1000)
            sampSendChat('/carcer '..id_carcer..' '..camera_carcer..' '..time_carcer..' '..reason_carcer)
        end)
    end
end

function addpunish(arg)
    id_addpunish, level_addpunish, reason_addpunish = string.match(arg, '(%d+) (%d+) (.+)')
    if id_addpunish == nil or id_addpunish == '' or reason_addpunish == nil or reason_addpunish == '' or level_addpunish == nil or level_addpunish == '' then
        sampAddChatMessage('{663300}[Defense Helper] {FFFFFF}Используйте /addpunish [id] [level] [reason]', -1)
    else
        lua_thread.create(function()
            sampSendChat('/do КПК лежит в правом кармане.')
            wait(1000)
            sampSendChat('/me взял в руки КПК, авторизовался в системе')
            wait(1000)
            sampSendChat('/me зашел в раздел "Заключенные", начал искать нужного')
            wait(1000)
            sampSendChat('/do Заключенный найден.')
            wait(1000)
            sampSendChat('/me открыл меню взаимодейтсвия, выбрал "Повысить срок"..')
            wait(1000)
            sampSendChat('/me ..ввел причину и подтвердил действие')
            wait(1000)
            sampSendChat('/do Данные о заключенном обнавлены.')
            wait(1000)
            sampSendChat('/punish '..id_addpunish..' '..level_addpunish..' 2 '..reason_addpunish)
        end)
    end
end

function rempunish(arg)
    id_rempunish, level_rempunish, reason_rempunish = string.match(arg, '(%d+) (%d+) (.+)')
    if id_rempunish == nil or id_rempunish == '' or level_rempunish == nil or level_rempunish == '' or reason_rempunish == nil or reason_rempunish == '' then
        sampAddChatMessage('{663300}[Defense Helper] {FFFFFF}Используйте /rempunish [id] [level] [reason]', -1)
    else
        lua_thread.create(function()
            sampSendChat('/do КПК лежит в правом кармане.')
            wait(1000)
            sampSendChat('/me взял в руки КПК, авторизовался в системе')
            wait(1000)
            sampSendChat('/me зашел в раздел "Заключенные", начал искать нужного')
            wait(1000)
            sampSendChat('/do Заключенный найден.')
            wait(1000)
            sampSendChat('/me открыл меню взаимодейтсвия, выбрал "Понизить срок"..')
            wait(1000)
            sampSendChat('/me ..ввел причину и подтвердил действие')
            wait(1000)
            sampSendChat('/do Данные о заключенном обнавлены.')
            wait(1000)
            sampSendChat('/punish '..id_rempunish..' '..level_rempunish..' 1 '..reason_rempunish)
        end)
    end
end

function unpunish(arg)
    id_unpunish, money_unpunish = string.match(arg, '(.+) (.+)')
    if id_unpunish == nil or id_unpunish == '' or money_unpunish == nil or money_unpunish == '' then
        sampAddChatMessage('{663300}[Defense Helper] {FFFFFF}Используйте /unpunish [id] [money]', -1)
    else
        lua_thread.create(function()
        sampSendChat('/do КПК лежит в правом кармане.')
        wait(1000)
        sampSendChat('/me взял в руки КПК, авторизовался в системе')
        wait(1000)
        sampSendChat('/me зашел в раздел "Заключенные", начал искать нужного')
        wait(1000)
        sampSendChat('/do Заключенный найден.')
        wait(1000)
        sampSendChat('/me открыл меню взаимодейтсвия, выбрал "Аннулировать срок"')
        wait(1000)
        sampSendChat('/me подтвердил действие')
        wait(1000)
        sampSendChat('/do Заключенный удален из базы данных.')
        wait(1000)
        sampSendChat('/unpunish '..id_unpunish..' '..money_unpunish)
        end)
    end
end

function setcarcer(arg)
    id_setcarcer, camera_setcarcer = string.match(arg, '(.+) (.+)')
    if id_setcarcer == nil or id_setcarcer == '' or camera_setcarcer == nil or camera_setcarcer == '' then
        sampAddChatMessage('{663300}[Defense Helper] {FFFFFF}Используйте /setcarcer [id] [camera]', -1)
    else
        lua_thread.create(function()
            sampSendChat('/do Ключ от карцера лежит в левом кармане.')
            wait(1000)
            sampSendChat('/me залез свободной рукой в карман, достал ключ')
            wait(1000)
            sampSendChat('/do Ключ в руках.')
            wait(1000)
            sampSendChat('/me вставил ключ в замок, провернул на 180 градусов')
            wait(1000)
            sampSendChat('/do Дверь открылась.')
            wait(1000)
            sampSendChat('/me затолкал подозреваемого в карцер, захлопнул дверь')
            wait(1000)
            sampSendChat('/setcarcer '..id_setcarcer..' '..camera_setcarcer)
        end)
    end
end

function uncarcer(arg)
    if arg == nil or arg == '' then
        sampAddChatMessage('{663300}[Defense Helper] {FFFFFF}Используйте /uncarcer [id]', -1)
    else
        lua_thread.create(function()
            sampSendChat('/do Ключ от карцера лежит в левом кармане.')
            wait(1000)
            sampSendChat('/me залез свободной рукой в карман, достал ключ')
            wait(1000)
            sampSendChat('/do Ключ в руках.')
            wait(1000)
            sampSendChat('/me вставил ключ в замок, провернул на 180 градусов')
            wait(1000)
            sampSendChat('/do Дверь открылась.')
            wait(1000)
            sampSendChat('/me затолкал подозреваемого в карцер, захлопнул дверь')
            wait(1000)
            sampSendChat('/uncarcer '..arg)
        end)
    end
end

function gotome(arg)
    if arg == nil or arg == '' then
        sampAddChatMessage('{663300}[Defense Helper] {FFFFFF}Используйте /gotome [id]', -1)
    else
        lua_thread.create(function()
            sampSendChat('/me заломал руки человеку')
            wait(1000)
            sampSendChat('/do Руки человека заломаны.')
            wait(1000)
            sampSendChat('/gotome '..arg)
        end)
    end
end

function uncuff(arg)
    if arg == nil or arg == '' then
        sampAddChatMessage('{663300}[Defense Helper] {FFFFFF}Используйте /uncuff [id]', -1)
    else
        lua_thread.create(function()
            sampSendChat('/me ослабив хват, снял наручники с рук человека')
            wait(1000)
            sampSendChat('/do Наручники сняты.')
            wait(1000)
            sampSendChat('/uncuff '..arg)
        end)
    end
end

на тебе фулл, удачи в поиске
так ты не до конца вставил, что я написал
 

Dmitriy Makarov

25.05.2021
Проверенный
2,514
1,140
ffi.string вроде для mimgui только. У тебя imgui.
Добавь просто сзади переменных leveladdpunishpopup и reasonaddpunishpopup.v:
leveladdpunishpopup.v, reasonaddpunishpopup.v
Screenshot_2.png

(Не трогай u8:decode)

Screenshot_1.png

Lua:
if imgui.Button(u8'Выдать') and leveladdpunishpopup.v ~= nil and reasonaddpunishpopup.v ~= nil then
    lua_thread.create(function()
        sampSendChat('/do КПК лежит в правом кармане.')
        wait(1000)
        sampSendChat('/me взял в руки КПК, авторизовался в системе')
        wait(1000)
        sampSendChat('/me зашел в раздел "Заключенные", начал искать нужного')
        wait(1000)
        sampSendChat('/do Заключенный найден.')
        wait(1000)
        sampSendChat('/me открыл меню взаимодейтсвия, выбрал "Повысить срок"..')
        wait(1000)
        sampSendChat('/me ..ввел причину и подтвердил действие')
        wait(1000)
        sampSendChat('/do Данные о заключенном обнавлены.')
        wait(1000)
        sampSendChat('/punish '..idtarg..' '..leveladdpunishpopup.v..' 2 '..u8:decode(reasonaddpunishpopup.v))
    end)
end
 
  • Нравится
Реакции: bruskin, Hinаta и cord