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

PanSeek

t.me/dailypanseek
Всефорумный модератор
899
1,747
Почему не появляется imgui окно?


код:
local window_mess = imgui.ImBool(false)

if window_mess.v then
        imgui.LockPlayer = true
        imgui.SetNextWindowPos(imgui.ImVec2(sw/2, sh/2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 1))
        imgui.SetNextWindowSize(imgui.ImVec2(sw/1.3, sh/1.05), imgui.Cond.FirstUseEver)
        imgui.Begin(u8"Быстрые сообщения /mess", window_mess)
        if imgui.CollapsingHeader(u8"Сторонние Программы") then
       
        end
        imgui.End()
    end
   
sampRegisterChatCommand("fmess", function()
    window_mess.v = not window_mess.v
    imgui.Process = window_mess.v
    end)
Если не изменяет память, то imgui.Process = window_mess.v нужно добавить в бесконечный цикл - while true do
 
  • Нравится
Реакции: James Saula

Corrygаn

Участник
225
6
Как лучше реализовать меню имгуи? Я хочу слева были пункты и при нажатии на каждый появлялась определённая менюшка, это лучше через несколько imgui.Button или есть какие-то другие функции?
 

Corrygаn

Участник
225
6
Lua:
local imgui = require('imgui')
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
local ffi = require "ffi"
local getBonePosition = ffi.cast("int (__thiscall*)(void*, float*, int, bool)", 0x5E4280)

local skeletal_wh = imgui.ImBool(false)
local window = imgui.ImBool(false)

function main()
    while not isSampAvailable() do wait(200) end
    imgui.Process = false
    window.v = true  --show window
    while true do
        wait(0)
        imgui.Process = window.v
        if skeletal_wh.v then bonewh() end
    end
end

