Skip to content

Instantly share code, notes, and snippets.

@kasuganosoras
Last active May 28, 2023 22:28
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kasuganosoras/c3384c5df3fcd2ffdd94c0032b686e72 to your computer and use it in GitHub Desktop.
Save kasuganosoras/c3384c5df3fcd2ffdd94c0032b686e72 to your computer and use it in GitHub Desktop.
FiveM dsmoke plugin
--[[===================]]
--[[=== C O N F I G ===]]
--[[===================]]
local CONFIG = {
size = 0.2,
dens = 10,
burnout_size = 0.8,
bind_key = 10,
smoke_on = true,
-- If this true, player can see the drift smoke for near car
multiplayer = true,
-- The distance of other cars to display drift smoke
distance = 30.0,
}
--[[===============]]
--[[=== C O D E ===]]
--[[===============]]
local bone_list = {"wheel_lr","wheel_rr"}
local entityEnumerator = {
__gc = function(enum)
if enum.destructor and enum.handle then
enum.destructor(enum.handle)
end
enum.destructor = nil
enum.handle = nil
end
}
local function EnumerateEntities(initFunc, moveFunc, disposeFunc)
return coroutine.wrap(function()
local iter, id = initFunc()
if not id or id == 0 then
disposeFunc(iter)
return
end
local enum = {handle = iter, destructor = disposeFunc}
setmetatable(enum, entityEnumerator)
local next = true
repeat
coroutine.yield(id)
next, id = moveFunc(iter)
until not next
enum.destructor, enum.handle = nil, nil
disposeFunc(iter)
end)
end
function EnumerateVehicles()
return EnumerateEntities(FindFirstVehicle, FindNextVehicle, EndFindVehicle)
end
Citizen.CreateThread(function()
base = "scr_recartheft"
base2 = "core"
Request(base)
Request(base2)
while true do Citizen.Wait(0)
ped = GetPlayerPed(-1)
car = GetVehiclePedIsUsing(ped)
selfPos = GetEntityCoords(ped)
ang,speed = angle(car)
if IsControlJustPressed(0, CONFIG.bind_key) then
CONFIG.smoke_on = not CONFIG.smoke_on
if CONFIG.smoke_on then Notify('~c~DriftSmoke ~g~ON') else Notify('~c~DriftSmoke ~r~OFF') end
end
if CONFIG.smoke_on then
if IsPedInAnyVehicle(GetPlayerPed(-1), false) and IsThisACar(car) then
if speed >= 3.0 and ang ~= 0 then
DriftSmoke(base,"scr_wheel_burnout", car, CONFIG.dens, CONFIG.size)
elseif speed < 1.0 and IsVehicleInBurnout(car) then
DriftSmoke(base2 ,"exp_grd_bzgas_smoke", car, 3, CONFIG.burnout_size)
end
end
if CONFIG.multiplayer then
for vehicle in EnumerateVehicles() do
vehPos = GetEntityCoords(vehicle)
if Vdist(selfPos.x, selfPos.y, selfPos.z, vehPos.x, vehPos.y, vehPos.z) < CONFIG.distance then
if IsThisACar(vehicle) then
ang2, speed2 = angle(vehicle)
if speed2 >= 3.0 and ang2 ~= 0 then
DriftSmoke(base,"scr_wheel_burnout", vehicle, CONFIG.dens, CONFIG.size)
elseif speed2 < 1.0 and IsVehicleInBurnout(vehicle) then
DriftSmoke(base2 ,"exp_grd_bzgas_smoke", vehicle, 3, CONFIG.burnout_size)
end
end
end
end
end
end
end
end)
--[[===============]]
--[[=== F U N C ===]]
--[[===============]]
function Request(name)
RequestNamedPtfxAsset(name)
while not HasNamedPtfxAssetLoaded(name) do
Wait(1)
end
end
function IsThisACar(entity)
return IsThisModelACar(GetEntityModel(entity))
end
function DriftSmoke(base, sub, car, dens, size)
all_part = {}
for i = 0,dens do
UseParticleFxAssetNextCall(base)
W1 = StartParticleFxLoopedOnEntityBone(sub, car, 0.05, 0, 0, 0, 0, 0, GetEntityBoneIndexByName(car, bone_list[1]), size, 0, 0, 0)
UseParticleFxAssetNextCall(base)
W2 = StartParticleFxLoopedOnEntityBone(sub, car, 0.05, 0, 0, 0, 0, 0, GetEntityBoneIndexByName(car, bone_list[2]), size, 0, 0, 0)
table.insert(all_part, 1, W1)
table.insert(all_part, 2, W2)
end
Citizen.Wait(1000)
for _,W1 in pairs(all_part) do
StopParticleFxLooped(W1, true)
end
end
function angle(veh)
if not veh then return false end
local vx,vy,vz = table.unpack(GetEntityVelocity(veh))
local modV = math.sqrt(vx*vx + vy*vy)
local rx,ry,rz = table.unpack(GetEntityRotation(veh,0))
local sn,cs = -math.sin(math.rad(rz)), math.cos(math.rad(rz))
if GetEntitySpeed(veh)* 3.6 < 5 or GetVehicleCurrentGear(veh) == 0 then return 0,modV end --speed over 30 km/h
local cosX = (sn*vx + cs*vy)/modV
if cosX > 0.966 or cosX < 0 then return 0,modV end
return math.deg(math.acos(cosX))*0.5, modV
end
function Notify(text)
SetNotificationTextEntry('STRING')
AddTextComponentString(text)
DrawNotification(true, false)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment