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

sssilvian

Активный
239
25
Lua:
pos x - renderGetFontDrawTextLength(my_font, твой string format) / 2
-- но советую вынести string формат в переменную, нафига это вставлять в renderFontDrawText
Вы можете поместить это в сценарий, который я перечислил выше для меня? Я не могу найти способ реализовать это в.

Есть ли способ упростить это? Мне нужно от 0 до 400.
Lua:
sampSendChat('/contract 0 500')
wait(676)
sampSendChat('/contract 1 500')
wait(676)
sampSendChat('/contract 2 500')
wait(676)
sampSendChat('/contract 3 500')
wait(676)
sampSendChat('/contract 4 500')
wait(676)
sampSendChat('/contract 5 500')
wait(676)
sampSendChat('/contract 6 500')
wait(676)
sampSendChat('/contract 7 500')
wait(676)
sampSendChat('/contract 8 500')
wait(676)
sampSendChat('/contract 9 500')
wait(676)
sampSendChat('/contract 10 500')
wait(676)
sampSendChat('/contract 11 500')
wait(676)
 
Последнее редактирование:

tyukapa

Активный
305
68
Как в getCharCoordinates сделать треугольник над игроками (ну типо херь когда наводишься на игрока и сверху треугольник зеленого цвтеа)
Lua:
getCharCoordinates(-- треугольник )
 

chromiusj

C Y N T H O N I
Модератор
5,056
3,322
Как в getCharCoordinates сделать треугольник над игроками (ну типо херь когда наводишься на игрока и сверху треугольник зеленого цвтеа)
Lua:
getCharCoordinates(-- треугольник )
 

Andrinall

Известный
687
515


[ML] (error) IMenu: opcode '00A0' call caused an unhandled exception
stack traceback:
[C]: in function 'getCharCoordinates'
...ee-user\Desktop\sborka\moonloader\IMenu 1.3.lua:1221: in function <...ee-user\Desktop\sborka\moonloader\IMenu 1.3.lua:1216>
[ML] (error) IMenu: Script died due to an error. (1F729C2C)

Как исправить?

Lua:
function Aimbot()
    if buf_1.enableaim.v and isKeyDown(VK_RBUTTON) then
        local handle = GetNearestPed(fov)
        if handle ~= -1 then
         local myPos = {getActiveCameraCoordinates()}
         local enPos = {getCharCoordinates(handle)} -- тут ошибка
         local vector = {myPos[1] - enPos[1], myPos[2] - enPos[2], myPos[3] - enPos[3]}
        if isWidescreenOnInOptions() then coefficentZ = 0.0778 else coefficentZ = 0.103 end
         local angle = {(math.atan2(vector[2], vector[1]) + 0.04253), (math.atan2((math.sqrt((math.pow(vector[1], 2) + math.pow(vector[2], 2)))), vector[3]) - math.pi / 2 - coefficentZ)}
         local view = {fix(representIntAsFloat(readMemory(0xB6F258, 4, false))), fix(representIntAsFloat(readMemory(0xB6F248, 4, false)))}
         local difference = {angle[1] - view[1], angle[2] - view[2]}
         local smooth = {difference[1] / buf_1.Smooth.v, difference[2] / buf_1.Smooth.v}
         setCameraPositionUnfixed((view[2] + smooth[2]), (view[1] + smooth[1]))
        end
    end
    return false
end
if handle ~= -1 then замени на if doesCharExist(handle) then
 
  • Нравится
Реакции: tyukapa

tyukapa

Активный
305
68
if handle ~= -1 then замени на if doesCharExist(handle) then
Скрытое содержимое для пользователя(ей): Andrinall




[ML] (error) IMenu: opcode '00A0' call caused an unhandled exception
stack traceback:
[C]: in function 'getCharCoordinates'
...ee-user\Desktop\sborka\moonloader\IMenu 1.3.lua:1221: in function <...ee-user\Desktop\sborka\moonloader\IMenu 1.3.lua:1216>
[ML] (error) IMenu: Script died due to an error. (1F729C2C)

Как исправить?