function imgui.OnDrawFrame()
    if window.v then
        imgui.SetNextWindowPos(imgui.ImVec2(350.0, 250.0), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowSize(imgui.ImVec2(280.0, 70.0), imgui.Cond.FirstUseEver)
        imgui.Begin('Window Title', window)

        imgui.Checkbox('wh', skeletal_wh)

        imgui.End()
    end
end

function bonewh()
    lua_thread.create(function()
        for k, i in ipairs(getAllChars()) do
            if not ch_wh_workonme.v then
                pedX, pedY, pedZ = getCharCoordinates(i)
                myX, myY, myZ = getCharCoordinates(PLAYER_PED)
                distance = getDistanceBetweenCoords3d(pedX, pedY, pedZ, myX, myY, myZ)
              
                if doesCharExist(i) and isCharOnScreen(i) and i ~= PLAYER_PED then
                    _, id = sampGetPlayerIdByCharHandle(i)
                    local color = sampGetPlayerColor(id)
                    local aa, rr, gg, bb = explode_argb(color)
                    local color = join_argb(255, rr, gg, bb)
  
                    thickness = 3 --толщина
                  
                    pos1X, pos1Y, pos1Z = getBodyPartCoordinates(6, i)
                    pos2X, pos2Y, pos2Z = getBodyPartCoordinates(7, i)
                  
                    pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
                    pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
                    renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
  
                    pos1X, pos1Y, pos1Z = getBodyPartCoordinates(7, i)
                    pos2X, pos2Y, pos2Z = getBodyPartCoordinates(8, i)
                  
                    pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
                    pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
                    renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
  
                    pos1X, pos1Y, pos1Z = getBodyPartCoordinates(8, i)
                    pos2X, pos2Y, pos2Z = getBodyPartCoordinates(6, i)
                  
                    pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
                    pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
                    renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
                  
                  
                  
                    pos1X, pos1Y, pos1Z = getBodyPartCoordinates(1, i)
                    pos2X, pos2Y, pos2Z = getBodyPartCoordinates(4, i)
                  
                    pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
                    pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
                    renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
  
                    pos1X, pos1Y, pos1Z = getBodyPartCoordinates(4, i)
                    pos2X, pos2Y, pos2Z = getBodyPartCoordinates(8, i)
                  
                    pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
                    pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
                    renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
                  
  
                  
                    pos1X, pos1Y, pos1Z = getBodyPartCoordinates(21, i)
                    pos2X, pos2Y, pos2Z = getBodyPartCoordinates(22, i)
                  
                    pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
                    pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
                    renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
  
                    pos1X, pos1Y, pos1Z = getBodyPartCoordinates(22, i)
                    pos2X, pos2Y, pos2Z = getBodyPartCoordinates(23, i)
                  
                    pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
                    pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
                    renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
  
                    pos1X, pos1Y, pos1Z = getBodyPartCoordinates(23, i)
                    pos2X, pos2Y, pos2Z = getBodyPartCoordinates(24, i)
                  
                    pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
                    pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
                    renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
  
                    pos1X, pos1Y, pos1Z = getBodyPartCoordinates(24, i)
                    pos2X, pos2Y, pos2Z = getBodyPartCoordinates(25, i)
                  
                    pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
                    pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
                    renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
                  
  
                  
                    pos1X, pos1Y, pos1Z = getBodyPartCoordinates(31, i)
                    pos2X, pos2Y, pos2Z = getBodyPartCoordinates(32, i)
                  
                    pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
                    pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
                    renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
  
                    pos1X, pos1Y, pos1Z = getBodyPartCoordinates(32, i)
                    pos2X, pos2Y, pos2Z = getBodyPartCoordinates(33, i)
                  
                    pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
                    pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
                    renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
  
                    pos1X, pos1Y, pos1Z = getBodyPartCoordinates(33, i)
                    pos2X, pos2Y, pos2Z = getBodyPartCoordinates(34, i)
                  
                    pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
                    pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
                    renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
  
                    pos1X, pos1Y, pos1Z = getBodyPartCoordinates(34, i)
                    pos2X, pos2Y, pos2Z = getBodyPartCoordinates(35, i)
                  
                    pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
                    pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
                    renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
                  
  
                  
                    pos1X, pos1Y, pos1Z = getBodyPartCoordinates(1, i)
                    pos2X, pos2Y, pos2Z = getBodyPartCoordinates(51, i)
                  
                    pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
                    pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
                    renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
                    pos1X, pos1Y, pos1Z = getBodyPartCoordinates(51, i)
                    pos2X, pos2Y, pos2Z = getBodyPartCoordinates(52, i)
                  
                    pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
                    pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
                    renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
  
                    pos1X, pos1Y, pos1Z = getBodyPartCoordinates(52, i)
                    pos2X, pos2Y, pos2Z = getBodyPartCoordinates(53, i)
                  
                    pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
                    pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
                    renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
  
                    pos1X, pos1Y, pos1Z = getBodyPartCoordinates(53, i)
                    pos2X, pos2Y, pos2Z = getBodyPartCoordinates(54, i)
                  
                    pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
                    pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
                    renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
                  
  
                  
                    pos1X, pos1Y, pos1Z = getBodyPartCoordinates(1, i)
                    pos2X, pos2Y, pos2Z = getBodyPartCoordinates(41, i)
                  
                    pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
                    pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
                    renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
  
                    pos1X, pos1Y, pos1Z = getBodyPartCoordinates(41, i)
                    pos2X, pos2Y, pos2Z = getBodyPartCoordinates(42, i)
                  
                    pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
                    pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
                    renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
  
                    pos1X, pos1Y, pos1Z = getBodyPartCoordinates(42, i)
                    pos2X, pos2Y, pos2Z = getBodyPartCoordinates(43, i)
                  
                    pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
                    pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
                    renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
  
                    pos1X, pos1Y, pos1Z = getBodyPartCoordinates(43, i)
                    pos2X, pos2Y, pos2Z = getBodyPartCoordinates(44, i)
                  
                    pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
                    pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
                    renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)

                    pos2X, pos2Y, pos2Z = getBodyPartCoordinates(44, i)
                    pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
                    renderDrawPolygon(pos3, pos4, thickness, thickness, 100, 0, color)
                  
                end
            end
          
        end
    end)
end

function getBodyPartCoordinates(id, handle)
    if doesCharExist(handle) then
        local pedptr = getCharPointer(handle)
        local vec = ffi.new("float[3]")
        getBonePosition(ffi.cast("void*", pedptr), vec, id, true)
        return vec[0], vec[1], vec[2]
    end
end
ch_wh_workonme? Тут ошибочка. D:\ARIZONA GAMES\bin\Arizona\moonloader\MVD Helper.lua:161: attempt to index global 'ch_wh_workonme' (a nil value)
 

tsunamiqq

