require "lib.moonloader"
local vkeys = require "vkeys"
local memory = require "memory"
local is_active = false
local speed_limit = 57 -- Стандартное ограничение по умолчанию
local last_key_time = 0 -- Таймер для плавного изменения при зажатии
-- Функция проверки, является ли транспорт велосипедом
local function isBicycle(modelID)
-- 481: BMX, 509: Bike, 510: Mountain Bike
return modelID == 481 or modelID == 509 or modelID == 510
end
function main()
if not isSampLoaded() or not isSampfuncsLoaded() then return end
while not isSampAvailable() do wait(100) end
-- Команда активации/деактивации без сообщений в чат
sampRegisterChatCommand("velocity", function()
is_active = not is_active
if is_active then
printStringNow("~g~Velocity Limit ON ~w~(" .. speed_limit .. ")", 1500)
else
printStringNow("~r~Velocity Limit OFF", 1500)
end
end)
-- Команда: Установка лимита числом
sampRegisterChatCommand("vlimit", function(arg)
local val = tonumber(arg)
if val then
if val < 1 then val = 1 end -- Меньше 1 теперь поставить нельзя
speed_limit = val
printStringNow("~y~Limit set to: ~w~" .. tostring(speed_limit), 2000)
else
printStringNow("~r~Use: /vlimit [number]", 2000)
end
end)
while true do
wait(0)
-- Если скрипт включен и игрок в транспорте
if is_active and isCharInAnyCar(PLAYER_PED) then
local car = storeCarCharIsInNoSave(PLAYER_PED)
if car then
local model = getCarModel(car)
-- ПРОВЕРКА: Работаем ТОЛЬКО если это велосипед
if isBicycle(model) then
local current_time = os.clock()
-- Настройка скорости (Зажать L и УДЕРЖИВАТЬ Минус или Плюс)
if isKeyDown(vkeys.VK_L) then
-- Срабатывает каждые 0.05 секунд (20 раз в секунду), пока кнопка зажата
if isKeyDown(vkeys.VK_OEM_MINUS) and (current_time - last_key_time > 0.05) then
speed_limit = speed_limit - 1
if speed_limit < 1 then speed_limit = 1 end -- Защита (не меньше 1)
printStringNow("~y~Limit: ~w~" .. tostring(speed_limit), 1000)
last_key_time = current_time
elseif isKeyDown(vkeys.VK_OEM_PLUS) and (current_time - last_key_time > 0.05) then
speed_limit = speed_limit + 1
printStringNow("~y~Limit: ~w~" .. tostring(speed_limit), 1000)
last_key_time = current_time
end
end
-- Логика ограничения скорости
local ptr = getCarPointer(car)
if ptr ~= 0 then
-- Читаем текущую скорость машины (Векторы X и Y)
local vx = memory.getfloat(ptr + 0x44, false)
local vy = memory.getfloat(ptr + 0x48, false)
-- Считаем фактическую скорость по плоскости
local current_speed_ms = math.sqrt(vx * vx + vy * vy)
-- Переводим км/ч в метры/секунду
local max_speed_ms = speed_limit / 3.6
-- Если скорость превышает лимит, плавно срезаем её
if current_speed_ms > max_speed_ms then
if current_speed_ms > 0 then
local ratio = max_speed_ms / current_speed_ms
memory.setfloat(ptr + 0x44, vx * ratio, false)
memory.setfloat(ptr + 0x48, vy * ratio, false)
end
end
end
end
end
end
end
end