Lua:
function Aimbot()
    if buf_1.enableaim.v and isKeyDown(VK_RBUTTON) then
        local handle = GetNearestPed(fov)
        if handle ~= -1 then
         local myPos = {getActiveCameraCoordinates()}
         local enPos = {getCharCoordinates(handle)} -- тут ошибка
         local vector = {myPos[1] - enPos[1], myPos[2] - enPos[2], myPos[3] - enPos[3]}
        if isWidescreenOnInOptions() then coefficentZ = 0.0778 else coefficentZ = 0.103 end
         local angle = {(math.atan2(vector[2], vector[1]) + 0.04253), (math.atan2((math.sqrt((math.pow(vector[1], 2) + math.pow(vector[2], 2)))), vector[3]) - math.pi / 2 - coefficentZ)}
         local view = {fix(representIntAsFloat(readMemory(0xB6F258, 4, false))), fix(representIntAsFloat(readMemory(0xB6F248, 4, false)))}
         local difference = {angle[1] - view[1], angle[2] - view[2]}
         local smooth = {difference[1] / buf_1.Smooth.v, difference[2] / buf_1.Smooth.v}
         setCameraPositionUnfixed((view[2] + smooth[2]), (view[1] + smooth[1]))
        end
    end
    return false
end
up

*** Скрытый текст не может быть процитирован. ***


up
с горем пополам решил проблему

Первый раз с радио кнопками работаю, как правильно сделать тут?

Код:
-- ini файл

bone = imgui.ImInt(1)


-- масив
local buf_1 = {
bone = imgui.ImInt(mainIni.imenu0.bone) -- сделал так - скрипт меня шлёт
}
 
Последнее редактирование:

Dmitriy Makarov

25.05.2021
Проверенный
2,490
1,120
*** Скрытый текст не может быть процитирован. ***


up


с горем пополам решил проблему

Первый раз с радио кнопками работаю, как правильно сделать тут?

Код:
-- ini файл

bone = imgui.ImInt(1)


-- масив
local buf_1 = {
bone = imgui.ImInt(mainIni.imenu0.bone) -- сделал так - скрипт меня шлёт
}
Lua:
-- Ini файл
bone = 1

-- Массив
local buf_1 = {
    bone = imgui.ImInt(mainIni.imenu0.bone)
}
 
  • Нравится
Реакции: tyukapa

tyukapa

Активный
305
68
help

[ML] (error) IMenu: ...ee-user\Desktop\by\moonloader\IMenu 1.3.lua:1259: attempt to index global 'ednPos' (a nil value)
stack traceback:

Lua:
-- взять у scar смог, а нормально сделать на имгуи нет ._.

-- имгуи
if one4.v then
         local sw, sh = getScreenResolution()
         imgui.SetNextWindowPos(imgui.ImVec2(sw / 2, sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.7))
         imgui.SetNextWindowSize(imgui.ImVec2(400,350), imgui.Cond.FirstUseEver)
         imgui.Begin(fa.ICON_FA_CROSSHAIRS.. u8" AIM", one4, imgui.WindowFlags.NoResize)
         imgui.Checkbox(fa.ICON_FA_CROSSHAIRS.. u8' Включить', buf_1.enableaim)
         imgui.SliderFloat(u8"Радиус", buf_1.fov, 1, 30)
         imgui.SliderFloat(u8"Плавность", buf_1.smooth, 1, 50)
         imgui.SliderFloat(u8"Дистанция", buf_1.maxdistAim, 30, 1000)
         imgui.Separator()
         imgui.Checkbox(u8"Проверка на здания", buf_1.checkBuild)
         imgui.Checkbox(u8"Проверка на машины", buf_1.checkVehicle)
         imgui.Checkbox(u8"Проверка на объекты", buf_1.checkObject)
         imgui.Separator()
         imgui.RadioButton(u8"Голова", buf_1.bone, 1)
         imgui.RadioButton(u8"Торс", buf_1.bone, 2)
         imgui.RadioButton(u8"Пах", buf_1.bone, 3)
         imgui.Separator()
         imgui.Checkbox(u8"Стрельба по своим", buf_1.team)
         imgui.End()
    end



function fix(angle)
    if angle > math.pi then
        angle = angle - (math.pi * 2)
    elseif angle < -math.pi then
        angle = angle + (math.pi * 2)
    end
    return angle
end