Участник
429
16
Lua:
function imgui.OnDrawFrame()
local iScreenWidth, iScreenHeight = getScreenResolution()
local btn_size = imgui.ImVec2(-1, 0)
    if main_window_state.v then
    imgui.SetNextWindowSize(imgui.ImVec2(1000, 500), imgui.Cond.FirstUseEver)
    imgui.Begin('Family Helper by Nakamura', main_window_state, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse)
    imgui.BeginChild('##121', imgui.ImVec2(200, 465), true)
    if imgui.Button(u8'Управление участниками', imgui.ImVec2(-1, 53)) then menu = 0 end
    if imgui.Button(u8'Для участников/nСемей', imgui.ImVec2(-1, 53)) then menu = 1 end
    if imgui.Button(u8'Для лидеров/nзамов', imgui.ImVec2(-1, 53)) then menu = 2 end
    if imgui.Button(u8'Биндер', imgui.ImVec2(-1, 53)) then menu = 3 end
    if imgui.Button(u8'Правила', imgui.ImVec2(-1, 53)) then menu = 4 end
    if imgui.Button(u8'CMD list', imgui.ImVec2(-1, 53)) then menu = 5 end
    if imgui.Button(u8'Настройки', imgui.ImVec2(-1, 53)) then menu = 6 end
    if imgui.Button(u8'О скрипте', imgui.ImVec2(-1, 53)) then menu = 7 end
    imgui.EndChild()
    imgui.SameLine()
    if menu == 0 then
        imgui.BeginChild('##once', imgui.ImVec2(775, 465), true)
        imgui.Text('')
        imgui.EndChild()
    elseif menu == 1 then
        imgui.BeginChild('##twice', imgui.ImVec2(775, 465), true)
        imgui.Text('')
        imgui.EndChild()
    elseif menu == 2 then
        imgui.BeginChild('##twice', imgui.ImVec2(775, 465), true)
        imgui.Text('')
        imgui.EndChild()
    elseif menu == 3 then
        imgui.BeginChild('##twice', imgui.ImVec2(775, 465), true)
        imgui.Text('')
        imgui.EndChild()
    elseif menu == 4 then
        imgui.BeginChild('##twice', imgui.ImVec2(775, 465), true)
        imgui.Text('')
        imgui.EndChild()
    elseif menu == 5 then
        imgui.BeginChild('##twice', imgui.ImVec2(775, 465), true)
        imgui.Text('')
        imgui.EndChild()
    elseif menu == 6 then
        imgui.BeginChild('##twice', imgui.ImVec2(775, 465), true)
        imgui.Text('')
        imgui.EndChild()
    elseif menu == 7 then
        imgui.BeginChild('##twice', imgui.ImVec2(775, 465), true)
        imgui.Text('Автор скрипта: Tsunami_Nakamura. Помощник: Adam_Karleone', main_window_state)
        imgui.Text('ВК - @lcn.maks', main_window_state)
        imgui.Text('Пишите в вк о багам, или предложением к обновлению.', main_window_state)
        imgui.Text('Скрипт сделан для Семей, не более.', main_window_state)
        imgui.EndChild()
    end
    imgui.End()
    end
Как сделать автологин, в 6 меню над, помогите плс
 

Dmitriy Makarov

25.05.2021
Проверенный
2,484
1,114
Как лучше реализовать меню имгуи? Я хочу слева были пункты и при нажатии на каждый появлялась определённая менюшка, это лучше через несколько imgui.Button или есть какие-то другие функции?
 

PanSeek

t.me/dailypanseek
Всефорумный модератор
899
1,747
Как лучше реализовать меню имгуи? Я хочу слева были пункты и при нажатии на каждый появлялась определённая менюшка, это лучше через несколько imgui.Button или есть какие-то другие функции?
Lua:
local tab = 0
--onDrawFrame
imgui.Begin(--[[твои аргументы]])
imgui.BeginChild(--[[твои аргументы]]) -- можно и с чайлдом, можно и без него
if imgui.Button('1') then tab = 1 end
if imgui.Button('2') then tab = 2 end
imgui.SameLine()
if tab == 1 then
    imgui.BeginChild(--[[args]])
    imgui.Text('test')
    imgui.EndChild()
elseif tab == 2 then
    -- code
end
imgui.EndChild() -- если используешь чайлд для кнопок слева
imgui.End()
 
  • Нравится
Реакции: James Saula

KewkHackers

