forked from MintKind/mint-houseRobbery
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclient.lua
More file actions
298 lines (276 loc) · 10.1 KB
/
client.lua
File metadata and controls
298 lines (276 loc) · 10.1 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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
local QBCore = exports['qb-core']:GetCoreObject()
local canStart = true
local ongoing = false
local robberyStarted = false
local NeededAttempts = 0
local SucceededAttempts = 0
local FailedAttemps = 0
AddEventHandler('QBCore:Client:OnPlayerLoaded', function()
createentryzones()
end)
local function createentryzones()
for k, v in pairs(Config.Locations) do
exports['qb-target']:AddBoxZone("enterhouserobbery", v.location, 0.45, 0.35, {
name = "enterhouserobbery",
heading = 0,
debugPoly = false,
minZ = 0.0,
maxZ = 300.0,
}, {
options = {
{
type = "client",
event = "getRandomHouseLoc",
icon = "far fa-clipboard",
label = "Enter",
},
},
distance = 2
})
end
end
RegisterNetEvent("getRandomHouseLoc")
AddEventHandler("getRandomHouseLoc", function()
local missionTarget
for k, v in ipairs(Config.Locations) do
local coords = GetEntityCoords(PlayerPedId())
local distance = #(v.location - coords)
if distance < 4 then
missionTarget = v
end
end
EntryMinigame(missionTarget)
end)
RegisterNetEvent("createBlipAndRoute")
AddEventHandler("createBlipAndRoute", function(missionTarget)
QBCore.Functions.Notify('You recived an robbery location.', "success")
targetBlip = AddBlipForCoord(missionTarget.location.x, missionTarget.location.y, missionTarget.location.z)
SetBlipSprite(targetBlip, 374)
SetBlipColour(targetBlip, 1)
SetBlipAlpha(targetBlip, 90)
SetBlipScale(targetBlip, 0.5)
SetBlipRoute(targetBlip, true)
BeginTextCommandSetBlipName("STRING")
AddTextComponentString("Robbery location")
EndTextCommandSetBlipName(targetBlip)
end)
RegisterNetEvent("createEntry")
AddEventHandler("createEntry", function(missionTarget)
Citizen.CreateThread(function()
local alreadyEnteredZone = false
local text = nil
while ongoing do
wait = 5
local ped = PlayerPedId()
local inZone = false
local dist = #(GetEntityCoords(ped)-vector3(missionTarget.location.x, missionTarget.location.y, missionTarget.location.z))
if dist <= 5.0 then
wait = 5
inZone = true
text = '<b>Entry</b></p>Press [F] to start the robbery'
if IsControlJustReleased(0, 23) then
EntryMinigame(missionTarget)
end
else
wait = 2000
end
if inZone and not alreadyEnteredZone then
alreadyEnteredZone = true
TriggerEvent('cd_drawtextui:ShowUI', 'show', text)
end
if not inZone and alreadyEnteredZone then
alreadyEnteredZone = false
TriggerEvent('cd_drawtextui:HideUI')
end
Citizen.Wait(wait)
end
end)
end)
RegisterNetEvent("goInside")
AddEventHandler("goInside", function(missionTarget)
robberyStarted = true
SetEntityCoords(PlayerPedId(), missionTarget.inside.x, missionTarget.inside.y, missionTarget.inside.z)
TriggerEvent("createExit", missionTarget)
TriggerEvent("createLoot", missionTarget)
end)
RegisterNetEvent("createExit")
AddEventHandler("createExit", function(missionTarget)
Citizen.CreateThread(function()
local alreadyEnteredZone = false
local text = nil
while ongoing do
wait = 5
local ped = PlayerPedId()
local inZone = false
local dist = #(GetEntityCoords(ped)-vector3(missionTarget.exit.x, missionTarget.exit.y, missionTarget.exit.z))
if dist <= 5.0 then
wait = 5
inZone = true
text = '<b>Exit</b></p>Press [F] to end the robbery and leave the house.'
if IsControlJustReleased(0, 23) then
Citizen.Wait(1000)
ongoing = false
SetEntityCoords(PlayerPedId(), missionTarget.location.x, missionTarget.location.y, missionTarget.location.z)
cooldownNextRobbery(missionTarget)
Citizen.Wait(500)
TriggerEvent('cd_drawtextui:HideUI')
end
else
wait = 2000
end
if inZone and not alreadyEnteredZone then
alreadyEnteredZone = true
TriggerEvent('cd_drawtextui:ShowUI', 'show', text)
end
if not inZone and alreadyEnteredZone then
alreadyEnteredZone = false
TriggerEvent('cd_drawtextui:HideUI')
end
Citizen.Wait(wait)
end
end)
end)
RegisterNetEvent("createLoot")
AddEventHandler("createLoot", function(missionTarget)
for i,v in ipairs(missionTarget.loot) do
--print(i, " ", v)
local looted = false
Citizen.CreateThread(function()
while ongoing do
local wait = 5000
local ped = PlayerPedId()
local pedCoords = GetEntityCoords(ped)
if #(v - pedCoords) < 20 then
wait = 1
DrawMarker(27, v.x, v.y, v.z - 0.5, 0, 0, 0, 0, 0, 0, 1.0, 1.0, 1.0001, 0, 50, 255, 150, 0, 1, 2,0)
if #(v - pedCoords) < 2 then
drawTxt3D(v.x, v.y, v.z, "Press [E] to look for stuff here")
if IsControlJustPressed(0, 46) then
if not looted then
beginLoot()
looted = true
else
QBCore.Functions.Notify('You already cheacked here.', "error")
end
end
end
end
Wait(wait)
end
end)
end
end)
function drawTxt3D(x,y,z, text)
local onScreen,_x,_y=World3dToScreen2d(x,y,z)
local px,py,pz=table.unpack(GetGameplayCamCoords())
SetTextScale(0.35, 0.35)
SetTextFont(4)
SetTextProportional(1)
SetTextColour(255, 255, 255, 215)
SetTextEntry("STRING")
SetTextCentre(1)
AddTextComponentString(text)
DrawText(_x,_y)
end
function beginLoot()
QBCore.Functions.Progressbar("loot_house", "Looking for stuff...", math.random(6000,12000), false, true, {
disableMovement = true,
disableCarMovement = true,
disableMouse = false,
disableCombat = true,
}, {
animDict = "mini@repair",
anim = "fixing_a_player",
flags = 16,
}, {}, {}, function() -- Done
StopAnimTask(ped, "mini@repair", "fixing_a_player", 1.0)
TriggerServerEvent("robbery:loot")
ClearPedTasks(PlayerPedId())
end, function() -- Cancel
StopAnimTask(ped, "mini@repair", "fixing_a_player", 1.0)
openingDoor = false
ClearPedTasks(PlayerPedId())
QBCore.Functions.Notify("Process Canceled", "error")
end)
end
function cooldownNextRobbery(missionTarget)
RemoveBlip(targetBlip)
TriggerEvent('cd_drawtextui:HideUI')
missionTarget.canrob = false
Citizen.Wait(Config.Robsuccesscooldown * 1000 * 60)
ongoing = false
missionTarget.canrob = true
end
function cooldownNextRobberyFail(missionTarget)
RemoveBlip(targetBlip)
TriggerEvent('cd_drawtextui:HideUI')
missionTarget.canrob = false
ongoing = false
Citizen.Wait(Config.Robfailedcooldown * 1000 * 60)
missionTarget.canrob = true
end
function EntryMinigame(missionTarget)
local Skillbar = exports['qb-skillbar']:GetSkillbarObject()
if NeededAttempts == 0 then
NeededAttempts = math.random(3, 5)
-- NeededAttempts = 1
end
local maxwidth = 30
local maxduration = 3500
local hasitem = QBCore.Functions.HasItem(Config.ItemRequired)
if hasitem then
if missionTarget.canrob then
if Config.Shoulduseitem then
TriggerServerEvent("robbery:removerequireditem")
end
Skillbar.Start({
duration = math.random(2000, 3000),
pos = math.random(10, 30),
width = math.random(20, 30),
}, function()
if SucceededAttempts + 1 >= NeededAttempts then
TriggerEvent("goInside", missionTarget)
ongoing = true
QBCore.Functions.Notify("You got the door open!", "success")
FailedAttemps = 0
SucceededAttempts = 0
NeededAttempts = 0
else
SucceededAttempts = SucceededAttempts + 1
Skillbar.Repeat({
duration = math.random(2000, 3000),
pos = math.random(10, 30),
width = math.random(20, 30),
})
end
end, function()
QBCore.Functions.Notify("You messed up the lock! Get outa there!", "error")
TriggerServerEvent("InteractSound_SV:PlayWithinDistance", 200, 'metaldetected', 0.4)
TriggerEvent("zombies:houserobberyfailed")
if not Config.Dispatch == "" then
callPolice(missionTarget)
end
FailedAttemps = 0
SucceededAttempts = 0
NeededAttempts = 0
robberyStarted = false
ongoing = false
cooldownNextRobberyFail(missionTarget)
Citizen.Wait(500)
TriggerEvent('cd_drawtextui:HideUI')
end)
else
QBCore.Functions.Notify('Come back later!', 'error', 7500)
end
else
QBCore.Functions.Notify('You are missing something, but what could it be?', 'error', 7500)
end
end
function callPolice(missionTarget)
if Config.Dispatch == "ps-dispatch" then
exports['ps-dispatch']:HouseRobbery()
elseif Config.Dispatch == "QBCore" then
TriggerServerEvent('police:server:policeAlert', 'Attempted House Robbery')
end
PlaySound(-1, "Lose_1st", "GTAO_FM_Events_Soundset", 0, 0, 1)
end