Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 51 additions & 9 deletions client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -130,36 +130,78 @@ end)

--Spike Strip Spawn Event
local SpawnedSpikes = {}

RegisterNetEvent('SEM_InteractionMenu:Spikes-SpawnSpikes')
AddEventHandler('SEM_InteractionMenu:Spikes-SpawnSpikes', function(Length)
if IsPedInAnyVehicle(PlayerPedId(), false) then
Notify('~r~You can\'t set spikes while in a vehicle!')
return
end

local SpawnCoords = GetOffsetFromEntityInWorldCoords(GetPlayerPed(PlayerId()) , 0.0, 2.0, 0.0)
local ped = PlayerPedId()
local SpawnCoords = GetOffsetFromEntityInWorldCoords(ped, 0.0, 2.0, 0.0)

local group = {}

for a = 1, Length do
local Spike = CreateObject(GetHashKey('P_ld_stinger_s'), SpawnCoords.x, SpawnCoords.y, SpawnCoords.z, 1, 1, 1)
local Spike = CreateObject(GetHashKey('P_ld_stinger_s'), SpawnCoords.x, SpawnCoords.y, SpawnCoords.z, true, true, true)
local NetID = NetworkGetNetworkIdFromEntity(Spike)

SetNetworkIdExistsOnAllMachines(NetID, true)
SetNetworkIdCanMigrate(NetID, false)
SetEntityHeading(Spike, GetEntityHeading(GetPlayerPed(PlayerId()) ))

SetEntityHeading(Spike, GetEntityHeading(ped))
PlaceObjectOnGroundProperly(Spike)
FreezeEntityPosition(Spike, true)

table.insert(group, {
NetID = NetID,
Coords = GetEntityCoords(Spike)
})

SpawnCoords = GetOffsetFromEntityInWorldCoords(Spike, 0.0, 4.0, 0.0)
table.insert(SpawnedSpikes, NetID)
end

table.insert(SpawnedSpikes, group)
end)

--Spike Strip Delete Event
RegisterNetEvent('SEM_InteractionMenu:Spikes-DeleteSpikes')
AddEventHandler('SEM_InteractionMenu:Spikes-DeleteSpikes', function()
for a = 1, #SpawnedSpikes do
local Spike = NetworkGetEntityFromNetworkId(SpawnedSpikes[a])
DeleteEntity(Spike)
local ped = PlayerPedId()
local playerCoords = GetEntityCoords(ped)

local closestIndex = nil
local closestDist = math.huge

for i = 1, #SpawnedSpikes do
local group = SpawnedSpikes[i]
local coords = group[1].Coords
local dist = #(playerCoords - coords)

if dist < closestDist then
closestDist = dist
closestIndex = i
end
end

if not closestIndex or closestDist > 15 then
Notify('~r~No spikes found nearby')
return
end
Notify('~r~Spikes Strips Removed!')
SpawnedSpikes = {}

local group = SpawnedSpikes[closestIndex]

for i = 1, #group do
local entity = NetworkGetEntityFromNetworkId(group[i].NetID)
if DoesEntityExist(entity) then
DeleteEntity(entity)
end
end

table.remove(SpawnedSpikes, closestIndex)

Notify('~r~Removed Spikes')
end)

--Spike Strip Tire Popping
Expand Down