Новичок
2
0
Lua:
lua_thread.create(function()
    while true do
        wait(0)
        for _, obj_hand in pairs(getAllObjects()) do
            local modelid = getObjectModel(obj_hand)
            if modelid == 1583 then
                if isObjectOnScreen(obj_hand) then
                    local x,y,z = getCharCoordinates(PLAYER_PED)
                    local res,x1,y1,z1 = getObjectCoordinates(obj_hand)
                    local weapon = getCurrentCharWeapon(PLAYER_PED)
                    if res then
                        BulletSync(3, obj_hand, x1, y1, z1, x, y, z, 0, 0, 0.5, weapon)
                    end
                end
            end
        end
    end
end)

function BulletSync(slot0, slot1, slot2, slot3, slot4, slot5, slot6, slot7, slot8, slot9, slot10, slot11)
    slot12 = allocateMemory(40)

    setStructElement(slot12, 0, 1, slot0)
    setStructElement(slot12, 1, 2, slot1)
    setStructElement(slot12, 3, 4, representFloatAsInt(slot2))
    setStructElement(slot12, 7, 4, representFloatAsInt(slot3))
    setStructElement(slot12, 11, 4, representFloatAsInt(slot4))
    setStructElement(slot12, 15, 4, representFloatAsInt(slot5))
    setStructElement(slot12, 19, 4, representFloatAsInt(slot6))
    setStructElement(slot12, 23, 4, representFloatAsInt(slot7))
    setStructElement(slot12, 27, 4, representFloatAsInt(slot8))
    setStructElement(slot12, 31, 4, representFloatAsInt(slot9))
    setStructElement(slot12, 35, 4, representFloatAsInt(slot10))
    setStructElement(slot12, 39, 1, slot11)
    sampSendBulletData(slot12)
    freeMemory(slot12)
end
Why this wont send any bullet to object? i think i did everything right.
Bump
 

chapo

🫡 В армии с 17.10.2023. В ЛС НЕ ОТВЕЧАЮ
Друг
8,776
11,231
Так я удалил, теперь оно ругается на эту строку D:\ARIZONA GAMES\bin\Arizona\moonloader\MVD Helper.lua:169: attempt to call global 'explode_argb' (a nil value)

local aa, rr, gg, bb = explode_argb(color)
Lua:
local imgui = require('imgui')
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
local ffi = require "ffi"
local getBonePosition = ffi.cast("int (__thiscall*)(void*, float*, int, bool)", 0x5E4280)

local skeletal_wh = imgui.ImBool(false)
local window = imgui.ImBool(false)

function main()
    while not isSampAvailable() do wait(200) end
    imgui.Process = false
    window.v = true  --show window
    while true do
        wait(0)
        imgui.Process = window.v
        if skeletal_wh.v then boneWh() end
    end
end

