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