- 17
- 6
- Версия SA-MP
-
- Любая
В чём суть проблемы создал скрипт записи маршрутов с ног вроде бы норм робит но на автобусе когда в него врезаются он сбивается с курса и потом медленно едет и тормозит
local samp = require 'lib.samp.events'
local imgui = require 'mimgui'
local encoding = require 'encoding'
local ffi = require 'ffi'
encoding.default = 'utf-8'
local u8 = encoding.UTF8
local path = "/sdcard/Download/game/autopilot.lua"
local recording, playing = false, false
local route, start_time, play_start_time, play_index = {}, 0, 0, 1
local show_menu = {false}
local function getCurrentTime() return os.clock() * 1000 end
-- Сохранение и загрузка (как в v8.0)
local function saveAuto()
local f = io.open(path, "w")
if f then
local function serialize(t)
local res = "{"
for k, v in pairs(t) do
res = res .. "[" .. (type(k) == "string" and string.format("%q", k) or k) .. "]="
if type(v) == "table" then res = res .. serialize(v) else res = tostring(v) end
res = res .. ","
end
return res .. "}"
end
f:write("return " .. serialize(route))
f:close()
sampAddChatMessage("{00FF00}[Route] Сохранено! Античит-фильтры применены.", -1)
end
end
local function loadAuto()
local f = io.open(path, "r")
if f then
local content = f:read("*all")
f:close()
local loader = load(content)
if loader then route = loader() play_index = 1 return true end
end
return false
end
imgui.OnFrame(function() return show_menu[1] end, function(player)
imgui.SetNextWindowSize(imgui.ImVec2(450, 250), imgui.Cond.FirstUseEver)
imgui.Begin(u8"Anti-Kick Route v9.0", nil)
if imgui.Button(recording and u8"СТОП (СОХРАНИТЬ)" or u8"ЗАПИСАТЬ НОВЫЙ", imgui.ImVec2(-1, 50)) then
if not recording then route = {} start_time = getCurrentTime() recording = true playing = false
else recording = false saveAuto() end
end
imgui.Separator()
if #route > 0 then
if imgui.Button(playing and u8"ВЫКЛЮЧИТЬ" or u8"ВКЛЮЧИТЬ (БЕЗ КИКА)", imgui.ImVec2(-1, 80)) then
playing = not playing
play_index = 1
play_start_time = getCurrentTime()
end
else
if imgui.Button(u8"ЗАГРУЗИТЬ ПОСЛЕДНИЙ", imgui.ImVec2(-1, 40)) then loadAuto() end
end
imgui.End()
end)
function main()
os.execute('mkdir -p /sdcard/Download/game/')
while not isSampAvailable() do wait(100) end
sampRegisterChatCommand("route", function() show_menu[1] = not show_menu[1] end)
while true do
wait(0)
if playing and #route > 0 then
local now = getCurrentTime()
local elapsed = now - play_start_time
while route[play_index] and elapsed >= route[play_index].t do
local item = route[play_index]
if isCharInAnyCar(PLAYER_PED) then
local car = storeCarCharIsInNoSave(PLAYER_PED)
local px, py, pz = getCarCoordinates(car)
-- АНТИ-КИК ЛОГИКА:
-- Не телепортируем, если расстояние больше 5 метров (защита от кика за ТП)
local dist = math.sqrt((item.s.pos.x - px)^2 + (item.s.pos.y - py)^2)
if dist < 5.0 then
setCarCoordinates(car, item.s.pos.x, item.s.pos.y, item.s.pos.z)
end
-- Ограничение скорости (защита от кика за SpeedHack)
local speed = math.sqrt(item.s.spd.x^2 + item.s.spd.y^2 + item.s.spd.z^2)
if speed > 0.9 then speed = 0.9 end -- Лимит скорости для синхры
setCarForwardSpeed(car, speed * 45.0)
end
-- Отправка пакета (уменьшаем множитель скорости в пакете)
local bs = raknetNewBitStream()
raknetBitStreamWriteInt8(bs, item.id)
if item.type == 'v' then
raknetBitStreamWriteInt16(bs, item.s.vId)
raknetBitStreamWriteInt16(bs, item.s.lr or 0)
raknetBitStreamWriteInt16(bs, item.s.ud or 0)
raknetBitStreamWriteInt16(bs, item.s.keys or 0)
for i=1, 4 do raknetBitStreamWriteFloat(bs, item.s.quat or 0.0) end
raknetBitStreamWriteFloat(bs, item.s.pos.x)
raknetBitStreamWriteFloat(bs, item.s.pos.y)
raknetBitStreamWriteFloat(bs, item.s.pos.z)
-- Занижаем скорость в пакете, чтобы сервер не ругался
raknetBitStreamWriteFloat(bs, item.s.spd.x * 0.7)
raknetBitStreamWriteFloat(bs, item.s.spd.y * 0.7)
raknetBitStreamWriteFloat(bs, item.s.spd.z * 0.7)
raknetBitStreamWriteFloat(bs, 1000.0)
raknetBitStreamWriteInt8(bs, 100)
raknetBitStreamWriteInt8(bs, 0)
raknetBitStreamWriteInt8(bs, 0)
raknetBitStreamWriteInt8(bs, 0)
raknetBitStreamWriteInt8(bs, 0)
raknetBitStreamWriteInt32(bs, 0)
end
raknetSendBitStream(bs)
raknetDeleteBitStream(bs)
play_index = play_index + 1
if not route[play_index] then break end
end
if play_index > #route then playing = false end
end
end
end
-- Функции записи
function samp.onSendVehicleSync(data)
if recording then
table.insert(route, {
t = getCurrentTime() - start_time, type = 'v', id = 200,
s = {
vId = data.vehicleId,
pos = {x = data.position.x, y = data.position.y, z = data.position.z},
spd = {x = data.moveSpeed.x, y = data.moveSpeed.y, z = data.moveSpeed.z},
quat = {data.quaternion[0], data.quaternion[1], data.quaternion[2], data.quaternion[3]},
lr = data.leftRightKeys, ud = data.upDownKeys, keys = data.keysData
}
})
end
end
Вот сам скрипт
local samp = require 'lib.samp.events'
local imgui = require 'mimgui'
local encoding = require 'encoding'
local ffi = require 'ffi'
encoding.default = 'utf-8'
local u8 = encoding.UTF8
local path = "/sdcard/Download/game/autopilot.lua"
local recording, playing = false, false
local route, start_time, play_start_time, play_index = {}, 0, 0, 1
local show_menu = {false}
local function getCurrentTime() return os.clock() * 1000 end
-- Сохранение и загрузка (как в v8.0)
local function saveAuto()
local f = io.open(path, "w")
if f then
local function serialize(t)
local res = "{"
for k, v in pairs(t) do
res = res .. "[" .. (type(k) == "string" and string.format("%q", k) or k) .. "]="
if type(v) == "table" then res = res .. serialize(v) else res = tostring(v) end
res = res .. ","
end
return res .. "}"
end
f:write("return " .. serialize(route))
f:close()
sampAddChatMessage("{00FF00}[Route] Сохранено! Античит-фильтры применены.", -1)
end
end
local function loadAuto()
local f = io.open(path, "r")
if f then
local content = f:read("*all")
f:close()
local loader = load(content)
if loader then route = loader() play_index = 1 return true end
end
return false
end
imgui.OnFrame(function() return show_menu[1] end, function(player)
imgui.SetNextWindowSize(imgui.ImVec2(450, 250), imgui.Cond.FirstUseEver)
imgui.Begin(u8"Anti-Kick Route v9.0", nil)
if imgui.Button(recording and u8"СТОП (СОХРАНИТЬ)" or u8"ЗАПИСАТЬ НОВЫЙ", imgui.ImVec2(-1, 50)) then
if not recording then route = {} start_time = getCurrentTime() recording = true playing = false
else recording = false saveAuto() end
end
imgui.Separator()
if #route > 0 then
if imgui.Button(playing and u8"ВЫКЛЮЧИТЬ" or u8"ВКЛЮЧИТЬ (БЕЗ КИКА)", imgui.ImVec2(-1, 80)) then
playing = not playing
play_index = 1
play_start_time = getCurrentTime()
end
else
if imgui.Button(u8"ЗАГРУЗИТЬ ПОСЛЕДНИЙ", imgui.ImVec2(-1, 40)) then loadAuto() end
end
imgui.End()
end)
function main()
os.execute('mkdir -p /sdcard/Download/game/')
while not isSampAvailable() do wait(100) end
sampRegisterChatCommand("route", function() show_menu[1] = not show_menu[1] end)
while true do
wait(0)
if playing and #route > 0 then
local now = getCurrentTime()
local elapsed = now - play_start_time
while route[play_index] and elapsed >= route[play_index].t do
local item = route[play_index]
if isCharInAnyCar(PLAYER_PED) then
local car = storeCarCharIsInNoSave(PLAYER_PED)
local px, py, pz = getCarCoordinates(car)
-- АНТИ-КИК ЛОГИКА:
-- Не телепортируем, если расстояние больше 5 метров (защита от кика за ТП)
local dist = math.sqrt((item.s.pos.x - px)^2 + (item.s.pos.y - py)^2)
if dist < 5.0 then
setCarCoordinates(car, item.s.pos.x, item.s.pos.y, item.s.pos.z)
end
-- Ограничение скорости (защита от кика за SpeedHack)
local speed = math.sqrt(item.s.spd.x^2 + item.s.spd.y^2 + item.s.spd.z^2)
if speed > 0.9 then speed = 0.9 end -- Лимит скорости для синхры
setCarForwardSpeed(car, speed * 45.0)
end
-- Отправка пакета (уменьшаем множитель скорости в пакете)
local bs = raknetNewBitStream()
raknetBitStreamWriteInt8(bs, item.id)
if item.type == 'v' then
raknetBitStreamWriteInt16(bs, item.s.vId)
raknetBitStreamWriteInt16(bs, item.s.lr or 0)
raknetBitStreamWriteInt16(bs, item.s.ud or 0)
raknetBitStreamWriteInt16(bs, item.s.keys or 0)
for i=1, 4 do raknetBitStreamWriteFloat(bs, item.s.quat or 0.0) end
raknetBitStreamWriteFloat(bs, item.s.pos.x)
raknetBitStreamWriteFloat(bs, item.s.pos.y)
raknetBitStreamWriteFloat(bs, item.s.pos.z)
-- Занижаем скорость в пакете, чтобы сервер не ругался
raknetBitStreamWriteFloat(bs, item.s.spd.x * 0.7)
raknetBitStreamWriteFloat(bs, item.s.spd.y * 0.7)
raknetBitStreamWriteFloat(bs, item.s.spd.z * 0.7)
raknetBitStreamWriteFloat(bs, 1000.0)
raknetBitStreamWriteInt8(bs, 100)
raknetBitStreamWriteInt8(bs, 0)
raknetBitStreamWriteInt8(bs, 0)
raknetBitStreamWriteInt8(bs, 0)
raknetBitStreamWriteInt8(bs, 0)
raknetBitStreamWriteInt32(bs, 0)
end
raknetSendBitStream(bs)
raknetDeleteBitStream(bs)
play_index = play_index + 1
if not route[play_index] then break end
end
if play_index > #route then playing = false end
end
end
end
-- Функции записи
function samp.onSendVehicleSync(data)
if recording then
table.insert(route, {
t = getCurrentTime() - start_time, type = 'v', id = 200,
s = {
vId = data.vehicleId,
pos = {x = data.position.x, y = data.position.y, z = data.position.z},
spd = {x = data.moveSpeed.x, y = data.moveSpeed.y, z = data.moveSpeed.z},
quat = {data.quaternion[0], data.quaternion[1], data.quaternion[2], data.quaternion[3]},
lr = data.leftRightKeys, ud = data.upDownKeys, keys = data.keysData
}
})
end
end
Вот сам скрипт