I changed the name of the lastdamage and curdamage variables to lastDamage and curDamage, following the naming conventions in Lua.
Remove the curspeed variable as it was not being used in the code.
I removed the local line veh2 = GetVehiclePedIsIn(PlayerPedId(), false), as it was not being used.
Fixed the call GetVehiclePedIsIn(PlayerPedId(-1, false) to GetVehiclePedIsIn(PlayerPedId(), false) since you are already getting the current player with PlayerPedId().
I changed GetVehiclePedIsIn(GetPlayerPed(-1)) to GetVehiclePedIsIn(playerPed) since playerPed is the current player.
I checked that the vehicle variable is different from nil and 0 before waiting with damage and judder checks.
I used GetEntitySpeed(vehicle) instead of GetEntitySpeed(veh) to get the current vehicle speed.
I increased the readability of the code by adding proper spacing and indentation.
Keep in mind that these are code organization and style improvements only. I didn’t change the logic of the program itself, so if there are other possible problems in your original code, they are not addressed here.
local lastDamage = 0.0
local curDamage = 0.0
local vehicle = nil
Citizen.CreateThread(function()
while true do
local playerPed = PlayerPedId()
local vehicle = GetVehiclePedIsIn(playerPed, false)
if DoesEntityExist(vehicle) then
local shakeRate = GetEntitySpeed(vehicle) / 250.0
if vehicle ~= nil and vehicle ~= 0 then
local curHealth = GetVehicleBodyHealth(vehicle)
if curHealth ~= lastDamage then
ShakeGameplayCam("MEDIUM_EXPLOSION_SHAKE", shakeRate)
end
lastDamage = curHealth
end
end
Citizen.Wait(0)
end
Hello @YvaneOficial, I detect the collision by checking the vehicle damage every milisecond while inside the car, in terms of performance it may not be a very good method, tomorrow I’ll share an improved version, thanks for resmon stats