lua skuka isxodnik

Smeruxa

Известный
Автор темы
1,361
722
Было скучно и написал 2 штуки
спидхак и отрисовка линии перед лицом\
скидываю просто обсудить код, кому что зайдет, кому то может пригодится
sa-mp-000.png

Lua:
require 'lib.moonloader'
local imgui = require 'imgui'
local samp = require 'lib.samp.events'
local inicfg = require 'inicfg'
local ffi = require 'ffi'
local encoding = require 'encoding'
local u8 = encoding.UTF8
encoding.default = "CP1251"

local window = imgui.ImBool(false)
local alt_down = false
local getBonePosition = ffi.cast("int (__thiscall*)(void*, float*, int, bool)", 0x5E4280)
function msg(text)
    sampAddChatMessage(text, -1)
end

function draw_circle()

end

local HLcfg = inicfg.load({
    config = {
        acceleration = 1,
        max_speed = 200,
        acceleration_state = false,
        line_forward = false
    }
}, "test.ini")
inicfg.save(HLcfg, "test.ini")

local elements = {
    int = {
        acceleration = imgui.ImInt(HLcfg.config.acceleration),
        max_speed = imgui.ImInt(HLcfg.config.max_speed)
    },
    checkbox = {
        acceleration_state = imgui.ImBool(HLcfg.config.acceleration_state),
        line_forward = imgui.ImBool(HLcfg.config.line_forward)
    }
}

function samp.onSendVehicleSync(data)
    if elements.checkbox.acceleration_state.v and alt_down then
        local carHandle = storeCarCharIsInNoSave(playerPed)
        local carSpeed = getCarSpeed(carHandle)
        local carAngle = getCarHeading(carHandle) * math.pi / 180
        if carSpeed <= elements.int.max_speed.v then
            local velX = (carSpeed * math.cos(carAngle)) + elements.int.acceleration.v * math.cos(carAngle)
            local velY = (carSpeed * math.sin(carAngle)) + elements.int.acceleration.v * math.sin(carAngle)
            setCarForwardSpeed(carHandle, math.sqrt(velX * velX + velY * velY))
            data.moveSpeed = {data.moveSpeed.x * 0.5, data.moveSpeed.y * 0.5, data.moveSpeed.z}
            return data
        end
    end
end

function getBodyPartCoordinates(id, handle)
  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


function calculateHorizontalLine(angle, position, distance)
    return {position[1] + distance * math.cos(math.rad(angle + 90)), position[2] + distance * math.sin(math.rad(angle + 90)), position[3]}
end

function main()
    while not isSampLoaded() do wait(100) end
    sampRegisterChatCommand("open", function()
        window.v = not window.v
    end)
    while true do wait(0)
        imgui.Process = true
        alt_down = isKeyDown(VK_MENU) and isKeyDown(VK_W)
        if not window.v then
            imgui.ShowCursor = false
        end
        
        -- draw line
        
        if elements.checkbox.line_forward.v then
            local player_pos = {getBodyPartCoordinates(5, playerPed)}
            player_pos[3] = player_pos[3] + 0.070
            local angle = getCharHeading(playerPed)
            local endPos = calculateHorizontalLine(angle, player_pos, 0.5)
            
            local endX, endY = convert3DCoordsToScreen(endPos[1], endPos[2], endPos[3])
            local startX, startY = convert3DCoordsToScreen(player_pos[1], player_pos[2], player_pos[3])
            renderDrawLine(startX, startY, endX, endY, 1, -1)
        end   
        
        -- draw line
        
    end
end

