Integrate this nitrous script into your FiveM server to enhance your vehicle customization experience. This script uses qb-target
and interacts with the nitrous
item to allow players to install nitrous on their vehicles dynamically.
This script allows players to approach a vehicle, target the nitrous item, and initiate a progress bar. Once the progress is complete, the vehicle will have nitrous installed, providing an enhanced driving experience.
Here's the implementation of the nitrous script for your FiveM server:
-- qb-target setup
exports['qb-target']:AddTargetModel('car', {
options = {
{
event = "nitrous:install",
icon = "fas fa-wrench",
label = "Install Nitrous",
item = "nitrous",
},
},
distance = 2.5,
})
-- Register the event for nitrous installation
RegisterNetEvent('nitrous:install')
AddEventHandler('nitrous:install', function(data)
local playerPed = PlayerPedId()
local vehicle = GetVehiclePedIsIn(playerPed, false)
if vehicle and data.item == "nitrous" then
-- Open the vehicle's hood
SetVehicleDoorOpen(vehicle, 4, false, false)
-- Focus camera on the engine
local coords = GetEntityCoords(vehicle)
local cam = CreateCamWithParams("DEFAULT_SCRIPTED_CAMERA", coords.x, coords.y, coords.z + 0.5, 0, 0, 0, 45.0, false, 0)
PointCamAtEntity(cam, vehicle, 0, 0, 0, true)
RenderScriptCams(true, false, 0, true, true)
-- Show progress bar
exports['progressbar']:Progress({
name = "installing_nitrous",
duration = 10000,
label = "Installing Nitrous...",
useWhileDead = false,
canCancel = false,
controlDisables = {
disableMovement = true,
disableCarMovement = true,
disableMouse = false,
disableCombat = true,
},
animation = {
animDict = "mini@repair",
anim = "fixing_a_player",
flags = 49,
},
}, function(status)
if not status then
-- Close the hood and reset camera
SetVehicleDoorShut(vehicle, 4, false)
RenderScriptCams(false, false, 0, true, true)
DestroyCam(cam, false)
-- Install nitrous
TriggerServerEvent('nitrous:installOnServer', GetVehicleNumberPlateText(vehicle))
TriggerEvent('chat:addMessage', {
color = {255, 0, 0},
multiline = true,
args = {"System", "Nitrous installed successfully!"}
})
end
end)
end
end)
-- Server-side event to handle nitrous installation
RegisterNetEvent('nitrous:installOnServer')
AddEventHandler('nitrous:installOnServer', function(plate)
local src = source
local xPlayer = QBCore.Functions.GetPlayer(src)
local vehicle = GetVehicleByPlate(plate)
-- Ensure the vehicle exists and the player has nitrous item
if vehicle and xPlayer.Functions.GetItemByName('nitrous') then
-- Add nitrous to the vehicle's metadata
MySQL.Async.execute('UPDATE owned_vehicles SET nitrous = 1 WHERE plate = @plate', {
['@plate'] = plate
})
-- Remove nitrous item from player inventory
xPlayer.Functions.RemoveItem('nitrous', 1)
TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items['nitrous'], "remove")
end
end)