forked from RichMilly/FiveM-Pepper-Spray
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.lua
184 lines (165 loc) · 6.61 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
local config = {}
config.intensity = 4.0
config.timeUntilReload = 10.0
config.sprayRange = 3.0
config.sprayEffectTime = 10
local holdingpepperspray = false
local usingpepperspray = false
local peppersprayModel = "w_am_flare"
local animDict = "weapons@first_person@aim_rng@generic@projectile@shared@core"
local animName = "idlerng_med"
local particleDict = "scr_bike_business"
local particleName = "scr_bike_spraybottle_spray"
local actionTime = 8
local pepperspray_net = nil
---------------------------------------------------------------------------
-- Toggling pepperspray --
---------------------------------------------------------------------------
RegisterNetEvent("pepperspray:Togglepepperspray")
AddEventHandler("pepperspray:Togglepepperspray", function()
if not holdingpepperspray then
RequestModel(GetHashKey(peppersprayModel))
while not HasModelLoaded(GetHashKey(peppersprayModel)) do
Citizen.Wait(100)
end
RequestAnimDict(animDict)
while not HasAnimDictLoaded(animDict) do
Citizen.Wait(100)
end
local plyCoords = GetOffsetFromEntityInWorldCoords(GetPlayerPed(PlayerId()), 0.0, 0.0, -5.0)
local peppersprayspawned = CreateObject(GetHashKey(peppersprayModel), plyCoords.x, plyCoords.y, plyCoords.z, 1, 1, 1)
Citizen.Wait(1000)
local netid = ObjToNet(peppersprayspawned)
SetNetworkIdExistsOnAllMachines(netid, true)
NetworkSetNetworkIdDynamic(netid, true)
SetNetworkIdCanMigrate(netid, false)
AttachEntityToEntity(peppersprayspawned, GetPlayerPed(PlayerId()), GetPedBoneIndex(GetPlayerPed(PlayerId()), 28422), 0.05, -0.05, 0.0, 260.0, 0.0, 0.0, 1, 1, 0, 1, 0, 1)
--TaskPlayAnim(GetPlayerPed(PlayerId()), 1.0, -1, -1, 50, 0, 0, 0, 0) -- 50 = 32 + 16 + 2
TaskPlayAnim(GetPlayerPed(PlayerId()), animDict, animName, 1.0, -1, -1, 50, 0, 0, 0, 0)
pepperspray_net = netid
holdingpepperspray = true
else
ClearPedSecondaryTask(GetPlayerPed(PlayerId()))
DetachEntity(NetToObj(pepperspray_net), 1, 1)
DeleteEntity(NetToObj(pepperspray_net))
pepperspray_net = nil
holdingpepperspray = false
usingpepperspray = false
end
end)
---------------------------------------------------------------------------
-- Start Particles --
---------------------------------------------------------------------------
RegisterNetEvent("pepperspray:StartParticles")
AddEventHandler("pepperspray:StartParticles", function(peppersprayid)
local entity = NetToObj(peppersprayid)
RequestNamedPtfxAsset(particleDict)
while not HasNamedPtfxAssetLoaded(particleDict) do
Citizen.Wait(100)
end
UseParticleFxAssetNextCall(particleDict)
local particleEffect = StartParticleFxLoopedOnEntity(particleName, entity, 0.2, 0.002, 0.0, 0.0, -95.0, 180.0, config.intensity, false, false, false)
SetTimeout(10000, function()
usingpepperspray = false
end)
end)
---------------------------------------------------------------------------
-- Stop Particles --
---------------------------------------------------------------------------
RegisterNetEvent("pepperspray:StopParticles")
AddEventHandler("pepperspray:StopParticles", function(peppersprayid)
local entity = NetToObj(peppersprayid)
RemoveParticleFxFromEntity(entity)
end)
---------------------------------------------------------------------------
-- Play Effect
---------------------------------------------------------------------------
local isSprayed = false
RegisterNetEvent("pepperspray:PlayerEffect")
AddEventHandler("pepperspray:PlayerEffect", function()
if not isSprayed then
SetTimecycleModifier("drunk")
SetTimecycleModifierStrength(2.0)
local ped = GetPlayerPed(PlayerId())
local fallPos = GetOffsetFromEntityInWorldCoords(ped, 0.0, -1.0, 0.0)
SetPedToRagdollWithFall(ped, config.sprayEffectTime * 1000, config.sprayEffectTime * 1000, 1, -GetEntityForwardVector(ped), 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
Citizen.Wait(config.sprayEffectTime * 1000)
ClearTimecycleModifier()
end
end)
---------------------------------------------------------------------------
-- Spraying Pepper Spray --
---------------------------------------------------------------------------
Citizen.CreateThread(function()
while true do
if holdingpepperspray then
if IsPedInAnyVehicle(GetPlayerPed(-1), false) then
TriggerEvent("pepperspray:Togglepepperspray")
end
for i=140, 143 do
DisableControlAction(0, i, true)
end
if IsControlJustPressed(0, 24) and usingpepperspray == false then
FireSpray()
end
else
for i=140, 143 do
EnableControlAction(0, i, true)
end
end
Citizen.Wait(0)
end
end)
function FireSpray()
Citizen.CreateThread(function()
usingpepperspray = true
local time = config.timeUntilReload
local count = time
TriggerServerEvent("pepperspray:SyncStartParticles", pepperspray_net)
local foundPed = FindPedInRaycast()
if foundPed ~= 0 then
if IsPedAPlayer(foundPed) then
local playerid = GetPlayerFromPed(foundPed)
if playerid ~= -1 then
TriggerServerEvent("pepperspray:TriggerPlayerEffect", GetPlayerServerId(playerid))
end
else
local fallPos = GetOffsetFromEntityInWorldCoords(foundPed, 0.0, -1.0, 0.0)
SetPedToRagdollWithFall(foundPed, 7000, 7000, 1, -GetEntityForwardVector(foundPed), 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
end
end
while IsControlPressed(0, 24) and count > 0 do
if not holdingpepperspray then
usingpepperspray = false
TriggerServerEvent("pepperspray:SyncStopParticles", pepperspray_net)
return
end
Citizen.Wait(500)
count = count - 0.5
end
TriggerServerEvent("pepperspray:SyncStopParticles", pepperspray_net)
usingpepperspray = false
end)
end
function FindPedInRaycast()
local player = PlayerId()
local plyPed = GetPlayerPed(player)
local plyPos = GetEntityCoords(plyPed, false)
local plyOffset = GetOffsetFromEntityInWorldCoords(plyPed, 0.0, config.sprayRange, 0.0)
local rayHandle = StartShapeTestCapsule(plyPos.x, plyPos.y, plyPos.z, plyOffset.x, plyOffset.y, plyOffset.z, 1.0, 12, plyPed, 7)
local _, _, _, _, ped = GetShapeTestResult(rayHandle)
return ped
end
function GetPlayerFromPed(ped)
for a = 0, 64 do
if GetPlayerPed(a) == ped then
return a
end
end
return -1
end
function Notification(message)
SetNotificationTextEntry("STRING")
AddTextComponentString(message)
DrawNotification(0, 1)
end