[Release] Police Spike strip non-scripthook version

Disclaimer : educational code

What is it

Here some code I made for SeedlessRP to allow police place Spike strip on the ground to blow out all tires and delete once the first vehicle drives over them.

you can freely use this on your server so long as you give credit it is also for educational use for people to learn how to interact with objects in game.

Description

reason for making this we did not want to use any form of script hook within our server so its a 100% custom lua script by me, it has room for improvement may be placing trips in front of you would be nice change, if you do any changes let me know thanks very much this code is untested on FXserver, but i dont see why it would not work but you can also let me know if it dont work.

[client.lua]

RegisterNetEvent('c_setSpike')
AddEventHandler('c_setSpike', function()
    SetSpikesOnGround()
end)

function SetSpikesOnGround()
    x, y, z = table.unpack(GetEntityCoords(GetPlayerPed(-1), true))

    spike = GetHashKey("P_ld_stinger_s")

    RequestModel(spike)
    while not HasModelLoaded(spike) do
      Citizen.Wait(1)
    end

    local object = CreateObject(spike, x+1, y, z-2, true, true, false) -- x+1
    PlaceObjectOnGroundProperly(object)
end

Citizen.CreateThread(function()
  while true do
    Citizen.Wait(0)
    local ped = GetPlayerPed(-1)
    local veh = GetVehiclePedIsIn(ped, false)
    local vehCoord = GetEntityCoords(veh)
    if IsPedInAnyVehicle(ped, false) then
      if DoesObjectOfTypeExistAtCoords(vehCoord["x"], vehCoord["y"], vehCoord["z"], 0.9, GetHashKey("P_ld_stinger_s"), true) then
         SetVehicleTyreBurst(veh, 0, true, 1000.0)
         SetVehicleTyreBurst(veh, 1, true, 1000.0)
         SetVehicleTyreBurst(veh, 2, true, 1000.0)
         SetVehicleTyreBurst(veh, 3, true, 1000.0)
         SetVehicleTyreBurst(veh, 4, true, 1000.0)
         SetVehicleTyreBurst(veh, 5, true, 1000.0)
         SetVehicleTyreBurst(veh, 6, true, 1000.0)
         SetVehicleTyreBurst(veh, 7, true, 1000.0)
         RemoveSpike()
       end
     end
   end
end)

function RemoveSpike()
   local ped = GetPlayerPed(-1)
   local veh = GetVehiclePedIsIn(ped, false)
   local vehCoord = GetEntityCoords(veh)
   if DoesObjectOfTypeExistAtCoords(vehCoord["x"], vehCoord["y"], vehCoord["z"], 0.9, GetHashKey("P_ld_stinger_s"), true) then
      spike = GetClosestObjectOfType(vehCoord["x"], vehCoord["y"], vehCoord["z"], 0.9, GetHashKey("P_ld_stinger_s"), false, false, false)
      SetEntityAsMissionEntity(spike, true, true)
      DeleteObject(spike)
   end
end

ES – [server.lua]

TriggerEvent('es:addCommand', 'spike', function(source) -- usage /spike in chat maybe change to a hot key at later date
  TriggerEvent('es:getPlayerFromId', source, function(user)
     if user.job == "police"  then -- set police job can also use [ user.permission_level >= 2 ] in place of job if need be
        TriggerClientEvent('c_setSpike', source)
     end
  end)
end)

non ES – [server.lua]
warning this version has no check for your current job you will need to add this yourself.

AddEventHandler('chatMessage', function(source, n, msg)  -- usage /spike in chat maybe change to a hot key at later date
   msg = string.lower(msg)
   if (msg == "/spike") then
      CancelEvent()
      TriggerClientEvent('c_setSpike', source)
   end
end)

[__resource.lua]

client_script "client.lua"
server_script "server.lua"

Thanks

8 Likes

Just tested, it’s working! Thanks!

I personally added a little Wait between the tire burst sets, like this:

         RemoveSpike()
         SetVehicleTyreBurst(veh, 0, true, 1000.0)
         SetVehicleTyreBurst(veh, 1, true, 1000.0)
         Citizen.Wait(200)
         SetVehicleTyreBurst(veh, 2, true, 1000.0)
         SetVehicleTyreBurst(veh, 3, true, 1000.0)
         Citizen.Wait(200)
         SetVehicleTyreBurst(veh, 4, true, 1000.0)
         SetVehicleTyreBurst(veh, 5, true, 1000.0)
         SetVehicleTyreBurst(veh, 6, true, 1000.0)
         SetVehicleTyreBurst(veh, 7, true, 1000.0)

When a player is detected, it looks a lot more legit as the tires pop in sets, not at once.

ya thats not a bad idea :slight_smile:

1 Like

would that go in the client or server files/

If you manage to find any “SetVehicleTyreBurst” in the server.lua file, go ahead and place them there.
Otherwise it’s a clientside native, so place it in the client.lua.

damn this is for es isnt it

Yes aegood but am sure with a little work ID making a custom check it can work for all only ES part that is used is for the permission / job check just replace that for what ever your using own check.

also I did put in client and server tags it clearly shows what goes were :smiley:

1 Like

I have updated code to add a none ES /command however like stated in that code you will need to write your own job check.

1 Like

Error…


Error parsing script server.lua in resource furapneuspike: server.lua:3: 'then' expected near '='

any ideia ?

Why not post it in the form of a resource? Why as code?

Just make a __resource.lua, client.lua, server.lua file and copy paste the code in there, it takes 30 seconds.

If you are using the ES version, the if user.job = "police" is missing an equal mark, change to if user.job == "police"

2 Likes

nice spot ha :smiley: ok updated code and added resource.lua code for the lazy people :smiley:

2 Likes

legend
20 characters

:slight_smile:

Yes, I know how to make a resource. My questions was why didn’t he upload it as a resource. I didn’t ask how to.

Disclaimer : educational code, idea for this release was to show you how its done and yes you can use it way it is but its educational mostly and giving a direct link to a zip prevents that

2 Likes

when i run over the spike strips they do not delete themselves, any idea why. (im using vrp)

I had the same issue with the delay edit by @FiveTwelve I took out the delay and it deletes everytime now. For some reason driving over the strip at high speed didn’t delete it, if you slowly drive over it will delete itself.

could you post the code you use please

I reinstalled the mod, cleared my cache and used the original client.lua code and the non-es version of server.lua that @wpgn provided. I made no other changes to the script.

I use es4, esrp, and fivem police.