function GetNearestPed(fov)
    local maxDistance = buf_1.maxDistAim
    local nearestPED = -1
    for i = 0, sampGetMaxPlayerId(true) do
        if sampIsPlayerConnected(i) then
            local find, handle = sampGetCharHandleBySampPlayerId(i)
            if find then
                if isCharOnScreen(handle) then
                    if not isCharDead(handle) then
                        local _, currentID = sampGetPlayerIdByCharHandle(PLAYER_PED)
                        local enPos = {getCharCoordinates(handle)}
                        local myPos = {getActiveCameraCoordinates()}
                        local vector = {myPos[1] - enPos[1], myPos[2] - enPos[2], myPos[3] - enPos[3]}
                        if isWidescreenOnInOptions() then coefficentZ = 0.0778 else coefficentZ = 0.103 end
                        local angle = {(math.atan2(vector[2], vector[1]) + 0.04253), (math.atan2((math.sqrt((math.pow(vector[1], 2) + math.pow(vector[2], 2)))), vector[3]) - math.pi / 2 - coefficentZ)}
                        local view = {fix(representIntAsFloat(readMemory(0xB6F258, 4, false))), fix(representIntAsFloat(readMemory(0xB6F248, 4, false)))}
                        local distance = math.sqrt((math.pow(angle[1] - view[1], 2) + math.pow(angle[2] - view[2], 2))) * 57.2957795131
                        if distance > fov then check = true else check = false end
                        if not check then
                            local myPos = {getCharCoordinates(PLAYER_PED)}
                            local distance = math.sqrt((math.pow((enPos[1] - myPos[1]), 2) + math.pow((enPos[2] - myPos[2]), 2) + math.pow((enPos[3] - myPos[3]), 2)))
                            if (distance < maxDistance) then
                                nearestPED = handle
                                maxDistance = distance
                            end
                        end
                    end
                end
            end
        end
    end
    return nearestPED
end

function Aimbot() -- aim спиздил у Scar
    if buf_1.enableaim and isKeyDown(VK_RBUTTON) then
        local handle = GetNearestPed(buf_1.fov)
        if handle ~= -1 then
            local myPos = {getActiveCameraCoordinates()}
            if buf_1.bone == 1 then
                ednPos = {GetBodyPartCoordinates(6, handle)}
            elseif buf_1.bone == 2 then
                ednPos = {GetBodyPartCoordinates(4, handle)}
            elseif buf_1.bone == 3 then
                ednPos = {GetBodyPartCoordinates(3, handle)}
            end
            if buf_1.team then
                if isLineOfSightClear(myPos[1], myPos[2], myPos[3], ednPos[1], ednPos[2], ednPos[3], buf_1.checkBuild, buf_1.checkVehicle, false, buf_1.checkObject, false) then
                    local vector = {myPos[1] - ednPos[1], myPos[2] - ednPos[2], myPos[3] - ednPos[3]}
                    if isWidescreenOnInOptions() then coefficentZ = 0.0778 else coefficentZ = 0.103 end
                    local angle = {(math.atan2(vector[2], vector[1]) + 0.04253), (math.atan2((math.sqrt((math.pow(vector[1], 2) + math.pow(vector[2], 2)))), vector[3]) - math.pi / 2 - coefficentZ)}
                    local view = {fix(representIntAsFloat(readMemory(0xB6F258, 4, false))), fix(representIntAsFloat(readMemory(0xB6F248, 4, false)))}
                    local difference = {angle[1] - view[1], angle[2] - view[2]}
                    local smooth = {difference[1] / buf_1.smooth, difference[2] / buf_1.smooth}
                    setCameraPositionUnfixed((view[2] + smooth[2]), (view[1] + smooth[1]))
                end
            else
                for i = 0, sampGetMaxPlayerId() do
                    if sampIsPlayerConnected(i) then
                        local result, handlePed = sampGetCharHandleBySampPlayerId(i)
                        local color_ped = sampGetPlayerColor(i)
                        if result and color_ped ~= sampGetPlayerColor(select(2, sampGetPlayerIdByCharHandle(PLAYER_PED))) then
                            if isLineOfSightClear(myPos[1], myPos[2], myPos[3], ednPos[1], ednPos[2], ednPos[3], buf_1.checkBuild, buf_1.checkVehicle, false, buf_1.checkObject, false) then
                                local vector = {myPos[1] - ednPos[1], myPos[2] - ednPos[2], myPos[3] - ednPos[3]}
                                if isWidescreenOnInOptions() then coefficentZ = 0.0778 else coefficentZ = 0.103 end
                                local angle = {(math.atan2(vector[2], vector[1]) + 0.04253), (math.atan2((math.sqrt((math.pow(vector[1], 2) + math.pow(vector[2], 2)))), vector[3]) - math.pi / 2 - coefficentZ)}
                                local view = {fix(representIntAsFloat(readMemory(0xB6F258, 4, false))), fix(representIntAsFloat(readMemory(0xB6F248, 4, false)))}
                                local difference = {angle[1] - view[1], angle[2] - view[2]}
                                local smooth = {difference[1] / buf_1.smooth, difference[2] / buf_1.smooth}
                                setCameraPositionUnfixed((view[2] + smooth[2]), (view[1] + smooth[1]))
                            end
                        end
                    end
                end
            end
        end
    end
    return false
