- 1,361
- 722
Было скучно и написал 2 штуки
спидхак и отрисовка линии перед лицом\
скидываю просто обсудить код, кому что зайдет, кому то может пригодится
спидхак и отрисовка линии перед лицом\
скидываю просто обсудить код, кому что зайдет, кому то может пригодится
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