This script adds a realistic hydroplaning effect to vehicles in FiveM. When driving at high speeds during specific weather conditions, vehicles (both players and AI) may lose grip temporarily, simulating hydroplaning. The script is fully configurable.
Features
Hydroplaning effect based on speed and weather conditions.
Affects both player and AI vehicles.
Configurable speed threshold, grip loss duration, and weather conditions.
Configuration
You can configure the script by modifying the Config table in client.lua:
SpeedThreshold: Speed (in MPH) at which hydroplaning can occur.
GripLossDuration: Duration (in milliseconds) for which grip is lost.
WeatherConditions: List of weather types that trigger hydroplaning. Default conditions:
RAIN
THUNDER
Installation
Download the script GitHub - SpaceDrout/sgn-hydroplaning
and place it in your server’s resources folder. Use a folder name like sgn-hydroplaning.
– Hydroplaning Script for FiveM
– Author: SpaceDrout
local Config = {
SpeedThreshold = 50.0, – Speed (in MPH) at which hydroplaning can occur
GripLossDuration = 3000, – Duration of grip loss in milliseconds
WeatherConditions = { “RAIN”, “THUNDER”, “SNOW” } – Weather conditions that cause hydroplaning
}
– Utility function to check if the weather causes hydroplaning
local function isHydroplaningWeather()
local weatherType1, weatherType2, _ = GetWeatherTypeTransition()
for _, weather in ipairs(Config.WeatherConditions) do
local weatherHash = GetHashKey(weather)
if weatherType1 == weatherHash or weatherType2 == weatherHash then
return true
end
end
return false
end
– Function to handle hydroplaning effect
local function applyHydroplaning(vehicle)
if not DoesEntityExist(vehicle) or IsVehicleOnAllWheels(vehicle) then return end
– Main thread to monitor player and AI vehicles
CreateThread(function()
while true do
Wait(100)
-- Check if weather conditions allow hydroplaning
if not isHydroplaningWeather() then
Wait(1000) -- Check less frequently if no hydroplaning conditions
else
-- Check player vehicles
local playerPed = PlayerPedId()
if IsPedInAnyVehicle(playerPed, false) then
local vehicle = GetVehiclePedIsIn(playerPed, false)
local speed = GetEntitySpeed(vehicle) * 2.23694 -- Convert m/s to MPH
if speed > Config.SpeedThreshold then
applyHydroplaning(vehicle)
end
end
-- Check AI vehicles
local vehicles = GetGamePool("CVehicle")
for _, vehicle in ipairs(vehicles) do
if not IsPedAPlayer(GetPedInVehicleSeat(vehicle, -1)) then -- AI vehicle
local speed = GetEntitySpeed(vehicle) * 2.23694 -- Convert m/s to MPH
if speed > Config.SpeedThreshold then
applyHydroplaning(vehicle)
end
end
end
end
end