end
 
Последнее редактирование:

sssilvian

Активный
239
25


Lua:
if arg < 0 or arg > 311 then
    sampAddChatMessage('от 0 до 311', -1)
else
    --code
end
Спасибо, но я не могу понять, как мне сделать так, чтобы когда мой снайперский прицел был на игроке, посередине справа на экране была зеленая надпись "HIT", иначе она была красной с тот же текст? (когда держу снайперский прицел)
 

de_clain

Активный
212
47
что именно ты хочешь?
Что не так?

[ML] (error) IMenu: ...ee-user\Desktop\by\moonloader\IMenu 1.3.lua:1259: attempt to index global 'ednPos' (a nil value)
stack traceback:

Lua:
-- взять у scar смог, а нормально сделать на имгуи нет ._.

-- имгуи
if one4.v then
         local sw, sh = getScreenResolution()
         imgui.SetNextWindowPos(imgui.ImVec2(sw / 2, sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.7))
         imgui.SetNextWindowSize(imgui.ImVec2(400,350), imgui.Cond.FirstUseEver)
         imgui.Begin(fa.ICON_FA_CROSSHAIRS.. u8" AIM", one4, imgui.WindowFlags.NoResize)
         imgui.Checkbox(fa.ICON_FA_CROSSHAIRS.. u8' Включить', buf_1.enableaim)
         imgui.SliderFloat(u8"Радиус", buf_1.fov, 1, 30)
         imgui.SliderFloat(u8"Плавность", buf_1.smooth, 1, 50)
         imgui.SliderFloat(u8"Дистанция", buf_1.maxdistAim, 30, 1000)
         imgui.Separator()
         imgui.Checkbox(u8"Проверка на здания", buf_1.checkBuild)
         imgui.Checkbox(u8"Проверка на машины", buf_1.checkVehicle)
         imgui.Checkbox(u8"Проверка на объекты", buf_1.checkObject)
         imgui.Separator()
         imgui.RadioButton(u8"Голова", buf_1.bone, 1)
         imgui.RadioButton(u8"Торс", buf_1.bone, 2)
         imgui.RadioButton(u8"Пах", buf_1.bone, 3)
         imgui.Separator()
         imgui.Checkbox(u8"Стрельба по своим", buf_1.team)
         imgui.End()
    end



function fix(angle)
    if angle > math.pi then
        angle = angle - (math.pi * 2)
    elseif angle < -math.pi then
        angle = angle + (math.pi * 2)
    end
    return angle
end

function GetNearestPed(fov)
    local maxDistance = buf_1.maxDistAim
    local nearestPED = -1
    for i = 0, sampGetMaxPlayerId(true) do
        if sampIsPlayerConnected(i) then
            local find, handle = sampGetCharHandleBySampPlayerId(i)
            if find then
                if isCharOnScreen(handle) then
                    if not isCharDead(handle) then
                        local _, currentID = sampGetPlayerIdByCharHandle(PLAYER_PED)
                        local enPos = {getCharCoordinates(handle)}
                        local myPos = {getActiveCameraCoordinates()}
                        local vector = {myPos[1] - enPos[1], myPos[2] - enPos[2], myPos[3] - enPos[3]}
                        if isWidescreenOnInOptions() then coefficentZ = 0.0778 else coefficentZ = 0.103 end
                        local angle = {(math.atan2(vector[2], vector[1]) + 0.04253), (math.atan2((math.sqrt((math.pow(vector[1], 2) + math.pow(vector[2], 2)))), vector[3]) - math.pi / 2 - coefficentZ)}
                        local view = {fix(representIntAsFloat(readMemory(0xB6F258, 4, false))), fix(representIntAsFloat(readMemory(0xB6F248, 4, false)))}
                        local distance = math.sqrt((math.pow(angle[1] - view[1], 2) + math.pow(angle[2] - view[2], 2))) * 57.2957795131
                        if distance > fov then check = true else check = false end
                        if not check then
                            local myPos = {getCharCoordinates(PLAYER_PED)}
                            local distance = math.sqrt((math.pow((enPos[1] - myPos[1]), 2) + math.pow((enPos[2] - myPos[2]), 2) + math.pow((enPos[3] - myPos[3]), 2)))
                            if (distance < maxDistance) then
                                nearestPED = handle
                                maxDistance = distance
                            end
                        end
                    end
                end
            end
        end
    end
    return nearestPED
