fivem scripting lua write the serverside for an oilslick script that makes your car…
- User
fivem scripting lua write the serverside for an oilslick script that makes your car slide when hitting in a car
here is the client side, Please generate the server side
-- This script allows the user to throw an item to create an oil slick this will make cars that hit it slide local AnimDict = "core"; local AnimName = "ent_anim_paparazzi_flash" local WeaponModel = "w_ex_oiltub" local Animations = {"anim@heists@ornate_bank@thermal_charge", "cover_eyes_intro"} local OilSlickEquiped = false local ped = GetPlayerPed(-1) local slipping = false
--table for oil slicks local_oil_slicks = {}
--local table of coords to handle local coords_to_handle = {}
--function for adding slip to vehicle function AddSlip() --create a thread Citizen.CreateThread(function() --get vehicle ped is in local vehicle = GetVehiclePedIsIn(ped, false) local old_val = GetVehicleHandlingFloat(vehicle, "CHandlingData", "fTractionCurveLateral") --set new traction value SetVehicleHandlingFloat(vehicle, "CHandlingData", "fTractionCurveLateral", old_val * 6) --wait 7 seconds Wait(7000) --set traction back to old value SetVehicleHandlingFloat(vehicle, "CHandlingData", "fTractionCurveLateral", old_val) --set slipping to false slipping = false end) end
--event to check local table and remove slick at location RegisterNetEvent('oil:delete_petrol_decal') AddEventHandler('oil:delete_petrol_decal', function(coords) for k,v in pairs(coords_to_handle) do if v == coords then RemoveDecal(k) --check local oil_slicks table and remove slick at location for k,v in pairs(local_oil_slicks) do if v == coords then local_oil_slicks[k]=nil end end end end end)
Citizen.CreateThread(function() while true do --if player in vehicle if IsPedInAnyVehicle(ped,false) and not slipping then for k,v in pairs(local_oil_slicks) do --get distance to slick local dist = #(GetEntityCoords(ped) - v) if dist < 4 then --tell server to tell clients to delete TriggerServerEvent('oil:delete_oil_slick', v) if slipping == false then slipping = true AddSlip() end end end end Wait(200) end end)
--function to create oil slick function CreateOilSlick(handle) -- thread do check for collision with ground Citizen.CreateThread(function() while true do --get coords of entity local coords = GetEntityCoords(handle) --draw line to it -- DrawLine(coords.x, coords.y, coords.z, coords.x, coords.y, coords.z - 10.0, 255, 0, 0, 255) local h = GetEntityHeightAboveGround(handle) --if collided with ground if h <= 0.3 then local coords = GetEntityCoords(handle) TriggerServerEvent('oil:create_oil_slick', coords) break end Wait(0) end end) end
Citizen.CreateThread(function() while true do ped = GetPlayerPed(-1) if OilSlickEquiped == false then if GetSelectedPedWeapon(ped) == 277905663 then OilSlickEquiped = true; end else if IsPedShooting(ped) then OilSlickEquiped = false; local pos = GetEntityCoords(ped) Wait(100) local handle = GetClosestObjectOfType(pos.x,pos.y,pos.z,50.0,GetHashKey(WeaponModel),false,false,false) if handle ~= 0 then CreateOilSlick(handle) end end end Wait(0) end end)
- Assistant
Here is the server side script for the oil slick functionality:
-- Server-side script for oil slick local oil_slicks = {} -- Event to create oil slick RegisterServerEvent('oil:create_oil_slick') AddEventHandler('oil:create_oil_slick', function(coords) -- Add the coords to the oil_slicks table table.insert(oil_slicks, coords) -- Broadcast to all clients to create the decal at the specified coords TriggerClientEvent('oil:create_petrol_decal', -1, coords, oil_slicks) end) -- Event to delete oil slick RegisterServerEvent('oil:delete_oil_slick') AddEventHandler('oil:delete_oil_slick', function(coords) -- Remove the coords from the oil_slicks table for i, v in ipairs(oil_slicks) do if v == coords then table.remove(oil_slicks, i) break end end -- Broadcast to all clients to remove the decal at the specified coords TriggerClientEvent('oil:delete_petrol_decal', -1, coords) end)This script will handle the creation and deletion of oil slicks on the server side, and broadcasts the corresponding events to all connected clients. It maintains the
oil_slickstable for all oil slicks created during the session.