function imgui.OnDrawFrame()
    if window.v then
        imgui.ShowCursor = true
        imgui.SetNextWindowPos(imgui.ImVec2(imgui.GetIO().DisplaySize.x / 2, imgui.GetIO().DisplaySize.y / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.SetNextWindowSize(imgui.ImVec2(300, 300), imgui.Cond.FirstUseEver)
        imgui.Begin("Test", window, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse + imgui.WindowFlags.NoScrollbar)
        imgui.Text(u8"Acceleration")
        imgui.Separator()
        if imgui.Checkbox(u8"Acceleration state", elements.checkbox.acceleration_state) then
            HLcfg.config.acceleration_state = elements.checkbox.acceleration_state.v
            save()
        end
        if imgui.SliderInt("##acceleration_scroll_choose", elements.int.acceleration, 1, 15) then
            HLcfg.config.acceleration = elements.int.acceleration.v
            save()
        end
        imgui.Separator()
        imgui.Text(u8"Line forward head")
        if imgui.Checkbox(u8"Line forward", elements.checkbox.line_forward) then
            HLcfg.config.line_forward = elements.checkbox.line_forward.v
            save()
        end
        
        imgui.End()
    end
end

function save()
    inicfg.save(HLcfg, "test.ini")
end
 
  • Эм
Реакции: Mintha

Mintha

Известный
Проверенный
149
1,256
так это ведь давно реализовано , че обсуждать то
 

Smeruxa

Известный
Автор темы
1,361
722
Lua:
require 'lib.moonloader'
local imgui = require 'imgui'
local samp = require 'lib.samp.events'
local inicfg = require 'inicfg'
local ffi = require 'ffi'
local encoding = require 'encoding'
local u8 = encoding.UTF8
encoding.default = "CP1251"

local window = imgui.ImBool(false)
local alt_down = false
local airbrake_state = false
local air_z = -1
local getBonePosition = ffi.cast("int (__thiscall*)(void*, float*, int, bool)", 0x5E4280)
function msg(text)
    sampAddChatMessage(text, -1)
end

function draw_circle()

end

local HLcfg = inicfg.load({
    config = {
        acceleration = 1,
        max_speed = 200,
        airbrake_speed = 10,
        acceleration_state = false,
        line_forward = false
    }
}, "test.ini")
inicfg.save(HLcfg, "test.ini")

local elements = {
    int = {
        acceleration = imgui.ImInt(HLcfg.config.acceleration),
        max_speed = imgui.ImInt(HLcfg.config.max_speed),
        airbrake_speed = imgui.ImInt(HLcfg.config.airbrake_speed)
    },
    checkbox = {
        acceleration_state = imgui.ImBool(HLcfg.config.acceleration_state),
        line_forward = imgui.ImBool(HLcfg.config.line_forward)
    }
}

function samp.onSendVehicleSync(data)
    if elements.checkbox.acceleration_state.v and alt_down then
        local carHandle = storeCarCharIsInNoSave(playerPed)
        local carSpeed = getCarSpeed(carHandle)
        local carAngle = getCarHeading(carHandle) * math.pi / 180
        if carSpeed <= elements.int.max_speed.v then
            local velX = (carSpeed * math.cos(carAngle)) + elements.int.acceleration.v * math.cos(carAngle)
            local velY = (carSpeed * math.sin(carAngle)) + elements.int.acceleration.v * math.sin(carAngle)
            setCarForwardSpeed(carHandle, math.sqrt(velX * velX + velY * velY))
            data.moveSpeed = {data.moveSpeed.x * 0.5, data.moveSpeed.y * 0.5, data.moveSpeed.z}
            return data
        end
    end
end

function getBodyPartCoordinates(id, handle)
  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


function calculateHorizontalLine(angle, position, distance)
    return {position[1] + distance * math.cos(math.rad(angle + 90)), position[2] + distance * math.sin(math.rad(angle + 90)), position[3]}
end

function main()
    while not isSampLoaded() do wait(100) end
    sampRegisterChatCommand("open", function()
        window.v = not window.v
    end)
    sampRegisterChatCommand('test', function()
        local cam = {getActiveCameraPointAt()}
        setCharCoordinates(playerPed, cam[1], cam[2], cam[3])
    end)
    while true do wait(0)
        imgui.Process = true
        alt_down = isKeyDown(VK_MENU) and isKeyDown(VK_W)
        if not window.v then
            imgui.ShowCursor = false
        end
        
        -- draw line
        
        if elements.checkbox.line_forward.v then
            local player_pos = {getBodyPartCoordinates(5, playerPed)}
            player_pos[3] = player_pos[3] + 0.070
            local angle = getCharHeading(playerPed)
            local endPos = calculateHorizontalLine(angle, player_pos, 0.5)
            
            local endX, endY = convert3DCoordsToScreen(endPos[1], endPos[2], endPos[3])
            local startX, startY = convert3DCoordsToScreen(player_pos[1], player_pos[2], player_pos[3])
            renderDrawLine(startX, startY, endX, endY, 1, -1)
        end   
        
        -- draw line
        
        -- airbrake
        
        if isKeyJustPressed(VK_RSHIFT) then
            airbrake_state = not airbrake_state
        end
        local airbrake_speed = elements.int.airbrake_speed.v
        if airbrake_state then
            local position = {getCharCoordinates(playerPed)}
            local angle = getCharHeading(playerPed)
            local camera_pos = {getActiveCameraCoordinates()}
            local camera_point = {getActiveCameraPointAt()}
            local rotate = getHeadingFromVector2d(camera_point[1] - camera_pos[1], camera_point[2] - camera_pos[2])
            airbrake_speed = airbrake_speed / 10
            if air_z == -1 then
                air_z = position[3] + 1
            end
            
            if isKeyDown(0x20) then
                air_z = air_z + 0.5
            end
            if isKeyDown(0x10) then
                air_z = air_z - 0.5
            end
            if isKeyDown(VK_A) then
                position[1] = position[1] + (-math.cos(math.rad(angle))) * airbrake_speed
                position[2] = position[2] + (-math.sin(math.rad(angle))) * airbrake_speed
            end
            if isKeyDown(VK_D) then
                position[1] = position[1] + math.cos(math.rad(angle)) * airbrake_speed
                position[2] = position[2] + math.sin(math.rad(angle)) * airbrake_speed
            end
            if isKeyDown(VK_W) then
                position[1] = position[1] + math.cos(math.rad(angle + 90)) * airbrake_speed
                position[2] = position[2] + math.sin(math.rad(angle + 90)) * airbrake_speed
            end
            if isKeyDown(VK_S) then
                position[1] = position[1] + math.cos(math.rad(angle - 90)) * airbrake_speed
                position[2] = position[2] + math.sin(math.rad(angle - 90)) * airbrake_speed
            end
            setCharHeading(playerPed, rotate)
            setCharCoordinates(playerPed, position[1], position[2], air_z)
        else
            air_z = -1
        end
        
        -- airbrake
        
    end
end

function imgui.OnDrawFrame()
    if window.v then
        imgui.ShowCursor = true
        imgui.SetNextWindowPos(imgui.ImVec2(imgui.GetIO().DisplaySize.x / 2, imgui.GetIO().DisplaySize.y / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.SetNextWindowSize(imgui.ImVec2(300, 300), imgui.Cond.FirstUseEver)
        imgui.Begin("Test", window, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse + imgui.WindowFlags.NoScrollbar)
        imgui.Text(u8"Acceleration")
        imgui.Separator()
        if imgui.Checkbox(u8"Acceleration state", elements.checkbox.acceleration_state) then
            HLcfg.config.acceleration_state = elements.checkbox.acceleration_state.v
            save()
        end
        if imgui.SliderInt("##acceleration_scroll_choose", elements.int.acceleration, 1, 15) then
            HLcfg.config.acceleration = elements.int.acceleration.v
            save()
        end
        imgui.Separator()
        imgui.Text(u8"Line forward head")
        if imgui.Checkbox(u8"Line forward", elements.checkbox.line_forward) then
            HLcfg.config.line_forward = elements.checkbox.line_forward.v
            save()
        end
        imgui.Separator()
        if imgui.SliderInt("airbrake_speed", elements.int.airbrake_speed, 1, 30) then
            HLcfg.config.airbrake_speed = elements.int.airbrake_speed.v
            save()
        end
        imgui.End()
    end
end

function save()
    inicfg.save(HLcfg, "test.ini")
end