end

function Aimbot() -- aim спиздил у Scar
    if buf_1.enableaim and isKeyDown(VK_RBUTTON) then
        local handle = GetNearestPed(buf_1.fov)
        if handle ~= -1 then
            local myPos = {getActiveCameraCoordinates()}
            if buf_1.bone == 1 then
                ednPos = {GetBodyPartCoordinates(6, handle)}
            elseif buf_1.bone == 2 then
                ednPos = {GetBodyPartCoordinates(4, handle)}
            elseif buf_1.bone == 3 then
                ednPos = {GetBodyPartCoordinates(3, handle)}
            end
            if buf_1.team then
                if isLineOfSightClear(myPos[1], myPos[2], myPos[3], ednPos[1], ednPos[2], ednPos[3], buf_1.checkBuild, buf_1.checkVehicle, false, buf_1.checkObject, false) then
                    local vector = {myPos[1] - ednPos[1], myPos[2] - ednPos[2], myPos[3] - ednPos[3]}
                    if isWidescreenOnInOptions() then coefficentZ = 0.0778 else coefficentZ = 0.103 end
                    local angle = {(math.atan2(vector[2], vector[1]) + 0.04253), (math.atan2((math.sqrt((math.pow(vector[1], 2) + math.pow(vector[2], 2)))), vector[3]) - math.pi / 2 - coefficentZ)}
                    local view = {fix(representIntAsFloat(readMemory(0xB6F258, 4, false))), fix(representIntAsFloat(readMemory(0xB6F248, 4, false)))}
                    local difference = {angle[1] - view[1], angle[2] - view[2]}
                    local smooth = {difference[1] / buf_1.smooth, difference[2] / buf_1.smooth}
                    setCameraPositionUnfixed((view[2] + smooth[2]), (view[1] + smooth[1]))
                end
            else
                for i = 0, sampGetMaxPlayerId() do
                    if sampIsPlayerConnected(i) then
                        local result, handlePed = sampGetCharHandleBySampPlayerId(i)
                        local color_ped = sampGetPlayerColor(i)
                        if result and color_ped ~= sampGetPlayerColor(select(2, sampGetPlayerIdByCharHandle(PLAYER_PED))) then
                            if isLineOfSightClear(myPos[1], myPos[2], myPos[3], ednPos[1], ednPos[2], ednPos[3], buf_1.checkBuild, buf_1.checkVehicle, false, buf_1.checkObject, false) then
                                local vector = {myPos[1] - ednPos[1], myPos[2] - ednPos[2], myPos[3] - ednPos[3]}
                                if isWidescreenOnInOptions() then coefficentZ = 0.0778 else coefficentZ = 0.103 end
                                local angle = {(math.atan2(vector[2], vector[1]) + 0.04253), (math.atan2((math.sqrt((math.pow(vector[1], 2) + math.pow(vector[2], 2)))), vector[3]) - math.pi / 2 - coefficentZ)}
                                local view = {fix(representIntAsFloat(readMemory(0xB6F258, 4, false))), fix(representIntAsFloat(readMemory(0xB6F248, 4, false)))}
                                local difference = {angle[1] - view[1], angle[2] - view[2]}
                                local smooth = {difference[1] / buf_1.smooth, difference[2] / buf_1.smooth}
                                setCameraPositionUnfixed((view[2] + smooth[2]), (view[1] + smooth[1]))
                            end
                        end
                    end
                end
            end
        end
    end
    return false
end
Почему ты внимание на ошибку не обращаешь или не читаешь, там написано что такой переменной нету, исправь название переменной и все
 
  • Нравится
Реакции: MLycoris

tyukapa

Активный
305
68
что именно ты хочешь?
Почему ты внимание на ошибку не обращаешь или не читаешь, там написано что такой переменной нету, исправь название переменной и все
Ну я понял что ошибка на 1259 строке, нету переменной. Я пробывал сделать
Lua:
           if buf_1.bone == 1 then
               local ednPos = {GetBodyPartCoordinates(6, handle)}
            elseif buf_1.bone == 2 then
               local ednPos = {GetBodyPartCoordinates(4, handle)}
            elseif buf_1.bone == 3 then
               local ednPos = {GetBodyPartCoordinates(3, handle)}
            end
Добавил local, пишет туже ошибку
 

de_clain

Активный
212
47
Ну я понял что ошибка на 1259 строке, нету переменной. Я пробывал сделать
Lua:
           if buf_1.bone == 1 then
               local ednPos = {GetBodyPartCoordinates(6, handle)}
            elseif buf_1.bone == 2 then
               local ednPos = {GetBodyPartCoordinates(4, handle)}
            elseif buf_1.bone == 3 then
               local ednPos = {GetBodyPartCoordinates(3, handle)}
            end
Добавил local, пишет туже ошибку
Я вижу у тебя там enPos а не ednPos, может надо это проверить, хотя раз ты взял откуда то эту фичу то вырезай все а не только функцию
 

tyukapa

Активный
305
68
help

[ML] (error) IMenu: ...ee-user\Desktop\by\moonloader\IMenu 1.3.lua:1259: attempt to index global 'ednPos' (a nil value)
stack traceback:

Lua:
-- взять у scar смог, а нормально сделать на имгуи нет ._.

-- имгуи
if one4.v then
         local sw, sh = getScreenResolution()
         imgui.SetNextWindowPos(imgui.ImVec2(sw / 2, sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.7))
         imgui.SetNextWindowSize(imgui.ImVec2(400,350), imgui.Cond.FirstUseEver)
         imgui.Begin(fa.ICON_FA_CROSSHAIRS.. u8" AIM", one4, imgui.WindowFlags.NoResize)
         imgui.Checkbox(fa.ICON_FA_CROSSHAIRS.. u8' Включить', buf_1.enableaim)
         imgui.SliderFloat(u8"Радиус", buf_1.fov, 1, 30)
         imgui.SliderFloat(u8"Плавность", buf_1.smooth, 1, 50)
         imgui.SliderFloat(u8"Дистанция", buf_1.maxdistAim, 30, 1000)
         imgui.Separator()
         imgui.Checkbox(u8"Проверка на здания", buf_1.checkBuild)
         imgui.Checkbox(u8"Проверка на машины", buf_1.checkVehicle)
         imgui.Checkbox(u8"Проверка на объекты", buf_1.checkObject)
         imgui.Separator()
         imgui.RadioButton(u8"Голова", buf_1.bone, 1)
         imgui.RadioButton(u8"Торс", buf_1.bone, 2)
         imgui.RadioButton(u8"Пах", buf_1.bone, 3)
         imgui.Separator()
         imgui.Checkbox(u8"Стрельба по своим", buf_1.team)
         imgui.End()
    end



function fix(angle)
    if angle > math.pi then
        angle = angle - (math.pi * 2)
    elseif angle < -math.pi then
        angle = angle + (math.pi * 2)
    end
    return angle
end

function GetNearestPed(fov)
    local maxDistance = buf_1.maxDistAim
    local nearestPED = -1
    for i = 0, sampGetMaxPlayerId(true) do
        if sampIsPlayerConnected(i) then
            local find, handle = sampGetCharHandleBySampPlayerId(i)
            if find then
                if isCharOnScreen(handle) then
                    if not isCharDead(handle) then
                        local _, currentID = sampGetPlayerIdByCharHandle(PLAYER_PED)
                        local enPos = {getCharCoordinates(handle)}
                        local myPos = {getActiveCameraCoordinates()}
                        local vector = {myPos[1] - enPos[1], myPos[2] - enPos[2], myPos[3] - enPos[3]}
                        if isWidescreenOnInOptions() then coefficentZ = 0.0778 else coefficentZ = 0.103 end
                        local angle = {(math.atan2(vector[2], vector[1]) + 0.04253), (math.atan2((math.sqrt((math.pow(vector[1], 2) + math.pow(vector[2], 2)))), vector[3]) - math.pi / 2 - coefficentZ)}
                        local view = {fix(representIntAsFloat(readMemory(0xB6F258, 4, false))), fix(representIntAsFloat(readMemory(0xB6F248, 4, false)))}
                        local distance = math.sqrt((math.pow(angle[1] - view[1], 2) + math.pow(angle[2] - view[2], 2))) * 57.2957795131
                        if distance > fov then check = true else check = false end
                        if not check then
                            local myPos = {getCharCoordinates(PLAYER_PED)}
                            local distance = math.sqrt((math.pow((enPos[1] - myPos[1]), 2) + math.pow((enPos[2] - myPos[2]), 2) + math.pow((enPos[3] - myPos[3]), 2)))
                            if (distance < maxDistance) then
                                nearestPED = handle
                                maxDistance = distance
                            end
                        end
                    end
                end
            end
        end
    end
    return nearestPED
