forked from trclassic92/qb-weaponsonback
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.lua
More file actions
241 lines (220 loc) · 6.31 KB
/
Copy pathclient.lua
File metadata and controls
241 lines (220 loc) · 6.31 KB
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
local QBCore = exports['qb-core']:GetCoreObject()
isLoggedIn = false
local slots = 5 -- Range for the inventory check, begins in 1 an finish on slots value, hotbar's slots are 1-5
local s = {}
local sa = {}
local k = 0
local m = 0
local back_bone = 24818
local x = -0.07
local y = -0.15
local z = 0.0
local x_rotation = 0.0
local y_rotation = 45.0
local z_rotation = 0.0
local selectwep = nil
local valid = false
local weaps = {}
local current = nil
local rifles = {
["weapon_microsmg"] = "w_sb_microsmg",
["weapon_smg"] = "w_sb_smg",
["weapon_assaultsmg"] = "w_sb_assaultsmg",
["weapon_combatpdw"] = "w_sb_pdw",
["weapon_gusenberg"] = "w_sb_gusenberg",
["weapon_assaultshotgun"] = "w_sg_assaultshotgun",
["weapon_bullpupshotgun"] = "w_sg_bullpupshotgun",
["weapon_heavyshotgun"] = "w_sg_heavyshotgun",
["weapon_pumpshotgun"] = "w_sg_pumpshotgun",
["weapon_sawnoffshotgun"] = "w_sg_sawnoff",
["weapon_musket"] = "w_ar_musket",
["weapon_advancedrifle"] = "w_ar_advancedrifle",
["weapon_assaultrifle"] = "w_ar_assaultrifle",
["weapon_bullpuprifle"] = "w_ar_bullpuprifle",
["weapon_carbinerifle"] = "w_ar_carbinerifle",
["weapon_specialcarbine"] = "w_ar_specialcarbine",
["weapon_carbinerifle_mk2"] = "w_ar_carbineriflemk2",
}
local pistols = {
["weapon_pistol"] = "w_pi_pistol",
["weapon_combatpistol"] = "w_pi_combatpistol",
["weapon_appistol"] = "w_pi_appistol",
["weapon_pistol50"] = "w_pi_pistol50",
["weapon_snspistol"] = "w_pi_sns_pistol",
["weapon_heavypistol"] = "w_pi_heavypistol",
["weapon_vintagepistol"] = "w_pi_vintage_pistol",
["weapon_revolver"] = "w_pi_revolver",
["weapon_doubleaction"] = "w_pi_doubleaction",
}
local melee = {
["weapon_knife"] ="prop_w_me_knife_01",
["weapon_nightstick"] = "w_me_nightstick",
["weapon_dagger"] = "w_me_dagger",
}
local meleelarge = {
["weapon_bat"] = "w_me_bat",
["weapon_golfclub"] = "w_me_gclub",
["weapon_crowbar"] = "w_me_crowbar",
["weapon_katana"] = "w_me_katana",
}
local polweap = {
["weapon_stungun"] = "w_pi_stungun",
}
RegisterNetEvent('QBCore:Client:OnPlayerLoaded')
AddEventHandler('QBCore:Client:OnPlayerLoaded', function()
isLoggedIn = true
end)
RegisterNetEvent('QBCore:Client:OnPlayerUnload')
AddEventHandler('QBCore:Client:OnPlayerUnload', function()
isLoggedIn = false
end)
Citizen.CreateThread(function()
while true do
if isLoggedIn then
local xPlayer = QBCore.Functions.GetPlayerData()
for i = 1, slots do
sa[i] = s[i]
s[i] = xPlayer.items[i]
end
check()
Citizen.Wait(500)
else
Citizen.Wait(1000)
end
end
end)
function check()
for i = 1, slots do
k = 0
if sa[i] ~= nil then
for j = 1, slots do
if s[j] ~= nil then
if sa[i].name == s[j].name then
k = 1
break
end
end
end
else
k = 1
end
if k == 0 then
if sa[i] ~= nil then
if sa[i].type == "weapon" then
DeleteWeapon(sa[i].name)
end
end
end
end
for i = 1, slots do
m = 0
if s[i] ~= nil then
for j = 1, slots do
if sa[j] ~= nil then
if s[i].name == sa[j].name then
m = 1
break
end
end
end
else
m = 1
end
if m == 0 then
if s[i] ~= nil then
if s[i].type == "weapon" then
if IsPedArmed(PlayerPedId()) then
local wp = GetHashKey(s[i].name)
local aw = GetSelectedPedWeapon(PlayerPedId())
if wp ~= aw then
GiveWeap(s[i].name)
end
else
GiveWeap(s[i].name)
end
end
end
end
end
end
function DeleteWeapon(wep)
DeleteObject(weaps[wep])
end
function GiveWeap(wep)
if rifles[wep] ~= nil then
back_bone = 24818
x = 0.0
y = -0.15
z = 0.10
x_rotation = 175.0
y_rotation = -175.0
z_rotation = 180.0
valid = true
selectwep = rifles[wep]
elseif pistols[wep] ~= nil then
back_bone = 51826
x = 0.05
y = 0.0
z = 0.12
x_rotation = -90.0
y_rotation = 0.0
z_rotation = 0.0
valid = true
selectwep = pistols[wep]
elseif melee[wep] ~= nil then
back_bone = 11816
x = -0.1
y = -0.15
z = 0.12
x_rotation = 0.0
y_rotation = 135.0
z_rotation = 0.0
valid = true
selectwep = melee[wep]
elseif meleelarge[wep] ~= nil then
back_bone = 24818
x = 0.25
y = -0.15
z = 0.25
x_rotation = 0.0
y_rotation = 220.0
z_rotation = 0.0
valid = true
selectwep = meleelarge[wep]
elseif polweap[wep] ~= nil then
back_bone = 58271
x = 0.0
y = 0.05
z = -0.1
x_rotation = -65.0
y_rotation = 0.0
z_rotation = 0.0
valid = true
selectwep = polweap[wep]
end
if valid then
valid = false
local bone = GetPedBoneIndex(PlayerPedId(), back_bone)
RequestModel(selectwep)
while not HasModelLoaded(selectwep) do
Citizen.Wait(10)
end
SetModelAsNoLongerNeeded(selectwep)
weaps[wep] = CreateObject(GetHashKey(selectwep), 1.0, 1.0, 1.0, true, true, false)
AttachEntityToEntity(weaps[wep], PlayerPedId(), bone, x, y, z, x_rotation, y_rotation, z_rotation, 1, 1, 0, 0, 2, 1)
end
end
RegisterNetEvent('weapons:client:SetCurrentWeapon')
AddEventHandler('weapons:client:SetCurrentWeapon', function(weap,shootbool)
if weap == nil then
GiveWeap(current)
current = nil
else
if current ~= nil then
GiveWeap(current)
current = nil
end
current = tostring(weap.name)
DeleteWeapon(current)
end
end)