[Release] Hydroplaning Script

Hydroplaning Script for FiveM

SGN Spiral Gaming Network

Description

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

  1. Download the script GitHub - SpaceDrout/sgn-hydroplaning
    and place it in your server’s resources folder. Use a folder name like sgn-hydroplaning.
  2. Ensure the folder structure looks like this:
    resources/
    └── sgn-hydroplaning/
        ├── fxmanifest.lua
        ├── client.lua
    
  3. Add the script to your server.cfg file:
    ensure sgn-hydroplaning
    
  4. Restart your server or run the following commands in the server console:
    refresh
    start sgn-hydroplaning
    

How It Works

  1. The script constantly checks the player’s speed and weather conditions.
  2. If the speed exceeds the threshold and the weather matches a condition in WeatherConditions, the vehicle loses grip for the specified duration.
  3. AI vehicles are also affected by the same logic.

Requirements

  • FiveM server (latest version recommended).

Support

If you encounter any issues or have suggestions, feel free to reach out to the script author: SpaceDrout.


License

This script is provided as-is without any warranty. Redistribution or modification is allowed as long as credit is given to the author.

4 Likes

Hello amazing release, what’s the resmon on it?

Use GetGamePool("CVehicle") instead to get all client side vehicles: GetGamePool - FiveM Natives @ Cfx.re Docs
No need for your own function :slight_smile:

3 Likes

Mate 1.67ms is a lot

– 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

-- Temporarily reduce vehicle traction  
SetVehicleReduceGrip(vehicle, true)  
Wait(Config.GripLossDuration)  
SetVehicleReduceGrip(vehicle, false)  

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  

end)

Cool script !
I didn’t plan to make it effect to npc veh. So comment all that part out and now resmon only around 0.01 :smiley: