forked from xander1998/shield
-
Notifications
You must be signed in to change notification settings - Fork 2
/
client.lua
138 lines (110 loc) · 3.39 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
ESX = nil
local CurrentAction = nil
local PlayerData = {}
local shieldActive = false
local shieldEntity = nil
local hadPistol = false
Citizen.CreateThread(function()
while ESX == nil do
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
Citizen.Wait(0)
end
end)
RegisterNetEvent('esx:playerLoaded')
AddEventHandler('esx:playerLoaded', function(xPlayer)
PlayerData = xPlayer
end)
RegisterNetEvent('esx:setJob')
AddEventHandler('esx:setJob', function(job)
PlayerData.job = job
end)
-- ANIM
local animDict = "combat@gestures@gang@pistol_1h@beckon"
local animName = "0"
local prop = "prop_ballistic_shield"
local pistol = GetHashKey("WEAPON_PISTOL")
RegisterCommand("shield", function()
ESX.TriggerServerCallback('lenzh:getItemAmount', function(qtty)
if qtty > 0 then
if shieldActive then
DisableShield()
else
EnableShield()
end
else
ESX.ShowNotification("You don't have a ~r~Police Shield ~s~")
end
end, 'shield')
end)
RegisterNetEvent('lenzh:shield')
AddEventHandler('lenzh:shield', function()
ESX.TriggerServerCallback('lenzh:getItemAmount', function(qtty)
if qtty > 0 then
if shieldActive then
DisableShield()
else
EnableShield()
end
else
ESX.ShowNotification("You don't have a ~r~Police Shield ~s~")
end
end, 'shield')
end)
function EnableShield()
if PlayerData.job.name == 'police' then
shieldActive = true
local ped = GetPlayerPed(-1)
local pedPos = GetEntityCoords(ped, false)
RequestAnimDict(animDict)
while not HasAnimDictLoaded(animDict) do
Citizen.Wait(100)
end
TaskPlayAnim(ped, animDict, animName, 8.0, -8.0, -1, (2 + 16 + 32), 0.0, 0, 0, 0)
RequestModel(GetHashKey(prop))
while not HasModelLoaded(GetHashKey(prop)) do
Citizen.Wait(100)
end
local shield = CreateObject(GetHashKey(prop), pedPos.x, pedPos.y, pedPos.z, 1, 1, 1)
shieldEntity = shield
AttachEntityToEntity(shieldEntity, ped, GetEntityBoneIndexByName(ped, "IK_L_Hand"), 0.0, -0.05, -0.10, -30.0, 180.0, 40.0, 0, 0, 1, 0, 0, 1)
SetWeaponAnimationOverride(ped, GetHashKey("Gang1H"))
if HasPedGotWeapon(ped, pistol, 0) or GetSelectedPedWeapon(ped) == pistol then
SetCurrentPedWeapon(ped, pistol, 1)
hadPistol = true
else
GiveWeaponToPed(ped, pistol, 300, 0, 1)
SetCurrentPedWeapon(ped, pistol, 1)
hadPistol = false
end
SetEnableHandcuffs(ped, true)
else
ESX.ShowNotification('Not a Cop!')
end
end
function DisableShield()
local ped = GetPlayerPed(-1)
DeleteEntity(shieldEntity)
ClearPedTasksImmediately(ped)
SetWeaponAnimationOverride(ped, GetHashKey("Default"))
if not hadPistol then
RemoveWeaponFromPed(ped, pistol)
end
SetEnableHandcuffs(ped, false)
hadPistol = false
shieldActive = false
end
Citizen.CreateThread(function()
while true do
if shieldActive then
local ped = GetPlayerPed(-1)
if not IsEntityPlayingAnim(ped, animDict, animName, 1) then
RequestAnimDict(animDict)
while not HasAnimDictLoaded(animDict) do
Citizen.Wait(100)
end
TaskPlayAnim(ped, animDict, animName, 8.0, -8.0, -1, (2 + 16 + 32), 0.0, 0, 0, 0)
end
end
Citizen.Wait(500)
end
end)