function imgui.OnDrawFrame()
    if window.v then
        imgui.SetNextWindowPos(imgui.ImVec2(350.0, 250.0), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowSize(imgui.ImVec2(280.0, 70.0), imgui.Cond.FirstUseEver)
        imgui.Begin('Window Title', window)

        imgui.Checkbox('wh', skeletal_wh)

        imgui.End()
    end
end

function join_argb(a, r, g, b)
    local argb = b  -- b
    argb = bit.bor(argb, bit.lshift(g, 8))  -- g
    argb = bit.bor(argb, bit.lshift(r, 16)) -- r
    argb = bit.bor(argb, bit.lshift(a, 24)) -- a
    return argb
  end
 
  function explode_argb(argb)
    local a = bit.band(bit.rshift(argb, 24), 0xFF)
    local r = bit.band(bit.rshift(argb, 16), 0xFF)
    local g = bit.band(bit.rshift(argb, 8), 0xFF)
    local b = bit.band(argb, 0xFF)
    return a, r, g, b
  end

function bonewh()
    lua_thread.create(function()
        for k, i in ipairs(getAllChars()) do
            pedX, pedY, pedZ = getCharCoordinates(i)
            myX, myY, myZ = getCharCoordinates(PLAYER_PED)
            ance = getDistanceBetweenCoords3d(pedX, pedY, pedZ, myX, myY, myZ)
            
            oesCharExist(i) and isCharOnScreen(i) and i ~= PLAYER_PED then
            _, id = sampGetPlayerIdByCharHandle(i)
            local color = sampGetPlayerColor(id)
            local aa, rr, gg, bb = explode_argb(color)
            local color = join_argb(255, rr, gg, bb)
    
            thickness = 3 --толщина
            
            pos1X, pos1Y, pos1Z = getBodyPartCoordinates(6, i)
            pos2X, pos2Y, pos2Z = getBodyPartCoordinates(7, i)
            
            pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
            pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
            renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
    
            pos1X, pos1Y, pos1Z = getBodyPartCoordinates(7, i)
            pos2X, pos2Y, pos2Z = getBodyPartCoordinates(8, i)
            
            pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
            pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
            renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
    
            pos1X, pos1Y, pos1Z = getBodyPartCoordinates(8, i)
            pos2X, pos2Y, pos2Z = getBodyPartCoordinates(6, i)
            
            pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
            pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
            renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
            
            
            
            pos1X, pos1Y, pos1Z = getBodyPartCoordinates(1, i)
            pos2X, pos2Y, pos2Z = getBodyPartCoordinates(4, i)
            
            pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
            pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
            renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
    
            pos1X, pos1Y, pos1Z = getBodyPartCoordinates(4, i)
            pos2X, pos2Y, pos2Z = getBodyPartCoordinates(8, i)
            
            pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
            pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
            renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
            
    
            
            pos1X, pos1Y, pos1Z = getBodyPartCoordinates(21, i)
            pos2X, pos2Y, pos2Z = getBodyPartCoordinates(22, i)
            
            pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
            pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
            renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
    
            pos1X, pos1Y, pos1Z = getBodyPartCoordinates(22, i)
            pos2X, pos2Y, pos2Z = getBodyPartCoordinates(23, i)
            
            pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
            pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
            renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
    
            pos1X, pos1Y, pos1Z = getBodyPartCoordinates(23, i)
            pos2X, pos2Y, pos2Z = getBodyPartCoordinates(24, i)
            
            pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
            pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
            renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
    
            pos1X, pos1Y, pos1Z = getBodyPartCoordinates(24, i)
            pos2X, pos2Y, pos2Z = getBodyPartCoordinates(25, i)
            
            pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
            pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
            renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
            
    
            
            pos1X, pos1Y, pos1Z = getBodyPartCoordinates(31, i)
            pos2X, pos2Y, pos2Z = getBodyPartCoordinates(32, i)
            
            pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
            pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
            renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
    
            pos1X, pos1Y, pos1Z = getBodyPartCoordinates(32, i)
            pos2X, pos2Y, pos2Z = getBodyPartCoordinates(33, i)
            
            pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
            pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
            renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
    
            pos1X, pos1Y, pos1Z = getBodyPartCoordinates(33, i)
            pos2X, pos2Y, pos2Z = getBodyPartCoordinates(34, i)
            
            pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
            pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
            renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
    
            pos1X, pos1Y, pos1Z = getBodyPartCoordinates(34, i)
            pos2X, pos2Y, pos2Z = getBodyPartCoordinates(35, i)
            
            pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
            pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
            renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
            
    
            
            pos1X, pos1Y, pos1Z = getBodyPartCoordinates(1, i)
            pos2X, pos2Y, pos2Z = getBodyPartCoordinates(51, i)
            
            pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
            pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
            renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
            pos1X, pos1Y, pos1Z = getBodyPartCoordinates(51, i)
            pos2X, pos2Y, pos2Z = getBodyPartCoordinates(52, i)
            
            pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
            pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
            renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
    
            pos1X, pos1Y, pos1Z = getBodyPartCoordinates(52, i)
            pos2X, pos2Y, pos2Z = getBodyPartCoordinates(53, i)
            
            pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
            pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
            renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
    
            pos1X, pos1Y, pos1Z = getBodyPartCoordinates(53, i)
            pos2X, pos2Y, pos2Z = getBodyPartCoordinates(54, i)
            
            pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
            pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
            renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
            
    
            
            pos1X, pos1Y, pos1Z = getBodyPartCoordinates(1, i)
            pos2X, pos2Y, pos2Z = getBodyPartCoordinates(41, i)
            
            pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
            pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
            renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
    
            pos1X, pos1Y, pos1Z = getBodyPartCoordinates(41, i)
            pos2X, pos2Y, pos2Z = getBodyPartCoordinates(42, i)
            
            pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
            pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
            renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
    
            pos1X, pos1Y, pos1Z = getBodyPartCoordinates(42, i)
            pos2X, pos2Y, pos2Z = getBodyPartCoordinates(43, i)
            
            pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
            pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
            renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
    
            pos1X, pos1Y, pos1Z = getBodyPartCoordinates(43, i)
            pos2X, pos2Y, pos2Z = getBodyPartCoordinates(44, i)
            
            pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
            pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
            renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)

            pos2X, pos2Y, pos2Z = getBodyPartCoordinates(44, i)
            pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
            renderDrawPolygon(pos3, pos4, thickness, thickness, 100, 0, color)   
            end   
        end
    end)
