Бот прикольный, но он не доезжает несколько метров до финального чека, из за чего не может закончить маршрут
,братан встав ето заместь старого скрипта и все буде вери гут
-- Конфігурація
local config = {
maxSpeed = 42.0, -- Максимальна швидкість поїзда
acceleration = 10.0, -- Швидкість прискорення поїзда
deceleration = 10.0, -- Швидкість гальмування поїзда
decelerationDistance = 1.0, -- Відстань до початку гальмування
stopDistance = 0.1, -- Відстань, на якій поїзд повністю зупиняється
}
-- Статусні змінні
local state = {
isActive = false, -- Чи активний бот
autoEat = false, -- Чи увімкнено автохарчування
isBarVisible = true, -- Чи показувати інформацію в барі
currentSpeed = 0.0, -- Поточна швидкість
distToCheckpoint = 0, -- Відстань до наступної точки
}
-- Ключові змінні для позицій та кроків
local onfoot_step = 'nil'
-- Шрифти та відображення
local font = renderCreateFont('UBUNTU', 12, 4)
-- Реєстрація команд
function registerCommands()
sampRegisterChatCommand('TRAINBOT', function(arg)
if #arg == 0 then
state.isActive = not state.isActive
printStringNow('~p~TRAINBOT: ' .. (state.isActive and '~G~ON' or '~r~OFF'), 2000)
elseif arg == 'bar' then
state.isBarVisible = not state.isBarVisible
printStringNow('~p~TRAINBOT: BAR: ' .. (state.isBarVisible and '~G~ON' or '~r~OFF'))
elseif arg == 'autoeat' then
state.autoEat = not state.autoEat
printStringNow('~p~TRAINBOT: AUTO-EAT: ' .. (state.autoEat and '~G~ON' or '~r~OFF'))
end
end)
end
-- Основна функція бота
function main()
repeat wait(0) until isSampAvailable()
registerCommands()
while true do
wait(0)
if state.isActive then
if isCharInAnyCar(PLAYER_PED) then
handleTrainMovement()
else
if state.autoEat then
handleAutoEat()
end
handleOnFootMovement()
end
end
end
end
-- Обробка руху поїзда
function handleTrainMovement()
local res, mX, mY, mZ = SearchMarker()
local x, y, z = getCharCoordinates(PLAYER_PED)
state.distToCheckpoint = getDistanceBetweenCoords3d(x, y, z, mX, mY, mZ)
if state.distToCheckpoint > config.decelerationDistance then
accelerateTrain()
elseif state.distToCheckpoint <= config.decelerationDistance and state.distToCheckpoint > config.stopDistance then
decelerateTrain()
elseif state.distToCheckpoint <= config.stopDistance then
stopTrain()
end
end
-- Обробка автоматичного харчування
function handleAutoEat()
onfoot_step = 'RUNFIX'
runToPoint(-2097.1640625, 515.29943847656, 1487.6927490234) -- fix
onfoot_step = 'RUNHAVKA'
runToPoint(-2097.2338867188, 512.36212158203, 1487.6927490234) -- їжа
onfoot_step = 'EAT'
if onfoot_step == 'EAT' then
wait(300)
setGameKeyState(21, 255)
wait(0)
setGameKeyState(21, 0)
wait(200)
local havkadialogid = sampGetCurrentDialogId()
sampSendDialogResponse(havkadialogid, 1, 3, "")
wait(2000)
end
end
-- Обробка руху на пішки
function handleOnFootMovement()
onfoot_step = 'RUNREYS'
runToPoint(-2102.4118652344, 512.90368652344, 1487.6927490234) -- рейс
onfoot_step = 'TAKEREYS'
if onfoot_step == 'TAKEREYS' then
while not isCharInAnyCar(PLAYER_PED) and state.isActive do
setGameKeyState(21, 255)
wait(0)
setGameKeyState(21, 0)
wait(100)
local reysdialogid = sampGetCurrentDialogId()
sampSendDialogResponse(reysdialogid, 1, 0, "")
wait(500)
end
end
end
-- Плавне прискорення поїзда
function accelerateTrain()
if state.currentSpeed < config.maxSpeed then
state.currentSpeed = state.currentSpeed + config.acceleration
if state.currentSpeed > config.maxSpeed then state.currentSpeed = config.maxSpeed end
end
setTrainSpeed(storeCarCharIsInNoSave(PLAYER_PED), state.currentSpeed)
end
-- Плавне гальмування поїзда
function decelerateTrain()
if state.currentSpeed > 0 then
state.currentSpeed = state.currentSpeed - config.deceleration
if state.currentSpeed < 0 then state.currentSpeed = 0 end
end
setTrainSpeed(storeCarCharIsInNoSave(PLAYER_PED), state.currentSpeed)
end
-- Повна зупинка поїзда
function stopTrain()
state.currentSpeed = 0
setTrainSpeed(storeCarCharIsInNoSave(PLAYER_PED), state.currentSpeed)
end
-- Відображення статусу
lua_thread.create(function()
while true do
wait(0)
if state.isActive and isCharInAnyCar(PLAYER_PED) then
local res, mX, mY, mZ = SearchMarker()
local x, y, z = getCharCoordinates(PLAYER_PED)
state.distToCheckpoint = math.floor(getDistanceBetweenCoords3d(x, y, z, mX, mY, mZ))
end
if state.isBarVisible then
local botState = state.isActive and 'ON' or 'OFF'
local autoEatState = state.autoEat and 'ON' or 'OFF'
renderFontDrawText(font, '| {6495ed}TRAINBOT:\n{ffffff}| {6495ed}STATE = ' .. botState .. '\n{FFFFFF}|{6495ed} DIST TO NEXT POINT = ' .. state.distToCheckpoint .. '\n{FFFFFF}|{6495ed} AUTO-EAT = ' .. autoEatState, 500, 500, -1)
end
end
end)
-- Рух до точки
function runToPoint(tox, toy, q)
if state.isActive then
local x, y, z = getCharCoordinates(PLAYER_PED)
local angle = getHeadingFromVector2d(tox - x, toy - y)
local xAngle = math.random(-50, 50) / 100
setCameraPositionUnfixed(xAngle, math.rad(angle - 90))
while getDistanceBetweenCoords2d(x, y, tox, toy) > 0.8 and state.isActive do
setGameKeyState(1, -255)
wait(1)
x, y, z = getCharCoordinates(PLAYER_PED)
angle = getHeadingFromVector2d(tox - x, toy - y)
setCameraPositionUnfixed(xAngle, math.rad(angle - 90))
end
end
end
-- Пошук маркерів
function SearchMarker()
local ret_posX, ret_posY, ret_posZ = 0.0, 0.0, 0.0
for id = 0, 31, 1 do
local MarkerStruct = 0xC7F168 + id * 56
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
ret_posX = MarkerPosX
ret_posY = MarkerPosY
ret_posZ = MarkerPosZ
return true, ret_posX, ret_posY, ret_posZ
end
end
return false
end