end

function Aimbot() -- aim спиздил у Scar
    if buf_1.enableaim and isKeyDown(VK_RBUTTON) then
        local handle = GetNearestPed(buf_1.fov)
        if handle ~= -1 then
            local myPos = {getActiveCameraCoordinates()}
            if buf_1.bone == 1 then
                ednPos = {GetBodyPartCoordinates(6, handle)}
            elseif buf_1.bone == 2 then
                ednPos = {GetBodyPartCoordinates(4, handle)}
            elseif buf_1.bone == 3 then
                ednPos = {GetBodyPartCoordinates(3, handle)}
            end
            if buf_1.team then
                if isLineOfSightClear(myPos[1], myPos[2], myPos[3], ednPos[1], ednPos[2], ednPos[3], buf_1.checkBuild, buf_1.checkVehicle, false, buf_1.checkObject, false) then
                    local vector = {myPos[1] - ednPos[1], myPos[2] - ednPos[2], myPos[3] - ednPos[3]}
                    if isWidescreenOnInOptions() then coefficentZ = 0.0778 else coefficentZ = 0.103 end
                    local angle = {(math.atan2(vector[2], vector[1]) + 0.04253), (math.atan2((math.sqrt((math.pow(vector[1], 2) + math.pow(vector[2], 2)))), vector[3]) - math.pi / 2 - coefficentZ)}
                    local view = {fix(representIntAsFloat(readMemory(0xB6F258, 4, false))), fix(representIntAsFloat(readMemory(0xB6F248, 4, false)))}
                    local difference = {angle[1] - view[1], angle[2] - view[2]}
                    local smooth = {difference[1] / buf_1.smooth, difference[2] / buf_1.smooth}
                    setCameraPositionUnfixed((view[2] + smooth[2]), (view[1] + smooth[1]))
                end
            else
                for i = 0, sampGetMaxPlayerId() do
                    if sampIsPlayerConnected(i) then
                        local result, handlePed = sampGetCharHandleBySampPlayerId(i)
                        local color_ped = sampGetPlayerColor(i)
                        if result and color_ped ~= sampGetPlayerColor(select(2, sampGetPlayerIdByCharHandle(PLAYER_PED))) then
                            if isLineOfSightClear(myPos[1], myPos[2], myPos[3], ednPos[1], ednPos[2], ednPos[3], buf_1.checkBuild, buf_1.checkVehicle, false, buf_1.checkObject, false) then
                                local vector = {myPos[1] - ednPos[1], myPos[2] - ednPos[2], myPos[3] - ednPos[3]}
                                if isWidescreenOnInOptions() then coefficentZ = 0.0778 else coefficentZ = 0.103 end
                                local angle = {(math.atan2(vector[2], vector[1]) + 0.04253), (math.atan2((math.sqrt((math.pow(vector[1], 2) + math.pow(vector[2], 2)))), vector[3]) - math.pi / 2 - coefficentZ)}
                                local view = {fix(representIntAsFloat(readMemory(0xB6F258, 4, false))), fix(representIntAsFloat(readMemory(0xB6F248, 4, false)))}
                                local difference = {angle[1] - view[1], angle[2] - view[2]}
                                local smooth = {difference[1] / buf_1.smooth, difference[2] / buf_1.smooth}
                                setCameraPositionUnfixed((view[2] + smooth[2]), (view[1] + smooth[1]))
                            end
                        end
                    end
                end
            end
        end
    end
    return false
end
up