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

ШPEK

Известный
1,476
524
Lua:
local key = require "vkeys"
require "lib.moonloader"
local imgui = require "imgui"
local encoding = require "encoding"
encoding.default = "CP1251"
u8 = encoding.UTF8


imint = imgui.ImInt(1500)
imbool = imgui.ImBool(false)
checkbox = imgui.ImBool(false)
function imgui.OnDrawFrame()
    if imbool.v then
         imgui.SetNextWindowSize(imgui.ImVec2(500, 200), imgui.Cond.FirstUseEver)
        local sw, sh = getScreenResolution()
        imgui.SetNextWindowPos(imgui.ImVec2(sw / 2, sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.Begin("AutoRP GUN by Dmitry555", imbool)
        imgui.Checkbox("Включить/выключить автоРП отыгровку оружия", checkbox)
        imgui.SliderInt("Задержка в мс", imint, 1000, 10000)
        imgui.End()
    end
end

function main()
while not isSampAvailable() do wait(100) end
    sampRegisterChatCommand("mg", function() imbool.v = not imbool.v end)
    while true do
    wait(0)
        imgui.Process = imbool.v
        imgui.ShowCursor = imbool.v
        imgui.LockPlayer = imbool.v
            local weapon = getCurrentCharWeapon(PLAYER_PED)
            while weapon == 1 or weapon == 2 or weapon == 3 or weapon == 5 or weapon == 8 or weapon == 17 or weapon == 22 or weapon == 23 or weapon == 24 or weapon == 25 or weapon == 29 or weapon == 30 or weapon == 31 or weapon == 33 or weapon == 34 and checkbox.v == true do
            wait(0)
            imgui.Process = imbool.v
            imgui.ShowCursor = imbool.v
            imgui.LockPlayer = imbool.v
            local weapon = getCurrentCharWeapon(PLAYER_PED)
                if weapon == 1 then
                    sampSendChat("/do Кастет на руке.")
                    while true and checkbox.v == true do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 1 then
                            break
                        end
                    end
                elseif weapon == 2 then
                    sampSendChat("/do Клюшка в руке.")
                    while true and checkbox.v == true do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 2 then
                            break
                        end
                    end 
                elseif weapon == 3 then
                    sampSendChat("/do Дубинка висит на поясе.")
                    wait(imint.v)
                    sampSendChat("/me снял дубинку с пояса")
                    while true and checkbox.v == true do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 3 then
                            sampSendChat("/me повесил дубинку на пояс")
                            break
                        end
                    end
                elseif weapon == 5 then
                    sampSendChat("/do Бита в руках.")
                    while true and checkbox.v do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 5 then
                            break
                        end
                    end
                elseif weapon == 8 then
                    sampSendChat("/do Катана на поясе в чехле.")
                    wait(imint.v)
                    sampSendChat("/me вытащил катану с чехла")
                    while true and checkbox.v do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 8 then
                            sampSendChat("/do Чехол для катаны на поясе.")
                            wait(imint.v)
                            sampSendChat("/me засунул катану в чехол")
                            break
                        end
                    end
                elseif weapon == 17 then
                    sampSendChat("/do Дымовая шашка в чехле на поясе.")
                    wait(imint.v)
                    sampSendChat("/me вытащил дымовую шашку")
                        while true and checkbox.v do
                        wait(0)
                        imgui.Process = imbool.v
                        imgui.ShowCursor = imbool.v
                        imgui.LockPlayer = imbool.v
                        local weapon = getCurrentCharWeapon(PLAYER_PED)
                            if weapon ~= 17 then
                                break
                            end
                        end
                elseif weapon == 22 then
                    sampSendChat("/do Пистолет \"Glock\" на поясе.")
                    wait(imint.v)
                    sampSendChat("/me вытащил пистолет \"Glock\" из кобуры")
                    while true and checkbox.v do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 22 then
                            sampSendChat("/do Кобура на поясе.")
                            wait(imint.v)
                            sampSendChat("/me засунул пистолет в кобуру")
                            break
                        end
                    end
                elseif weapon == 23 then
                    sampSendChat("/do На поясе дистанционный электрошокер.")
                    wait(imint.v)
                    sampSendChat("/me снял с пояса электрошокер")
                    while true and checkbox.v do
                    wait(0)
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    imgui.Process = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 23 then
                            sampSendChat("/do Электрошокер в руках.")
                            wait(imint.v)
                            sampSendChat("/me прикрепил электрошокер к поясу")
                            break
                        end
                    end
                elseif weapon == 24 then
                    sampSendChat(u8"/do В кобуре пистолет \"Пустынный ястреб\".")
                    wait(imint.v)
                    sampSendChat(u8"/me достал пистолет из кобуры")
                    while true and checkbox.v do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 24 then
                            sampSendChat("/do Кобура на поясе.")
                            wait(imint.v)
                            sampSendChat("/me засунул пистолет в кобуру")
                            break
                        end
                    end
                elseif weapon == 25 then
                    sampSendChat("/do На плече весит дробовик \"Remington\".")
                    wait(imint.v)
                    sampSendChat("/me снял с плеча дробовик")
                    while true and checkbox.v do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 25 then
                            sampSendChat("/me повесил дробовик на плечо")
                            break
                        end
                    end
                elseif weapon == 29 then
                    sampSendChat("/do На плече весит пистолет-пулемёт \"MP-5\".")
                    wait(imint.v)
                    sampSendChat("/me снял с плеча пистолет-пулемёт")
                    while true and checkbox.v do
                    wait(0)
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    imgui.Process = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 29 then
                            sampSendChat("/me повесил пистолет-пулемёт на плечо")
                            break
                        end
                    end
                elseif weapon == 30 then
                    sampSendChat("/do На плече весит автомат \"АК-47\".")
                    wait(imint.v)
                    sampSendChat("/me снял с плеча автомат")
                    while true and checkbox.v do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 30 then
                            sampSendChat("/me повесил автомат на плечо")
                            break
                        end
                    end
                elseif weapon == 31 then
                    sampSendChat("/do На плече висит карабин \"M4A1\".")
                    wait(imint.v)
                    sampSendChat("/me снял с плеча карабин")
                    while true and checkbox.v do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 31 then
                            sampSendChat("/me повесил карабин на плечо")
                            break
                        end
                    end
                elseif weapon == 33 then
                    sampSendChat("/do На плече висит охотничья винтовка.")
                    wait(imint.v)
                    sampSendChat("/me снял охотничью винтовку с плеча")
                    while true and checkbox.v do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 33 then
                            sampSendChat("/me повесил охотничью винтовку на плечо")
                            break
                        end
                    end
                elseif weapon == 34 then
                    sampSendChat("/do В руке кейс с винтовкой \"SVD\".")
                    wait(imint.v)
                    sampSendChat("/me открыв кейс, достал оттуда винтовку")
                    wait(imint.v)
                    sampSendChat("/me зарядил винтовку")
                    while true and checkbox.v do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 34 then
                            sampSendChat("/me открыл кейс")
                            wait(imint.v)
                            sampSendChat("/me положил винтовку в кейс")
                            wait(imint.v)
                            sampSendChat("/me закрыл кейс")
                            break
                        end
                    end
                end
            end
        end
    end
Почему выходят каракули? Кодировка на CP1251 и выходят каракули
 

AnWu

Guardian of Order
Всефорумный модератор
4,687
5,166
Lua:
local key = require "vkeys"
require "lib.moonloader"
local imgui = require "imgui"
local encoding = require "encoding"
encoding.default = "CP1251"
u8 = encoding.UTF8


imint = imgui.ImInt(1500)
imbool = imgui.ImBool(false)
checkbox = imgui.ImBool(false)
function imgui.OnDrawFrame()
    if imbool.v then
         imgui.SetNextWindowSize(imgui.ImVec2(500, 200), imgui.Cond.FirstUseEver)
        local sw, sh = getScreenResolution()
        imgui.SetNextWindowPos(imgui.ImVec2(sw / 2, sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.Begin("AutoRP GUN by Dmitry555", imbool)
        imgui.Checkbox("Включить/выключить автоРП отыгровку оружия", checkbox)
        imgui.SliderInt("Задержка в мс", imint, 1000, 10000)
        imgui.End()
    end
end

function main()
while not isSampAvailable() do wait(100) end
    sampRegisterChatCommand("mg", function() imbool.v = not imbool.v end)
    while true do
    wait(0)
        imgui.Process = imbool.v
        imgui.ShowCursor = imbool.v
        imgui.LockPlayer = imbool.v
            local weapon = getCurrentCharWeapon(PLAYER_PED)
            while weapon == 1 or weapon == 2 or weapon == 3 or weapon == 5 or weapon == 8 or weapon == 17 or weapon == 22 or weapon == 23 or weapon == 24 or weapon == 25 or weapon == 29 or weapon == 30 or weapon == 31 or weapon == 33 or weapon == 34 and checkbox.v == true do
            wait(0)
            imgui.Process = imbool.v
            imgui.ShowCursor = imbool.v
            imgui.LockPlayer = imbool.v
            local weapon = getCurrentCharWeapon(PLAYER_PED)
                if weapon == 1 then
                    sampSendChat("/do Кастет на руке.")
                    while true and checkbox.v == true do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 1 then
                            break
                        end
                    end
                elseif weapon == 2 then
                    sampSendChat("/do Клюшка в руке.")
                    while true and checkbox.v == true do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 2 then
                            break
                        end
                    end
                elseif weapon == 3 then
                    sampSendChat("/do Дубинка висит на поясе.")
                    wait(imint.v)
                    sampSendChat("/me снял дубинку с пояса")
                    while true and checkbox.v == true do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 3 then
                            sampSendChat("/me повесил дубинку на пояс")
                            break
                        end
                    end
                elseif weapon == 5 then
                    sampSendChat("/do Бита в руках.")
                    while true and checkbox.v do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 5 then
                            break
                        end
                    end
                elseif weapon == 8 then
                    sampSendChat("/do Катана на поясе в чехле.")
                    wait(imint.v)
                    sampSendChat("/me вытащил катану с чехла")
                    while true and checkbox.v do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 8 then
                            sampSendChat("/do Чехол для катаны на поясе.")
                            wait(imint.v)
                            sampSendChat("/me засунул катану в чехол")
                            break
                        end
                    end
                elseif weapon == 17 then
                    sampSendChat("/do Дымовая шашка в чехле на поясе.")
                    wait(imint.v)
                    sampSendChat("/me вытащил дымовую шашку")
                        while true and checkbox.v do
                        wait(0)
                        imgui.Process = imbool.v
                        imgui.ShowCursor = imbool.v
                        imgui.LockPlayer = imbool.v
                        local weapon = getCurrentCharWeapon(PLAYER_PED)
                            if weapon ~= 17 then
                                break
                            end
                        end
                elseif weapon == 22 then
                    sampSendChat("/do Пистолет \"Glock\" на поясе.")
                    wait(imint.v)
                    sampSendChat("/me вытащил пистолет \"Glock\" из кобуры")
                    while true and checkbox.v do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 22 then
                            sampSendChat("/do Кобура на поясе.")
                            wait(imint.v)
                            sampSendChat("/me засунул пистолет в кобуру")
                            break
                        end
                    end
                elseif weapon == 23 then
                    sampSendChat("/do На поясе дистанционный электрошокер.")
                    wait(imint.v)
                    sampSendChat("/me снял с пояса электрошокер")
                    while true and checkbox.v do
                    wait(0)
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    imgui.Process = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 23 then
                            sampSendChat("/do Электрошокер в руках.")
                            wait(imint.v)
                            sampSendChat("/me прикрепил электрошокер к поясу")
                            break
                        end
                    end
                elseif weapon == 24 then
                    sampSendChat(u8"/do В кобуре пистолет \"Пустынный ястреб\".")
                    wait(imint.v)
                    sampSendChat(u8"/me достал пистолет из кобуры")
                    while true and checkbox.v do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 24 then
                            sampSendChat("/do Кобура на поясе.")
                            wait(imint.v)
                            sampSendChat("/me засунул пистолет в кобуру")
                            break
                        end
                    end
                elseif weapon == 25 then
                    sampSendChat("/do На плече весит дробовик \"Remington\".")
                    wait(imint.v)
                    sampSendChat("/me снял с плеча дробовик")
                    while true and checkbox.v do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 25 then
                            sampSendChat("/me повесил дробовик на плечо")
                            break
                        end
                    end
                elseif weapon == 29 then
                    sampSendChat("/do На плече весит пистолет-пулемёт \"MP-5\".")
                    wait(imint.v)
                    sampSendChat("/me снял с плеча пистолет-пулемёт")
                    while true and checkbox.v do
                    wait(0)
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    imgui.Process = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 29 then
                            sampSendChat("/me повесил пистолет-пулемёт на плечо")
                            break
                        end
                    end
                elseif weapon == 30 then
                    sampSendChat("/do На плече весит автомат \"АК-47\".")
                    wait(imint.v)
                    sampSendChat("/me снял с плеча автомат")
                    while true and checkbox.v do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 30 then
                            sampSendChat("/me повесил автомат на плечо")
                            break
                        end
                    end
                elseif weapon == 31 then
                    sampSendChat("/do На плече висит карабин \"M4A1\".")
                    wait(imint.v)
                    sampSendChat("/me снял с плеча карабин")
                    while true and checkbox.v do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 31 then
                            sampSendChat("/me повесил карабин на плечо")
                            break
                        end
                    end
                elseif weapon == 33 then
                    sampSendChat("/do На плече висит охотничья винтовка.")
                    wait(imint.v)
                    sampSendChat("/me снял охотничью винтовку с плеча")
                    while true and checkbox.v do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 33 then
                            sampSendChat("/me повесил охотничью винтовку на плечо")
                            break
                        end
                    end
                elseif weapon == 34 then
                    sampSendChat("/do В руке кейс с винтовкой \"SVD\".")
                    wait(imint.v)
                    sampSendChat("/me открыв кейс, достал оттуда винтовку")
                    wait(imint.v)
                    sampSendChat("/me зарядил винтовку")
                    while true and checkbox.v do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 34 then
                            sampSendChat("/me открыл кейс")
                            wait(imint.v)
                            sampSendChat("/me положил винтовку в кейс")
                            wait(imint.v)
                            sampSendChat("/me закрыл кейс")
                            break
                        end
                    end
                end
            end
        end
    end
Почему выходят каракули? Кодировка на CP1251 и выходят каракули
Пример до конца читал?
imgui.Checkbox(u8("Русский текст"))
 
  • Нравится
Реакции: ШPEK

imring

Ride the Lightning
Всефорумный модератор
2,355
2,516
Lua:
local key = require "vkeys"
require "lib.moonloader"
local imgui = require "imgui"
local encoding = require "encoding"
encoding.default = "CP1251"
u8 = encoding.UTF8


imint = imgui.ImInt(1500)
imbool = imgui.ImBool(false)
checkbox = imgui.ImBool(false)
function imgui.OnDrawFrame()
    if imbool.v then
         imgui.SetNextWindowSize(imgui.ImVec2(500, 200), imgui.Cond.FirstUseEver)
        local sw, sh = getScreenResolution()
        imgui.SetNextWindowPos(imgui.ImVec2(sw / 2, sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.Begin("AutoRP GUN by Dmitry555", imbool)
        imgui.Checkbox("Включить/выключить автоРП отыгровку оружия", checkbox)
        imgui.SliderInt("Задержка в мс", imint, 1000, 10000)
        imgui.End()
    end
end

function main()
while not isSampAvailable() do wait(100) end
    sampRegisterChatCommand("mg", function() imbool.v = not imbool.v end)
    while true do
    wait(0)
        imgui.Process = imbool.v
        imgui.ShowCursor = imbool.v
        imgui.LockPlayer = imbool.v
            local weapon = getCurrentCharWeapon(PLAYER_PED)
            while weapon == 1 or weapon == 2 or weapon == 3 or weapon == 5 or weapon == 8 or weapon == 17 or weapon == 22 or weapon == 23 or weapon == 24 or weapon == 25 or weapon == 29 or weapon == 30 or weapon == 31 or weapon == 33 or weapon == 34 and checkbox.v == true do
            wait(0)
            imgui.Process = imbool.v
            imgui.ShowCursor = imbool.v
            imgui.LockPlayer = imbool.v
            local weapon = getCurrentCharWeapon(PLAYER_PED)
                if weapon == 1 then
                    sampSendChat("/do Кастет на руке.")
                    while true and checkbox.v == true do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 1 then
                            break
                        end
                    end
                elseif weapon == 2 then
                    sampSendChat("/do Клюшка в руке.")
                    while true and checkbox.v == true do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 2 then
                            break
                        end
                    end
                elseif weapon == 3 then
                    sampSendChat("/do Дубинка висит на поясе.")
                    wait(imint.v)
                    sampSendChat("/me снял дубинку с пояса")
                    while true and checkbox.v == true do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 3 then
                            sampSendChat("/me повесил дубинку на пояс")
                            break
                        end
                    end
                elseif weapon == 5 then
                    sampSendChat("/do Бита в руках.")
                    while true and checkbox.v do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 5 then
                            break
                        end
                    end
                elseif weapon == 8 then
                    sampSendChat("/do Катана на поясе в чехле.")
                    wait(imint.v)
                    sampSendChat("/me вытащил катану с чехла")
                    while true and checkbox.v do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 8 then
                            sampSendChat("/do Чехол для катаны на поясе.")
                            wait(imint.v)
                            sampSendChat("/me засунул катану в чехол")
                            break
                        end
                    end
                elseif weapon == 17 then
                    sampSendChat("/do Дымовая шашка в чехле на поясе.")
                    wait(imint.v)
                    sampSendChat("/me вытащил дымовую шашку")
                        while true and checkbox.v do
                        wait(0)
                        imgui.Process = imbool.v
                        imgui.ShowCursor = imbool.v
                        imgui.LockPlayer = imbool.v
                        local weapon = getCurrentCharWeapon(PLAYER_PED)
                            if weapon ~= 17 then
                                break
                            end
                        end
                elseif weapon == 22 then
                    sampSendChat("/do Пистолет \"Glock\" на поясе.")
                    wait(imint.v)
                    sampSendChat("/me вытащил пистолет \"Glock\" из кобуры")
                    while true and checkbox.v do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 22 then
                            sampSendChat("/do Кобура на поясе.")
                            wait(imint.v)
                            sampSendChat("/me засунул пистолет в кобуру")
                            break
                        end
                    end
                elseif weapon == 23 then
                    sampSendChat("/do На поясе дистанционный электрошокер.")
                    wait(imint.v)
                    sampSendChat("/me снял с пояса электрошокер")
                    while true and checkbox.v do
                    wait(0)
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    imgui.Process = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 23 then
                            sampSendChat("/do Электрошокер в руках.")
                            wait(imint.v)
                            sampSendChat("/me прикрепил электрошокер к поясу")
                            break
                        end
                    end
                elseif weapon == 24 then
                    sampSendChat(u8"/do В кобуре пистолет \"Пустынный ястреб\".")
                    wait(imint.v)
                    sampSendChat(u8"/me достал пистолет из кобуры")
                    while true and checkbox.v do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 24 then
                            sampSendChat("/do Кобура на поясе.")
                            wait(imint.v)
                            sampSendChat("/me засунул пистолет в кобуру")
                            break
                        end
                    end
                elseif weapon == 25 then
                    sampSendChat("/do На плече весит дробовик \"Remington\".")
                    wait(imint.v)
                    sampSendChat("/me снял с плеча дробовик")
                    while true and checkbox.v do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 25 then
                            sampSendChat("/me повесил дробовик на плечо")
                            break
                        end
                    end
                elseif weapon == 29 then
                    sampSendChat("/do На плече весит пистолет-пулемёт \"MP-5\".")
                    wait(imint.v)
                    sampSendChat("/me снял с плеча пистолет-пулемёт")
                    while true and checkbox.v do
                    wait(0)
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    imgui.Process = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 29 then
                            sampSendChat("/me повесил пистолет-пулемёт на плечо")
                            break
                        end
                    end
                elseif weapon == 30 then
                    sampSendChat("/do На плече весит автомат \"АК-47\".")
                    wait(imint.v)
                    sampSendChat("/me снял с плеча автомат")
                    while true and checkbox.v do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 30 then
                            sampSendChat("/me повесил автомат на плечо")
                            break
                        end
                    end
                elseif weapon == 31 then
                    sampSendChat("/do На плече висит карабин \"M4A1\".")
                    wait(imint.v)
                    sampSendChat("/me снял с плеча карабин")
                    while true and checkbox.v do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 31 then
                            sampSendChat("/me повесил карабин на плечо")
                            break
                        end
                    end
                elseif weapon == 33 then
                    sampSendChat("/do На плече висит охотничья винтовка.")
                    wait(imint.v)
                    sampSendChat("/me снял охотничью винтовку с плеча")
                    while true and checkbox.v do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 33 then
                            sampSendChat("/me повесил охотничью винтовку на плечо")
                            break
                        end
                    end
                elseif weapon == 34 then
                    sampSendChat("/do В руке кейс с винтовкой \"SVD\".")
                    wait(imint.v)
                    sampSendChat("/me открыв кейс, достал оттуда винтовку")
                    wait(imint.v)
                    sampSendChat("/me зарядил винтовку")
                    while true and checkbox.v do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 34 then
                            sampSendChat("/me открыл кейс")
                            wait(imint.v)
                            sampSendChat("/me положил винтовку в кейс")
                            wait(imint.v)
                            sampSendChat("/me закрыл кейс")
                            break
                        end
                    end
                end
            end
        end
    end
Почему выходят каракули? Кодировка на CP1251 и выходят каракули
это шутка?
upload_2018-7-20_18-29-34.png
 
  • Нравится
Реакции: AnWu

castlefamily

Участник
104
3
Lua:
local key = require "vkeys"
require "lib.moonloader"
local imgui = require "imgui"
local encoding = require "encoding"
encoding.default = "CP1251"
u8 = encoding.UTF8


imint = imgui.ImInt(1500)
imbool = imgui.ImBool(false)
checkbox = imgui.ImBool(false)
function imgui.OnDrawFrame()
    if imbool.v then
         imgui.SetNextWindowSize(imgui.ImVec2(500, 200), imgui.Cond.FirstUseEver)
        local sw, sh = getScreenResolution()
        imgui.SetNextWindowPos(imgui.ImVec2(sw / 2, sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.Begin("AutoRP GUN by Dmitry555", imbool)
        imgui.Checkbox("Включить/выключить автоРП отыгровку оружия", checkbox)
        imgui.SliderInt("Задержка в мс", imint, 1000, 10000)
        imgui.End()
    end
end

function main()
while not isSampAvailable() do wait(100) end
    sampRegisterChatCommand("mg", function() imbool.v = not imbool.v end)
    while true do
    wait(0)
        imgui.Process = imbool.v
        imgui.ShowCursor = imbool.v
        imgui.LockPlayer = imbool.v
            local weapon = getCurrentCharWeapon(PLAYER_PED)
            while weapon == 1 or weapon == 2 or weapon == 3 or weapon == 5 or weapon == 8 or weapon == 17 or weapon == 22 or weapon == 23 or weapon == 24 or weapon == 25 or weapon == 29 or weapon == 30 or weapon == 31 or weapon == 33 or weapon == 34 and checkbox.v == true do
            wait(0)
            imgui.Process = imbool.v
            imgui.ShowCursor = imbool.v
            imgui.LockPlayer = imbool.v
            local weapon = getCurrentCharWeapon(PLAYER_PED)
                if weapon == 1 then
                    sampSendChat("/do Кастет на руке.")
                    while true and checkbox.v == true do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 1 then
                            break
                        end
                    end
                elseif weapon == 2 then
                    sampSendChat("/do Клюшка в руке.")
                    while true and checkbox.v == true do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 2 then
                            break
                        end
                    end
                elseif weapon == 3 then
                    sampSendChat("/do Дубинка висит на поясе.")
                    wait(imint.v)
                    sampSendChat("/me снял дубинку с пояса")
                    while true and checkbox.v == true do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 3 then
                            sampSendChat("/me повесил дубинку на пояс")
                            break
                        end
                    end
                elseif weapon == 5 then
                    sampSendChat("/do Бита в руках.")
                    while true and checkbox.v do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 5 then
                            break
                        end
                    end
                elseif weapon == 8 then
                    sampSendChat("/do Катана на поясе в чехле.")
                    wait(imint.v)
                    sampSendChat("/me вытащил катану с чехла")
                    while true and checkbox.v do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 8 then
                            sampSendChat("/do Чехол для катаны на поясе.")
                            wait(imint.v)
                            sampSendChat("/me засунул катану в чехол")
                            break
                        end
                    end
                elseif weapon == 17 then
                    sampSendChat("/do Дымовая шашка в чехле на поясе.")
                    wait(imint.v)
                    sampSendChat("/me вытащил дымовую шашку")
                        while true and checkbox.v do
                        wait(0)
                        imgui.Process = imbool.v
                        imgui.ShowCursor = imbool.v
                        imgui.LockPlayer = imbool.v
                        local weapon = getCurrentCharWeapon(PLAYER_PED)
                            if weapon ~= 17 then
                                break
                            end
                        end
                elseif weapon == 22 then
                    sampSendChat("/do Пистолет \"Glock\" на поясе.")
                    wait(imint.v)
                    sampSendChat("/me вытащил пистолет \"Glock\" из кобуры")
                    while true and checkbox.v do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 22 then
                            sampSendChat("/do Кобура на поясе.")
                            wait(imint.v)
                            sampSendChat("/me засунул пистолет в кобуру")
                            break
                        end
                    end
                elseif weapon == 23 then
                    sampSendChat("/do На поясе дистанционный электрошокер.")
                    wait(imint.v)
                    sampSendChat("/me снял с пояса электрошокер")
                    while true and checkbox.v do
                    wait(0)
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    imgui.Process = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 23 then
                            sampSendChat("/do Электрошокер в руках.")
                            wait(imint.v)
                            sampSendChat("/me прикрепил электрошокер к поясу")
                            break
                        end
                    end
                elseif weapon == 24 then
                    sampSendChat(u8"/do В кобуре пистолет \"Пустынный ястреб\".")
                    wait(imint.v)
                    sampSendChat(u8"/me достал пистолет из кобуры")
                    while true and checkbox.v do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 24 then
                            sampSendChat("/do Кобура на поясе.")
                            wait(imint.v)
                            sampSendChat("/me засунул пистолет в кобуру")
                            break
                        end
                    end
                elseif weapon == 25 then
                    sampSendChat("/do На плече весит дробовик \"Remington\".")
                    wait(imint.v)
                    sampSendChat("/me снял с плеча дробовик")
                    while true and checkbox.v do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 25 then
                            sampSendChat("/me повесил дробовик на плечо")
                            break
                        end
                    end
                elseif weapon == 29 then
                    sampSendChat("/do На плече весит пистолет-пулемёт \"MP-5\".")
                    wait(imint.v)
                    sampSendChat("/me снял с плеча пистолет-пулемёт")
                    while true and checkbox.v do
                    wait(0)
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    imgui.Process = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 29 then
                            sampSendChat("/me повесил пистолет-пулемёт на плечо")
                            break
                        end
                    end
                elseif weapon == 30 then
                    sampSendChat("/do На плече весит автомат \"АК-47\".")
                    wait(imint.v)
                    sampSendChat("/me снял с плеча автомат")
                    while true and checkbox.v do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 30 then
                            sampSendChat("/me повесил автомат на плечо")
                            break
                        end
                    end
                elseif weapon == 31 then
                    sampSendChat("/do На плече висит карабин \"M4A1\".")
                    wait(imint.v)
                    sampSendChat("/me снял с плеча карабин")
                    while true and checkbox.v do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 31 then
                            sampSendChat("/me повесил карабин на плечо")
                            break
                        end
                    end
                elseif weapon == 33 then
                    sampSendChat("/do На плече висит охотничья винтовка.")
                    wait(imint.v)
                    sampSendChat("/me снял охотничью винтовку с плеча")
                    while true and checkbox.v do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 33 then
                            sampSendChat("/me повесил охотничью винтовку на плечо")
                            break
                        end
                    end
                elseif weapon == 34 then
                    sampSendChat("/do В руке кейс с винтовкой \"SVD\".")
                    wait(imint.v)
                    sampSendChat("/me открыв кейс, достал оттуда винтовку")
                    wait(imint.v)
                    sampSendChat("/me зарядил винтовку")
                    while true and checkbox.v do
                    wait(0)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 34 then
                            sampSendChat("/me открыл кейс")
                            wait(imint.v)
                            sampSendChat("/me положил винтовку в кейс")
                            wait(imint.v)
                            sampSendChat("/me закрыл кейс")
                            break
                        end
                    end
                end
            end
        end
    end
Почему выходят каракули? Кодировка на CP1251 и выходят каракули
Везде где русские слова используешь в imgui u8 пиши
imgui.Checkbox(u8"Включить/выключить автоРП отыгровку оружия", checkbox)
 

ШPEK

Известный
1,476
524
Ещё вопрос, почему скрипт игнорирует checkbox.v == true на 32 строке?
Lua:
local key = require "vkeys"
require "lib.moonloader"
local imgui = require "imgui"
local encoding = require 'encoding' -- загружаем библиотеку
encoding.default = 'CP1251' -- указываем кодировку по умолчанию, она должна совпадать с кодировкой файла. CP1251 - это Windows-1251
u8 = encoding.UTF8 -- и создаём

local imint = imgui.ImInt(3000)
local imbool = imgui.ImBool(false)
local checkbox = imgui.ImBool(true)
function imgui.OnDrawFrame()
    if imbool.v then
         imgui.SetNextWindowSize(imgui.ImVec2(500, 200), imgui.Cond.FirstUseEver)
        local sw, sh = getScreenResolution()
        imgui.SetNextWindowPos(imgui.ImVec2(sw / 2, sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.Begin(u8("AutoRP GUN by Dmitry555"), imbool)
        imgui.Checkbox(u8("Включить/выключить автоРП отыгровку оружия"), checkbox)
        imgui.SliderInt(u8("Задержка в мс"), imint, 1000, 10000)
        imgui.End()
    end
end

function main()
while not isSampAvailable() do wait(100) end
    sampRegisterChatCommand("mg", function() imbool.v = not imbool.v end)
    while true do
    wait(imint.v)
        imgui.Process = imbool.v
        imgui.ShowCursor = imbool.v
        imgui.LockPlayer = imbool.v
            local weapon = getCurrentCharWeapon(PLAYER_PED)
            while checkbox.v == true and weapon == 1 or weapon == 2 or weapon == 3 or weapon == 5 or weapon == 8 or weapon == 17 or weapon == 22 or weapon == 23 or weapon == 24 or weapon == 25 or weapon == 29 or weapon == 30 or weapon == 31 or weapon == 33 or weapon == 34 do
            wait(imint.v)
            imgui.Process = imbool.v
            imgui.ShowCursor = imbool.v
            imgui.LockPlayer = imbool.v
            local weapon = getCurrentCharWeapon(PLAYER_PED)
                if weapon == 1 then
                    sampSendChat("/do Кастет на руке.")
                    while true and checkbox.v == true do
                    wait(imint.v)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 1 then
                            break
                        end
                    end
                elseif weapon == 2 then
                    sampSendChat("/do Клюшка в руке.")
                    while true and checkbox.v == true do
                    wait(imint.v)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 2 then
                            break
                        end
                    end  
                elseif weapon == 3 then
                    sampSendChat("/do Дубинка висит на поясе.")
                    wait(imint.v)
                    sampSendChat("/me снял дубинку с пояса")
                    while true and checkbox.v == true do
                    wait(imint.v)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 3 then
                            sampSendChat("/me повесил дубинку на пояс")
                            break
                        end
                    end
                elseif weapon == 5 then
                    sampSendChat("/do Бита в руках.")
                    while true and checkbox.v do
                    wait(imint.v)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 5 then
                            break
                        end
                    end
                elseif weapon == 8 then
                    sampSendChat("/do Катана на поясе в чехле.")
                    wait(imint.v)
                    sampSendChat("/me вытащил катану с чехла")
                    while true and checkbox.v do
                    wait(imint.v)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 8 then
                            sampSendChat("/do Чехол для катаны на поясе.")
                            wait(imint.v)
                            sampSendChat("/me засунул катану в чехол")
                            break
                        end
                    end
                elseif weapon == 17 then
                    sampSendChat("/do Дымовая шашка в чехле на поясе.")
                    wait(imint.v)
                    sampSendChat("/me вытащил дымовую шашку")
                        while true and checkbox.v do
                        wait(imint.v)
                        imgui.Process = imbool.v
                        imgui.ShowCursor = imbool.v
                        imgui.LockPlayer = imbool.v
                        local weapon = getCurrentCharWeapon(PLAYER_PED)
                            if weapon ~= 17 then
                                break
                            end
                        end
                elseif weapon == 22 then
                    sampSendChat("/do Пистолет \"Glock\" на поясе.")
                    wait(imint.v)
                    sampSendChat("/me вытащил пистолет \"Glock\" из кобуры")
                    while true and checkbox.v do
                    wait(imint.v)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 22 then
                            sampSendChat("/do Кобура на поясе.")
                            wait(imint.v)
                            sampSendChat("/me засунул пистолет в кобуру")
                            break
                        end
                    end
                elseif weapon == 23 then
                    sampSendChat("/do На поясе дистанционный электрошокер.")
                    wait(imint.v)
                    sampSendChat("/me снял с пояса электрошокер")
                    while true and checkbox.v do
                    wait(imint.v)
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    imgui.Process = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 23 then
                            sampSendChat("/do Электрошокер в руках.")
                            wait(imint.v)
                            sampSendChat("/me прикрепил электрошокер к поясу")
                            break
                        end
                    end
                elseif weapon == 24 then
                    sampSendChat("/do В кобуре пистолет \"Пустынный ястреб\".")
                    wait(imint.v)
                    sampSendChat("/me достал пистолет из кобуры")
                    while true and checkbox.v do
                    wait(imint.v)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 24 then
                            sampSendChat("/do Кобура на поясе.")
                            wait(imint.v)
                            sampSendChat("/me засунул пистолет в кобуру")
                            break
                        end
                    end
                elseif weapon == 25 then
                    sampSendChat("/do На плече весит дробовик \"Remington\".")
                    wait(imint.v)
                    sampSendChat("/me снял с плеча дробовик")
                    while true and checkbox.v do
                    wait(imint.v)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 25 then
                            sampSendChat("/me повесил дробовик на плечо")
                            break
                        end
                    end
                elseif weapon == 29 then
                    sampSendChat("/do На плече весит пистолет-пулемёт \"MP-5\".")
                    wait(imint.v)
                    sampSendChat("/me снял с плеча пистолет-пулемёт")
                    while true and checkbox.v do
                    wait(imint.v)
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    imgui.Process = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 29 then
                            sampSendChat("/me повесил пистолет-пулемёт на плечо")
                            break
                        end
                    end
                elseif weapon == 30 then
                    sampSendChat("/do На плече весит автомат \"АК-47\".")
                    wait(imint.v)
                    sampSendChat("/me снял с плеча автомат")
                    while true and checkbox.v do
                    wait(imint.v)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 30 then
                            sampSendChat("/me повесил автомат на плечо")
                            break
                        end
                    end
                elseif weapon == 31 then
                    sampSendChat("/do На плече висит карабин \"M4A1\".")
                    wait(imint.v)
                    sampSendChat("/me снял с плеча карабин")
                    while true and checkbox.v do
                    wait(imint.v)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 31 then
                            sampSendChat("/me повесил карабин на плечо")
                            break
                        end
                    end
                elseif weapon == 33 then
                    sampSendChat("/do На плече висит охотничья винтовка.")
                    wait(imint.v)
                    sampSendChat("/me снял охотничью винтовку с плеча")
                    while true and checkbox.v do
                    wait(imint.v)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 33 then
                            sampSendChat("/me повесил охотничью винтовку на плечо")
                            break
                        end
                    end
                elseif weapon == 34 then
                    sampSendChat("/do В руке кейс с винтовкой \"SVD\".")
                    wait(imint.v)
                    sampSendChat("/me открыв кейс, достал оттуда винтовку")
                    wait(imint.v)
                    sampSendChat("/me зарядил винтовку")
                    while true and checkbox.v do
                    wait(imint.v)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 34 then
                            sampSendChat("/me открыл кейс")
                            wait(imint.v)
                            sampSendChat("/me положил винтовку в кейс")
                            wait(imint.v)
                            sampSendChat("/me закрыл кейс")
                            break
                        end
                    end
                end
            end
        end
    end
 

AnWu

Guardian of Order
Всефорумный модератор
4,687
5,166
Ещё вопрос, почему скрипт игнорирует checkbox.v == true на 32 строке?
Lua:
local key = require "vkeys"
require "lib.moonloader"
local imgui = require "imgui"
local encoding = require 'encoding' -- загружаем библиотеку
encoding.default = 'CP1251' -- указываем кодировку по умолчанию, она должна совпадать с кодировкой файла. CP1251 - это Windows-1251
u8 = encoding.UTF8 -- и создаём

local imint = imgui.ImInt(3000)
local imbool = imgui.ImBool(false)
local checkbox = imgui.ImBool(true)
function imgui.OnDrawFrame()
    if imbool.v then
         imgui.SetNextWindowSize(imgui.ImVec2(500, 200), imgui.Cond.FirstUseEver)
        local sw, sh = getScreenResolution()
        imgui.SetNextWindowPos(imgui.ImVec2(sw / 2, sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.Begin(u8("AutoRP GUN by Dmitry555"), imbool)
        imgui.Checkbox(u8("Включить/выключить автоРП отыгровку оружия"), checkbox)
        imgui.SliderInt(u8("Задержка в мс"), imint, 1000, 10000)
        imgui.End()
    end
end

function main()
while not isSampAvailable() do wait(100) end
    sampRegisterChatCommand("mg", function() imbool.v = not imbool.v end)
    while true do
    wait(imint.v)
        imgui.Process = imbool.v
        imgui.ShowCursor = imbool.v
        imgui.LockPlayer = imbool.v
            local weapon = getCurrentCharWeapon(PLAYER_PED)
            while checkbox.v == true and weapon == 1 or weapon == 2 or weapon == 3 or weapon == 5 or weapon == 8 or weapon == 17 or weapon == 22 or weapon == 23 or weapon == 24 or weapon == 25 or weapon == 29 or weapon == 30 or weapon == 31 or weapon == 33 or weapon == 34 do
            wait(imint.v)
            imgui.Process = imbool.v
            imgui.ShowCursor = imbool.v
            imgui.LockPlayer = imbool.v
            local weapon = getCurrentCharWeapon(PLAYER_PED)
                if weapon == 1 then
                    sampSendChat("/do Кастет на руке.")
                    while true and checkbox.v == true do
                    wait(imint.v)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 1 then
                            break
                        end
                    end
                elseif weapon == 2 then
                    sampSendChat("/do Клюшка в руке.")
                    while true and checkbox.v == true do
                    wait(imint.v)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 2 then
                            break
                        end
                    end 
                elseif weapon == 3 then
                    sampSendChat("/do Дубинка висит на поясе.")
                    wait(imint.v)
                    sampSendChat("/me снял дубинку с пояса")
                    while true and checkbox.v == true do
                    wait(imint.v)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 3 then
                            sampSendChat("/me повесил дубинку на пояс")
                            break
                        end
                    end
                elseif weapon == 5 then
                    sampSendChat("/do Бита в руках.")
                    while true and checkbox.v do
                    wait(imint.v)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 5 then
                            break
                        end
                    end
                elseif weapon == 8 then
                    sampSendChat("/do Катана на поясе в чехле.")
                    wait(imint.v)
                    sampSendChat("/me вытащил катану с чехла")
                    while true and checkbox.v do
                    wait(imint.v)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 8 then
                            sampSendChat("/do Чехол для катаны на поясе.")
                            wait(imint.v)
                            sampSendChat("/me засунул катану в чехол")
                            break
                        end
                    end
                elseif weapon == 17 then
                    sampSendChat("/do Дымовая шашка в чехле на поясе.")
                    wait(imint.v)
                    sampSendChat("/me вытащил дымовую шашку")
                        while true and checkbox.v do
                        wait(imint.v)
                        imgui.Process = imbool.v
                        imgui.ShowCursor = imbool.v
                        imgui.LockPlayer = imbool.v
                        local weapon = getCurrentCharWeapon(PLAYER_PED)
                            if weapon ~= 17 then
                                break
                            end
                        end
                elseif weapon == 22 then
                    sampSendChat("/do Пистолет \"Glock\" на поясе.")
                    wait(imint.v)
                    sampSendChat("/me вытащил пистолет \"Glock\" из кобуры")
                    while true and checkbox.v do
                    wait(imint.v)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 22 then
                            sampSendChat("/do Кобура на поясе.")
                            wait(imint.v)
                            sampSendChat("/me засунул пистолет в кобуру")
                            break
                        end
                    end
                elseif weapon == 23 then
                    sampSendChat("/do На поясе дистанционный электрошокер.")
                    wait(imint.v)
                    sampSendChat("/me снял с пояса электрошокер")
                    while true and checkbox.v do
                    wait(imint.v)
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    imgui.Process = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 23 then
                            sampSendChat("/do Электрошокер в руках.")
                            wait(imint.v)
                            sampSendChat("/me прикрепил электрошокер к поясу")
                            break
                        end
                    end
                elseif weapon == 24 then
                    sampSendChat("/do В кобуре пистолет \"Пустынный ястреб\".")
                    wait(imint.v)
                    sampSendChat("/me достал пистолет из кобуры")
                    while true and checkbox.v do
                    wait(imint.v)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 24 then
                            sampSendChat("/do Кобура на поясе.")
                            wait(imint.v)
                            sampSendChat("/me засунул пистолет в кобуру")
                            break
                        end
                    end
                elseif weapon == 25 then
                    sampSendChat("/do На плече весит дробовик \"Remington\".")
                    wait(imint.v)
                    sampSendChat("/me снял с плеча дробовик")
                    while true and checkbox.v do
                    wait(imint.v)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 25 then
                            sampSendChat("/me повесил дробовик на плечо")
                            break
                        end
                    end
                elseif weapon == 29 then
                    sampSendChat("/do На плече весит пистолет-пулемёт \"MP-5\".")
                    wait(imint.v)
                    sampSendChat("/me снял с плеча пистолет-пулемёт")
                    while true and checkbox.v do
                    wait(imint.v)
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    imgui.Process = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 29 then
                            sampSendChat("/me повесил пистолет-пулемёт на плечо")
                            break
                        end
                    end
                elseif weapon == 30 then
                    sampSendChat("/do На плече весит автомат \"АК-47\".")
                    wait(imint.v)
                    sampSendChat("/me снял с плеча автомат")
                    while true and checkbox.v do
                    wait(imint.v)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 30 then
                            sampSendChat("/me повесил автомат на плечо")
                            break
                        end
                    end
                elseif weapon == 31 then
                    sampSendChat("/do На плече висит карабин \"M4A1\".")
                    wait(imint.v)
                    sampSendChat("/me снял с плеча карабин")
                    while true and checkbox.v do
                    wait(imint.v)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 31 then
                            sampSendChat("/me повесил карабин на плечо")
                            break
                        end
                    end
                elseif weapon == 33 then
                    sampSendChat("/do На плече висит охотничья винтовка.")
                    wait(imint.v)
                    sampSendChat("/me снял охотничью винтовку с плеча")
                    while true and checkbox.v do
                    wait(imint.v)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 33 then
                            sampSendChat("/me повесил охотничью винтовку на плечо")
                            break
                        end
                    end
                elseif weapon == 34 then
                    sampSendChat("/do В руке кейс с винтовкой \"SVD\".")
                    wait(imint.v)
                    sampSendChat("/me открыв кейс, достал оттуда винтовку")
                    wait(imint.v)
                    sampSendChat("/me зарядил винтовку")
                    while true and checkbox.v do
                    wait(imint.v)
                    imgui.Process = imbool.v
                    imgui.ShowCursor = imbool.v
                    imgui.LockPlayer = imbool.v
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                        if weapon ~= 34 then
                            sampSendChat("/me открыл кейс")
                            wait(imint.v)
                            sampSendChat("/me положил винтовку в кейс")
                            wait(imint.v)
                            sampSendChat("/me закрыл кейс")
                            break
                        end
                    end
                end
            end
        end
    end
Потому-что код ебанутый. Зачем там вообще while.
 

samespoon

Известный
163
20
Пытаюсь переводить текст с помощью API Яндекс Переводчика, но из-за того, что ответ я получаю в UTF-8 кодировке вместо текста мне приходят каракули. Пытаюсь с помощью муновской библиотеки "encoding" преобразовать его в "Windows 1251", но на выходе всё-равно получаю каракули. Подскажите, как мне преобразовать "UTF-8" в "Windows 1251"?
Lua:
    sampRegisterChatCommand('translate', function(text)
        local text = string.gsub(text, ' ', '+')
        async_http_request('GET', 'https://translate.yandex.net/api/v1.5/tr.json/translate?key=' ..key.. '&text='..text..'&lang=ru', nil,
          function(response) -- вызовется при успешном выполнении и получении ответа
                local tttext = cjson.decode(response.text)
                print(u8(response.text)) -- u8 всё равно даёт каракули, но уже отличающиеся от исходных
                notf.addNotification(u8(tttext.text[1]), 2.5)
            end,
          function(err) -- вызовется при ошибке, err - текст ошибки. эту функцию можно не указывать
            print(err)
          end)
    end)
Повторю свой вопрос.
 

Petr_Sergeevich

Известный
Проверенный
707
296
if isKeyJustPressed(0x27) then -- RIGHT ARROW key
-- Code here
end

При нажатии на данную клавишу, выполняется определенный кусок кода, но срабатывает перемещение игрока в сторону после нажатия стрелки вправо. Как на этот небольшой промежуток времени запретить игроку двигаться?
 

deddosouru

Смотрю аниме, служу Сатане
Друг
2,036
1,319
господа.
в емгуй нужна кнопка с текстурой. в идеале чтобы просто можно было сделать кликабельную пикчу. желательно с примером. шрифты вроде font awesome не предлагать