end

function getBodyPartCoordinates(id, handle)
    if doesCharExist(handle) then
        local pedptr = getCharPointer(handle)
        local vec = ffi.new("float[3]")
        getBonePosition(ffi.cast("void*", pedptr), vec, id, true)
        return vec[0], vec[1], vec[2]
    end
end
 

tsunamiqq

Участник
429
16
Lua:
function imgui.OnDrawFrame()
local iScreenWidth, iScreenHeight = getScreenResolution()
local btn_size = imgui.ImVec2(-1, 0)
    if main_window_state.v then
    imgui.SetNextWindowSize(imgui.ImVec2(1000, 500), imgui.Cond.FirstUseEver)
    imgui.Begin('Family Helper by Nakamura', main_window_state, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse)
    imgui.BeginChild('##121', imgui.ImVec2(200, 465), true)
    if imgui.Button(u8'Управление участниками', imgui.ImVec2(-1, 53)) then menu = 0 end
    if imgui.Button(u8'Для участников/nСемей', imgui.ImVec2(-1, 53)) then menu = 1 end
    if imgui.Button(u8'Для лидеров/nзамов', imgui.ImVec2(-1, 53)) then menu = 2 end
    if imgui.Button(u8'Биндер', imgui.ImVec2(-1, 53)) then menu = 3 end
    if imgui.Button(u8'Правила', imgui.ImVec2(-1, 53)) then menu = 4 end
    if imgui.Button(u8'CMD list', imgui.ImVec2(-1, 53)) then menu = 5 end
    if imgui.Button(u8'Настройки', imgui.ImVec2(-1, 53)) then menu = 6 end
    if imgui.Button(u8'О скрипте', imgui.ImVec2(-1, 53)) then menu = 7 end
    imgui.EndChild()
    imgui.SameLine()
    if menu == 0 then
        imgui.BeginChild('##once', imgui.ImVec2(775, 465), true)
        imgui.Text('')
        imgui.EndChild()
    elseif menu == 1 then
        imgui.BeginChild('##twice', imgui.ImVec2(775, 465), true)
        imgui.Text('')
        imgui.EndChild()
    elseif menu == 2 then
        imgui.BeginChild('##twice', imgui.ImVec2(775, 465), true)
        imgui.Text('')
        imgui.EndChild()
    elseif menu == 3 then
        imgui.BeginChild('##twice', imgui.ImVec2(775, 465), true)
        imgui.Text('')
        imgui.EndChild()
    elseif menu == 4 then
        imgui.BeginChild('##twice', imgui.ImVec2(775, 465), true)
        imgui.Text('')
        imgui.EndChild()
    elseif menu == 5 then
        imgui.BeginChild('##twice', imgui.ImVec2(775, 465), true)
        imgui.Text('')
        imgui.EndChild()
    elseif menu == 6 then
        imgui.BeginChild('##twice', imgui.ImVec2(775, 465), true)
        imgui.Text('')
        imgui.EndChild()
    elseif menu == 7 then
        imgui.BeginChild('##twice', imgui.ImVec2(775, 465), true)
        imgui.Text('Автор скрипта: Tsunami_Nakamura. Помощник: Adam_Karleone', main_window_state)
        imgui.Text('ВК - @lcn.maks', main_window_state)
        imgui.Text('Пишите в вк о багам, или предложением к обновлению.', main_window_state)
        imgui.Text('Скрипт сделан для Семей, не более.', main_window_state)
        imgui.EndChild()
    end
    imgui.End()
    end
Как сделать автологин, в 6 меню над, помогите плс
 

TaoTan

Участник
63
3
Lua:
local ev = require('lib.samp.events')

require "lib.moonloader"

local state = false
local tpCount, timer = 0, 0
local server = -1
local join = 0
local x, y, z = 0, 0, 0
local data = samp_create_sync_data('player')
data.position.x = 2517
data.position.y = 1317
data.position.z = 8
data.send()

local vector = require 'vector3d'
local tp, sync = false, false

