-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathclient.lua
152 lines (133 loc) · 3.99 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
local QBCore = exports['qb-core']:GetCoreObject()
local CurrentBackItems = {}
local TempBackItems = {}
local checking = true
local currentWeapon = nil
local slots = 40
local s = {}
AddEventHandler('onResourceStart', function(resourceName)
if (GetCurrentResourceName() ~= resourceName) then return end
BackLoop()
end)
AddEventHandler('onResourceStop', function(resourceName)
if (GetCurrentResourceName() ~= resourceName) then return end
resetItems()
end)
RegisterNetEvent("QBCore:Client:OnPlayerUnload", function()
resetItems()
end)
RegisterNetEvent("backitems:start", function()
Wait(10000)
BackLoop()
end)
RegisterNetEvent("backitems:displayItems", function(toggle)
if toggle then
for k,v in pairs(TempBackItems) do
createBackItem(k)
end
BackLoop()
else
TempBackItems = CurrentBackItems
checking = false
for k,v in pairs(CurrentBackItems) do
removeBackItem(k)
end
CurrentBackItems = {}
end
end)
function resetItems()
removeAllBackItems()
CurrentBackItems = {}
TempBackItems = {}
currentWeapon = nil
s = {}
checking = false
end
function BackLoop()
print("[Backitems]: Starting Loop")
checking = true
CreateThread(function()
while checking do
local player = QBCore.Functions.GetPlayerData()
while player == nil do
player = QBCore.Functions.GetPlayerData()
Wait(500)
end
for i = 1, slots do
s[i] = player.items[i]
end
check()
Wait(1000)
end
end)
end
function check()
for i = 1, slots do
if s[i] ~= nil then
local name = s[i].name
if BackItems[name] then
if name ~= currentWeapon then
createBackItem(name)
end
end
end
end
for k,v in pairs(CurrentBackItems) do
local hasItem = false
for j = 1, slots do
if s[j] ~= nil then
local name = s[j].name
if name == k then
hasItem = true
end
end
end
if not hasItem then
removeBackItem(k)
end
end
end
function createBackItem(item)
if not CurrentBackItems[item] then
if BackItems[item] then
local i = BackItems[item]
local model = i["model"]
local ped = PlayerPedId()
local bone = GetPedBoneIndex(ped, i["back_bone"])
RequestModel(model)
while not HasModelLoaded(model) do
Wait(10)
end
SetModelAsNoLongerNeeded(model)
CurrentBackItems[item] = CreateObject(GetHashKey(model), 1.0, 1.0, 1.0, true, true, false)
local y = i["y"]
if QBCore.Functions.GetPlayerData().charinfo.gender == 1 then y = y + 0.035 end
AttachEntityToEntity(CurrentBackItems[item], ped, bone, i["x"], y, i["z"], i["x_rotation"], i["y_rotation"], i["z_rotation"], 0, 1, 0, 1, 0, 1)
SetEntityCompletelyDisableCollision(CurrentBackItems[item], false, true)
end
end
end
function removeBackItem(item)
if CurrentBackItems[item] then
DeleteEntity(CurrentBackItems[item])
CurrentBackItems[item] = nil
end
end
function removeAllBackItems()
for k,v in pairs(CurrentBackItems) do
removeBackItem(k)
end
end
RegisterNetEvent('weapons:client:SetCurrentWeapon', function(weap, shootbool)
if weap == nil then
createBackItem(currentWeapon)
currentWeapon = nil
else
if currentWeapon ~= nil then
createBackItem(currentWeapon)
currentWeapon = nil
end
currentWeapon = tostring(weap.name)
removeBackItem(currentWeapon)
end
end)