Destroy Cheaters Car

Trying to destroy the car of cheater if they spawn one in or change the features of the car, like add armor, make invincible, lock the doors, etc. Well, not happening.

First issue: how do i tell if a player spawns in a vehicle? I don’t see anything in the natives that tells how the vehicle came to be. Could this be an event? If so, how do I access and use the event?

Second issue is destroying the vehicle. What I have now is:

  • lock the doors so the player can’t get out, works great.
  • Turn on the alarm to draw attention to those near by, the alarm doesn’t sound.
  • I wait to give those around the vehicle time to move away, the script doesn’t wait.
  • The vehicle then explodes, taking the cheater with them. Vehicles doesn’t explode

Two versions of the code I have tried, neither works.

Citizen.CreateThread(function()
– get the player info
playerPed = GetPlayerPed(-1)
playerid = PlayerId()
playername = GetPlayerName(playerid)

while true do
Wait(1)
vehicle = GetVehiclePedIsIn(playerPed, 1)
if vehicle then
SendNUIMessage({
playsound = “termination.ogg”,
soundvolume = volume
})
SetVehicleDoorsLocked(vehicle, 4) <-- works as expected
StartVehicleAlarm(vehicle) <-- does not work
Wait(300) <— does not work
ExplodeVehicle(vehicle, true, true) <-- does not work
end
end
end)

Using AddExplosion as suggested in another threat that never showed any code:

Citizen.CreateThread(function()
– get the player info
playerPed = GetPlayerPed(-1)
playerid = PlayerId()
playername = GetPlayerName(playerid)

while true do
Wait(1)
vehicle = GetVehiclePedIsIn(playerPed, 1)
if vehicle then
SendNUIMessage({
playsound = “termination.ogg”,
soundvolume = volume
})
SetVehicleDoorsLocked(vehicle, 4) <-- works as expected
StartVehicleAlarm(vehicle) <-- does not work
Wait(300) <— does not work
x, y, z = table.unpack(GetEntityCoords(playerPed, true)) <— works as expected
AddExplosion(x, y, z, “EXPLOSION_ROCKET”, 100000000000, true, true, true) < — does not work
end
end
end)

Thanks for any help.

MY first thought on the alarm part is. StartVehicleAlarm is probably not working on vehicles that has no alarm. So i searched and found - > VEHICLE::SET_VEHICLE_ALARM = setvehiclealarm(vehicle, true/false).

For the explosion.

Maybe this one works?
function NetworkExplodeVehicle(vehicle, p1, p2, p3)
return _in(0x301A42153C9AD707, vehicle, p1, p2, p3, _r)
end

Thank you, got what i wanted with the explosion,. I got rid of locking the doors and the alarm and just blew up the car. Modified code below. Now i need to know why Wait(300) is not working, but everything else does.

local vehicle = Citizen.InvokeNative(0x9A9112A0FE9A4713, playerPed, false)
if vehicle then
– destroy the car
Citizen.InvokeNative(0x301A42153C9AD707, vehicle, true, true, true)
– play termination sound
PlayTermination()
– broadcast cheater message
killmessage = playername … " got caught in a booby trapped vehicle."
TriggerServerEvent(“ZA:BroadcastMessage”, killmessage)
– prevent cheater message and sound from repeating several times
Wait(300) <-- doesn’t work
end

Actually, it does work 100% now, just needed to increase the wait time to a lot more than 300, more like 3000.

Testing has shown there’s a problem, I can’t figure out what to solve it. The vehicle gets destroyed with the player in it, the wait time works to prevent multiple occurrences of the announcer voice and the chat text. When the player spawns another vehicle, the destroyed vehicle disappears. That’s fine, when the player gets in the new vehicle, nothing happens. I have confirmed the script is still running and attempting to detect the vehicle the player is in, except Citizen.InvokeNative(0x9A9112A0FE9A4713, playerPed, false) (or even setting the false to true) gets nothing, even when the player is in a vehicle.

The only way for the script to detect the player is in the vehicle is to restart the script in the server console.

To try to fix this I looked over the natives and found void RESET_PED_LAST_VEHICLE(Ped ped) // BB8DE8CF6A8DD8BB 5E3B5942. That doesn’t help. I tried void DELETE_VEHICLE(Vehicle *vehicle) // EA386986E786A54F 9803AF60, but vehicles aren’t deleted. I even tried setting the owner with void SET_VEHICLE_HAS_BEEN_OWNED_BY_PLAYER(Vehicle vehicle, BOOL owned) // 2B5F9D2AF1F1722D B4D3DBFB and then deleting the vehicle, vehicle still doesn’t go away.

Everything I try doesn’t fix not being able to detect if the player is in a vehicle after the first vehicle is destoyed.

Any suggestions?

I figured out when the vehicle is destroyed, deleting the vehicle doesn’t work. Instead of destroying the vehicle, I just delete it. Talk about anticlimactic.

Since the last update, I had to switch to MrScammer’s Model Blacklist mod and modify that for my purposes. The update took my code and made it work for the first car only.

Thanks for the help everyone.

2 Likes