function main()
    while not isSampAvailable() do wait(0) end
    sampAddChatMessage("[TP-GOVNO]ЗАГРУЗИЛСЯ!", 1337228)
    sampRegisterChatCommand('ftp', gtp)
    lua_thread.create(gtp)
        if tp then return sampAddChatMessage('уже телепортируемс¤', -1) end
        
            blip, blipX, blipY, blipZ = getTargetBlipCoordinatesFixed()
            if blip then
                sync = true
                charPosX, charPosY, charPosZ = getCarCoordinates(car)
                local distan = getDistanceBetweenCoords3d(blipX, blipY, charPosZ, charPosX, charPosY, charPosZ)
                --if distan < 1 then return setCarCoordinates(car, blipX, blipY, blipZ) end
                tp = true
                else
                warpCharIntoCar(PLAYER_PED, car)
                    sampAddChatMessage('SUCCESS', -1)
                    printStringNow('teleported successfully.', 4000)
                  tp = false
                end
            end
        end)
    end)

function SearchMarker(posX, posY, posZ, radius, isRace)
    local ret_posX = 0.0
    local ret_posY = 0.0
    local ret_posZ = 0.0
    local isFind = false

    for id = 0, 31 do
        local MarkerStruct = 0
        if isRace then MarkerStruct = 0xC7F168 + id * 56
        else MarkerStruct = 0xC7DD88 + id * 160 end
        local MarkerPosX = representIntAsFloat(readMemory(MarkerStruct + 0, 4, false))
        local MarkerPosY = representIntAsFloat(readMemory(MarkerStruct + 4, 4, false))
        local MarkerPosZ = representIntAsFloat(readMemory(MarkerStruct + 8, 4, false))

        if MarkerPosX ~= 0.0 or MarkerPosY ~= 0.0 or MarkerPosZ ~= 0.0 then
            if getDistanceBetweenCoords3d(MarkerPosX, MarkerPosY, MarkerPosZ, posX, posY, posZ) < radius then
                ret_posX = MarkerPosX
                ret_posY = MarkerPosY
                ret_posZ = MarkerPosZ
                isFind = true
                radius = getDistanceBetweenCoords3d(MarkerPosX, MarkerPosY, MarkerPosZ, posX, posY, posZ)
            end
        end
    end

    return isFind, ret_posX, ret_posY, ret_posZ
end

function ftp()
blip, blipX, blipY, blipZ = SearchMarker()
            if blip then
                sync = true
                charPosX, charPosY, charPosZ = getCarCoordinates(car)
                local distan = getDistanceBetweenCoords3d(blipX, blipY, charPosZ, charPosX, charPosY, charPosZ)
                --if distan < 1 then return setCarCoordinates(car, blipX, blipY, blipZ) end
                tp = true
            end
        end
    end
end

function sendSpectatorSync(x, y, z)
    local data = samp_create_sync_data('spectator')
    data.position = {x, y, z}
    data.send()
end

function samp_create_sync_data(sync_type, copy_from_player)
    local ffi = require 'ffi'
    local sampfuncs = require 'sampfuncs'
    -- from SAMP.Lua
    local raknet = require 'samp.raknet'
    require 'samp.synchronization'

    copy_from_player = copy_from_player or true
    local sync_traits = {
        player = {'PlayerSyncData', raknet.PACKET.PLAYER_SYNC, sampStorePlayerOnfootData},
        vehicle = {'VehicleSyncData', raknet.PACKET.VEHICLE_SYNC, sampStorePlayerIncarData},
        passenger = {'PassengerSyncData', raknet.PACKET.PASSENGER_SYNC, sampStorePlayerPassengerData},
        aim = {'AimSyncData', raknet.PACKET.AIM_SYNC, sampStorePlayerAimData},
        trailer = {'TrailerSyncData', raknet.PACKET.TRAILER_SYNC, sampStorePlayerTrailerData},
        unoccupied = {'UnoccupiedSyncData', raknet.PACKET.UNOCCUPIED_SYNC, nil},
        bullet = {'BulletSyncData', raknet.PACKET.BULLET_SYNC, nil},
        spectator = {'SpectatorSyncData', raknet.PACKET.SPECTATOR_SYNC, nil}
    }
    local sync_info = sync_traits[sync_type]
    local data_type = 'struct ' .. sync_info[1]
    local data = ffi.new(data_type, {})
    local raw_data_ptr = tonumber(ffi.cast('uintptr_t', ffi.new(data_type .. '*', data)))
    -- copy player's sync data to the allocated memory
    if copy_from_player then
        local copy_func = sync_info[3]
        if copy_func then
            local _, player_id
            if copy_from_player == true then
                _, player_id = sampGetPlayerIdByCharHandle(PLAYER_PED)
            else
                player_id = tonumber(copy_from_player)
            end
            copy_func(player_id, raw_data_ptr)
        end
    end
    -- function to send packet
    local func_send = function()
        local bs = raknetNewBitStream()
        raknetBitStreamWriteInt8(bs, sync_info[2])
        raknetBitStreamWriteBuffer(bs, raw_data_ptr, ffi.sizeof(data))
        raknetSendBitStreamEx(bs, sampfuncs.HIGH_PRIORITY, sampfuncs.UNRELIABLE_SEQUENCED, 1)
        raknetDeleteBitStream(bs)
    end
    -- metatable to access sync data and 'send' function
    local mt = {
        __index = function(t, index)
            return data[index]
        end,
        __newindex = function(t, index, value)
            data[index] = value
        end
    }
    return setmetatable({send = func_send}, mt)
