This repository was archived by the owner on Mar 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathclient.lua
170 lines (153 loc) · 6.23 KB
/
client.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
---------------------------------------------------------------------------
-- Important Variables --
---------------------------------------------------------------------------
local PoliceModels = {}
local SpawnedSpikes = {}
local spikemodel = "P_ld_stinger_s"
local nearSpikes = false
local spikesSpawned = false
---------------------------------------------------------------------------
-- Checking Distance To Spikestrips --
---------------------------------------------------------------------------
Citizen.CreateThread(function()
while true do
if IsPedInAnyVehicle(LocalPed(), false) then
local vehicle = GetVehiclePedIsIn(LocalPed(), false)
if GetPedInVehicleSeat(vehicle, -1) == LocalPed() then
local vehiclePos = GetEntityCoords(vehicle, false)
local spikes = GetClosestObjectOfType(vehiclePos.x, vehiclePos.y, vehiclePos.z, 80.0, GetHashKey(spikemodel), 1, 1, 1)
local spikePos = GetEntityCoords(spikes, false)
local distance = Vdist(vehiclePos.x, vehiclePos.y, vehiclePos.z, spikePos.x, spikePos.y, spikePos.z)
if spikes ~= 0 then
nearSpikes = true
else
nearSpikes = false
end
else
nearSpikes = false
end
else
nearSpikes = false
end
Citizen.Wait(0)
end
end)
---------------------------------------------------------------------------
-- Tire Popping --
---------------------------------------------------------------------------
Citizen.CreateThread(function()
while true do
if nearSpikes then
local tires = {
{bone = "wheel_lf", index = 0},
{bone = "wheel_rf", index = 1},
{bone = "wheel_lm", index = 2},
{bone = "wheel_rm", index = 3},
{bone = "wheel_lr", index = 4},
{bone = "wheel_rr", index = 5}
}
for a = 1, #tires do
local vehicle = GetVehiclePedIsIn(LocalPed(), false)
local tirePos = GetWorldPositionOfEntityBone(vehicle, GetEntityBoneIndexByName(vehicle, tires[a].bone))
local spike = GetClosestObjectOfType(tirePos.x, tirePos.y, tirePos.z, 15.0, GetHashKey(spikemodel), 1, 1, 1)
local spikePos = GetEntityCoords(spike, false)
local distance = Vdist(tirePos.x, tirePos.y, tirePos.z, spikePos.x, spikePos.y, spikePos.z)
if distance < 1.8 then
if not IsVehicleTyreBurst(vehicle, tires[a].index, true) or IsVehicleTyreBurst(vehicle, tires[a].index, false) then
SetVehicleTyreBurst(vehicle, tires[a].index, false, 1000.0)
end
end
end
end
Citizen.Wait(0)
end
end)
---------------------------------------------------------------------------
-- Keypresses Spikes Event --
---------------------------------------------------------------------------
Citizen.CreateThread(function()
while true do
if spikesSpawned then
DisplayNotification("To remove the spikstrips press ~INPUT_CHARACTER_WHEEL~ + ~INPUT_PHONE~")
if IsControlPressed(1, 19) and IsControlJustPressed(1, 27) then
RemoveSpikes()
spikesSpawned = false
end
end
Citizen.Wait(0)
end
end)
---------------------------------------------------------------------------
-- Spawn Spikes Event --
---------------------------------------------------------------------------
RegisterNetEvent("Spikes:SpawnSpikes")
AddEventHandler("Spikes:SpawnSpikes", function(config)
if config.isRestricted then
if CheckPedRestriction(LocalPed(), config.pedList) then
CreateSpikes(config.amount)
end
else
CreateSpikes(config.amount)
end
end)
---------------------------------------------------------------------------
-- Delete Spikes Event --
---------------------------------------------------------------------------
RegisterNetEvent("Spikes:DeleteSpikes")
AddEventHandler("Spikes:DeleteSpikes", function(netid)
Citizen.CreateThread(function()
local spike = NetworkGetEntityFromNetworkId(netid)
DeleteEntity(spike)
end)
end)
---------------------------------------------------------------------------
-- Extra Functions --
---------------------------------------------------------------------------
function CreateSpikes(amount)
local spawnCoords = GetOffsetFromEntityInWorldCoords(LocalPed(), 0.0, 2.0, 0.0)
for a = 1, amount do
local spike = CreateObject(GetHashKey(spikemodel), spawnCoords.x, spawnCoords.y, spawnCoords.z, 1, 1, 1)
local netid = NetworkGetNetworkIdFromEntity(spike)
SetNetworkIdExistsOnAllMachines(netid, true)
SetNetworkIdCanMigrate(netid, false)
SetEntityHeading(spike, GetEntityHeading(LocalPed()))
PlaceObjectOnGroundProperly(spike)
spawnCoords = GetOffsetFromEntityInWorldCoords(spike, 0.0, 4.0, 0.0)
table.insert(SpawnedSpikes, netid)
end
spikesSpawned = true
end
Citizen.CreateThread(function()
while true do
local dev = false
if dev then
local plyOffset = GetOffsetFromEntityInWorldCoords(LocalPed(), 0.0, 2.0, 0.0)
DrawMarker(0, plyOffset.x, plyOffset.y, plyOffset.z, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 2.0, 2.0, 255, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0)
local spike = GetClosestObjectOfType(plyOffset.x, plyOffset.y, plyOffset.z, 80.0, GetHashKey(spikemodel), 1, 1, 1)
Citizen.Trace("NETID: " .. ObjToNet(spike))
end
Citizen.Wait(0)
end
end)
function RemoveSpikes()
for a = 1, #SpawnedSpikes do
TriggerServerEvent("Spikes:TriggerDeleteSpikes", SpawnedSpikes[a])
end
SpawnedSpikes = {}
end
function LocalPed()
return GetPlayerPed(PlayerId())
end
function CheckPedRestriction(ped, pedList)
for a = 1, #pedList do
if GetHashKey(pedList[a]) == GetEntityModel(ped) then
return true
end
end
return false
end
function DisplayNotification(string)
SetTextComponentFormat("STRING")
AddTextComponentString(string)
DisplayHelpTextFromStringLabel(0, 0, 1, -1)
end