end

ЧТО НЕ ТАК???!!!
 

Pashyka

Участник
220
17
Приветствую, уважаемые скриптеры)
Такая вот проблема, я хочу реализовать скрипт, который ищет капс в чате и считает все буквы капсом, чтобы легче было выдавать муты игрокам.
Я сделал данный скрипт, но он работает не точно, дело в том, что скрипт хоть и ищет заглавные буквы, например, игрок написал слово "ПРИВЕТ", скрипт посчитал в этом слове 6 букв заглавных. Далее, если игрок напишет слово ПРИВЕЕЕЕТ, то он все равно посчитает 6 букв заглавных, вместо 9-ти. Код приложу ниже.

Кодик:
local sampev = require 'samp.events'
require 'lib.moonloader'
local keys = require "vkeys"

local bykv = {"А","Б","В","Г","Д","Е","Ж","З","И","Й","К","Л","М","Н","О","П","Р","С","Т","У","Ф","Х","Ц","Ч","Ш","Щ","Ъ","Ы","Ь","Э","Ю","Я"}

local rabota = false
local bykvi = 0
time = 30
statustime = false

function main()
    while not isSampAvailable() do wait(100) end
    sampRegisterChatCommand("mut", function()
        rabota = not rabota
        sampAddChatMessage(rabota and "{00FF44}Скрипт включен" or "{FF0000}Скрипт выключен",-1)
    end)
    sampRegisterChatCommand("gg", function()
        sampAddChatMessage("Букв в переменной - " .. bykvi, -1)
    end)
    sampRegisterChatCommand("stime", function()
        statustime = not statustime
        if statustime == false then
            sampAddChatMessage("Мут на 30 минут установлен", -1)
            time = 30
        else
            sampAddChatMessage("Мут на 100 минут установлен", -1)
            time = 100
        end
    end)
    sampAddChatMessage("{00E8E8} Скрипт активирован", -1)
    while true do
        wait(0)
        if wasKeyPressed(VK_XBUTTON2) and not sampIsChatInputActive() and bykvi >= 10 then
            sampSetChatInputEnabled(true)
            sampSetChatInputText("/mute " .. id .. " " .. time .. " капс")
            bykvi = 0
        end
    end
end

function sampev.onServerMessage(color, text)
    if rabota then
        if text:find("%{F345FC%}%[PREMIUM%] %{FFFFFF%}(%a+_%a+)%[(%d+)%]: (.+)") and bykvi < 10 then
            nick, id, textik = text:match("%{F345FC%}%[PREMIUM%] %{FFFFFF%}(%a+_%a+)%[(%d+)%]: (.+)")
            for i, v in pairs(bykv) do
                if string.find(textik, v) then
                    bykvi = bykvi + 1
                end
            end
            if bykvi >= 10 then
                sampAddChatMessage("{FF0077}[WARNING] " .. bykvi.." букв капсом, игрок: "..nick.."["..id.."]", -1)
            end
            elseif bykvi < 10 then
            bykvi = 0
        end
        if text:find("%{6495ED%}%[VIP%] %{FFFFFF%}(%a+_%a+)%[(%d+)%]: (.+)") and bykvi < 10 then
            nick, id, textik = text:match("%{6495ED%}%[VIP%] %{FFFFFF%}(%a+_%a+)%[(%d+)%]: (.+)")
            for i, v in pairs(bykv) do
                if string.find(textik, v) then
                    bykvi = bykvi + 1
                end
            end
            if bykvi >= 10 then
                sampAddChatMessage("{FF0077}[WARNING] " .. bykvi.." букв капсом, игрок: "..nick.."["..id.."]", -1)
            end
            elseif bykvi < 10 then
            bykvi = 0
        end
    end
end

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