-
Notifications
You must be signed in to change notification settings - Fork 176
/
main.lua
386 lines (357 loc) · 15.8 KB
/
main.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
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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
local QBCore = exports['qb-core']:GetCoreObject()
local inside = false
local currentHouse = nil
local closestHouse
local inRange
local IsLockpicking = false
local houseObj = {}
local POIOffsets = nil
local usingAdvanced = false
local requiredItemsShowed = false
local requiredItems = {}
local CurrentCops = 0
local openingDoor = false
local SucceededAttempts = 0
local NeededAttempts = 4
-- Functions
local function DrawText3Ds(x, y, z, text)
SetTextScale(0.35, 0.35)
SetTextFont(4)
SetTextProportional(1)
SetTextColour(255, 255, 255, 215)
SetTextEntry("STRING")
SetTextCentre(true)
AddTextComponentString(text)
SetDrawOrigin(x,y,z, 0)
DrawText(0.0, 0.0)
local factor = (string.len(text)) / 370
DrawRect(0.0, 0.0+0.0125, 0.017+ factor, 0.03, 0, 0, 0, 75)
ClearDrawOrigin()
end
local function loadAnimDict(dict)
while (not HasAnimDictLoaded(dict)) do
RequestAnimDict(dict)
Wait(5)
end
end
local function openHouseAnim()
loadAnimDict("anim@heists@keycard@")
TaskPlayAnim( PlayerPedId(), "anim@heists@keycard@", "exit", 5.0, 1.0, -1, 16, 0, 0, 0, 0 )
Wait(400)
ClearPedTasks(PlayerPedId())
end
local function enterRobberyHouse(house)
TriggerServerEvent("InteractSound_SV:PlayOnSource", "houses_door_open", 0.25)
openHouseAnim()
Wait(250)
local coords = { x = Config.Houses[house]["coords"]["x"], y = Config.Houses[house]["coords"]["y"], z= Config.Houses[house]["coords"]["z"] - Config.MinZOffset}
local data
if Config.Houses[house]["tier"] == 1 then
data = exports['qb-interior']:CreateHouseRobbery(coords)
end
Wait(100)
houseObj = data[1]
POIOffsets = data[2]
inside = true
currentHouse = house
Wait(500)
TriggerEvent('qb-weathersync:client:DisableSync')
end
local function leaveRobberyHouse(house)
local ped = PlayerPedId()
TriggerServerEvent("InteractSound_SV:PlayOnSource", "houses_door_open", 0.25)
openHouseAnim()
Wait(250)
DoScreenFadeOut(250)
Wait(500)
exports['qb-interior']:DespawnInterior(houseObj, function()
TriggerEvent('qb-weathersync:client:EnableSync')
Wait(250)
DoScreenFadeIn(250)
SetEntityCoords(ped, Config.Houses[house]["coords"]["x"], Config.Houses[house]["coords"]["y"], Config.Houses[house]["coords"]["z"] + 0.5)
SetEntityHeading(ped, Config.Houses[house]["coords"]["h"])
inside = false
currentHouse = nil
end)
end
local function PoliceCall()
local chance = 75
if GetClockHours() >= 1 and GetClockHours() <= 6 then
chance = 25
end
if math.random(1, 100) <= chance then
TriggerServerEvent('police:server:policeAlert', 'Attempted House Robbery')
end
end
local function lockpickFinish(success)
if success then
TriggerServerEvent('qb-houserobbery:server:enterHouse', closestHouse)
QBCore.Functions.Notify(Lang:t("success.worked"), "success", 2500)
else
if usingAdvanced then
if math.random(1, 100) < 20 then
TriggerServerEvent("qb-houserobbery:server:removeAdvancedLockpick")
TriggerEvent('inventory:client:ItemBox', QBCore.Shared.Items["advancedlockpick"], "remove")
end
else
if math.random(1, 100) < 40 then
TriggerServerEvent("qb-houserobbery:server:removeLockpick")
TriggerEvent('inventory:client:ItemBox', QBCore.Shared.Items["lockpick"], "remove")
end
end
QBCore.Functions.Notify(Lang:t("error.didnt_work"), "error", 2500)
end
end
local function LockpickDoorAnim()
openingDoor = true
CreateThread(function()
while true do
if openingDoor then
TaskPlayAnim(PlayerPedId(), "veh@break_in@0h@p_m_one@", "low_force_entry_ds", 3.0, 3.0, -1, 16, 0, 0, 0, 0)
else
StopAnimTask(PlayerPedId(), "veh@break_in@0h@p_m_one@", "low_force_entry_ds", 1.0)
break
end
Wait(1000)
end
end)
end
local function IsWearingHandshoes()
local armIndex = GetPedDrawableVariation(PlayerPedId(), 3)
local model = GetEntityModel(PlayerPedId())
local retval = true
if model == `mp_m_freemode_01` then
if Config.MaleNoHandshoes[armIndex] ~= nil and Config.MaleNoHandshoes[armIndex] then
retval = false
end
else
if Config.FemaleNoHandshoes[armIndex] ~= nil and Config.FemaleNoHandshoes[armIndex] then
retval = false
end
end
return retval
end
local function searchCabin(cabin)
local ped = PlayerPedId()
local Skillbar = exports['qb-skillbar']:GetSkillbarObject()
if math.random(1, 100) <= 85 and not IsWearingHandshoes() then
local pos = GetEntityCoords(PlayerPedId())
TriggerServerEvent("evidence:server:CreateFingerDrop", pos)
end
LockpickDoorAnim()
TriggerServerEvent('qb-houserobbery:server:SetBusyState', cabin, currentHouse, true)
FreezeEntityPosition(ped, true)
IsLockpicking = true
Skillbar.Start({
duration = math.random(7500, 15000),
pos = math.random(10, 30),
width = math.random(10, 20),
}, function()
if SucceededAttempts + 1 >= NeededAttempts then
openingDoor = false
ClearPedTasks(PlayerPedId())
TriggerServerEvent('qb-houserobbery:server:searchCabin', cabin, currentHouse)
Config.Houses[currentHouse]["furniture"][cabin]["searched"] = true
TriggerServerEvent('qb-houserobbery:server:SetBusyState', cabin, currentHouse, false)
SucceededAttempts = 0
FreezeEntityPosition(ped, false)
SetTimeout(500, function()
IsLockpicking = false
end)
else
Skillbar.Repeat({
duration = math.random(700, 1250),
pos = math.random(10, 40),
width = math.random(10, 13),
})
SucceededAttempts = SucceededAttempts + 1
end
end, function()
openingDoor = false
ClearPedTasks(PlayerPedId())
TriggerServerEvent('qb-houserobbery:server:SetBusyState', cabin, currentHouse, false)
QBCore.Functions.Notify(Lang:t("error.process_cancelled"), "error", 3500)
SucceededAttempts = 0
FreezeEntityPosition(ped, false)
SetTimeout(500, function()
IsLockpicking = false
end)
end)
end
-- Events
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
QBCore.Functions.TriggerCallback('qb-houserobbery:server:GetHouseConfig', function(HouseConfig)
Config.Houses = HouseConfig
end)
end)
RegisterNetEvent('qb-houserobbery:client:ResetHouseState', function(house)
Config.Houses[house]["opened"] = false
for _, v in pairs(Config.Houses[house]["furniture"]) do
v["searched"] = false
end
end)
RegisterNetEvent('police:SetCopCount', function(amount)
CurrentCops = amount
end)
RegisterNetEvent('qb-houserobbery:client:enterHouse', function(house)
enterRobberyHouse(house)
end)
RegisterNetEvent('qb-houserobbery:client:setHouseState', function(house, state)
Config.Houses[house]["opened"] = state
end)
RegisterNetEvent('qb-houserobbery:client:setCabinState', function(house, cabin, state)
Config.Houses[house]["furniture"][cabin]["searched"] = state
end)
RegisterNetEvent('qb-houserobbery:client:SetBusyState', function(cabin, house, bool)
Config.Houses[house]["furniture"][cabin]["isBusy"] = bool
end)
RegisterNetEvent('lockpicks:UseLockpick', function(isAdvanced)
local hours = GetClockHours()
if hours >= Config.MinimumTime or hours <= Config.MaximumTime then
usingAdvanced = isAdvanced
if usingAdvanced then
if closestHouse ~= nil then
if CurrentCops >= Config.MinimumHouseRobberyPolice then
if not Config.Houses[closestHouse]["opened"] then
PoliceCall()
TriggerEvent('qb-lockpick:client:openLockpick', lockpickFinish)
if math.random(1, 100) <= 85 and not IsWearingHandshoes() then
local pos = GetEntityCoords(PlayerPedId())
TriggerServerEvent("evidence:server:CreateFingerDrop", pos)
end
else
QBCore.Functions.Notify(Lang:t("error.door_open"), "error", 3500)
end
else
QBCore.Functions.Notify(Lang:t("error.not_enough_police"), "error", 3500)
end
end
else
QBCore.Functions.TriggerCallback('QBCore:HasItem', function(result)
if closestHouse ~= nil then
if result then
if CurrentCops >= Config.MinimumHouseRobberyPolice then
if not Config.Houses[closestHouse]["opened"] then
PoliceCall()
TriggerEvent('qb-lockpick:client:openLockpick', lockpickFinish)
if math.random(1, 100) <= 85 and not IsWearingHandshoes() then
local pos = GetEntityCoords(PlayerPedId())
TriggerServerEvent("evidence:server:CreateFingerDrop", pos)
end
else
QBCore.Functions.Notify(Lang:t("error.door_open"), "error", 3500)
end
else
QBCore.Functions.Notify(Lang:t("error.not_enough_police"), "error", 3500)
end
else
QBCore.Functions.Notify(Lang:t("error.missing_something"), "error", 3500)
end
end
end, "screwdriverset")
end
end
end)
-- Threads
CreateThread(function()
Wait(500)
requiredItems = {
[1] = {name = QBCore.Shared.Items["advancedlockpick"]["name"], image = QBCore.Shared.Items["advancedlockpick"]["image"]},
[2] = {name = QBCore.Shared.Items["screwdriverset"]["name"], image = QBCore.Shared.Items["screwdriverset"]["image"]},
}
while true do
inRange = false
local PlayerPed = PlayerPedId()
local PlayerPos = GetEntityCoords(PlayerPed)
closestHouse = nil
if QBCore ~= nil then
local hours = GetClockHours()
if hours >= Config.MinimumTime or hours <= Config.MaximumTime then
if not inside then
for k, _ in pairs(Config.Houses) do
local dist = #(PlayerPos - vector3(Config.Houses[k]["coords"]["x"], Config.Houses[k]["coords"]["y"], Config.Houses[k]["coords"]["z"]))
if dist <= 1.5 then
closestHouse = k
inRange = true
if CurrentCops >= Config.MinimumHouseRobberyPolice then
if Config.Houses[k]["opened"] then
DrawText3Ds(Config.Houses[k]["coords"]["x"], Config.Houses[k]["coords"]["y"], Config.Houses[k]["coords"]["z"], '~g~E~w~ - To Enter')
if IsControlJustPressed(0, 38) then
enterRobberyHouse(k)
end
else
if not requiredItemsShowed then
requiredItemsShowed = true
TriggerEvent('inventory:client:requiredItems', requiredItems, true)
end
end
end
end
end
end
end
if inside then Wait(1000) end
if not inRange then
if requiredItemsShowed then
requiredItemsShowed = false
TriggerEvent('inventory:client:requiredItems', requiredItems, false)
end
Wait(1000)
end
end
Wait(5)
end
end)
CreateThread(function()
while true do
local ped = PlayerPedId()
local pos = GetEntityCoords(ped)
if inside then
if #(pos - vector3(Config.Houses[currentHouse]["coords"]["x"] + POIOffsets.exit.x, Config.Houses[currentHouse]["coords"]["y"] + POIOffsets.exit.y, Config.Houses[currentHouse]["coords"]["z"] - Config.MinZOffset + POIOffsets.exit.z)) < 1.5 then
DrawText3Ds(Config.Houses[currentHouse]["coords"]["x"] + POIOffsets.exit.x, Config.Houses[currentHouse]["coords"]["y"] + POIOffsets.exit.y, Config.Houses[currentHouse]["coords"]["z"] - Config.MinZOffset + POIOffsets.exit.z, '~g~E~w~ - To leave home')
if IsControlJustPressed(0, 38) then
leaveRobberyHouse(currentHouse)
end
end
for k, _ in pairs(Config.Houses[currentHouse]["furniture"]) do
if #(pos - vector3(Config.Houses[currentHouse]["coords"]["x"] + Config.Houses[currentHouse]["furniture"][k]["coords"]["x"], Config.Houses[currentHouse]["coords"]["y"] + Config.Houses[currentHouse]["furniture"][k]["coords"]["y"], Config.Houses[currentHouse]["coords"]["z"] + Config.Houses[currentHouse]["furniture"][k]["coords"]["z"] - Config.MinZOffset)) < 1 then
if not Config.Houses[currentHouse]["furniture"][k]["searched"] then
if not Config.Houses[currentHouse]["furniture"][k]["isBusy"] then
DrawText3Ds(Config.Houses[currentHouse]["coords"]["x"] + Config.Houses[currentHouse]["furniture"][k]["coords"]["x"], Config.Houses[currentHouse]["coords"]["y"] + Config.Houses[currentHouse]["furniture"][k]["coords"]["y"], Config.Houses[currentHouse]["coords"]["z"] + Config.Houses[currentHouse]["furniture"][k]["coords"]["z"] - Config.MinZOffset, '~g~E~w~ - '..Config.Houses[currentHouse]["furniture"][k]["text"])
if not IsLockpicking then
if IsControlJustReleased(0, 38) then
searchCabin(k)
end
end
else
DrawText3Ds(Config.Houses[currentHouse]["coords"]["x"] + Config.Houses[currentHouse]["furniture"][k]["coords"]["x"], Config.Houses[currentHouse]["coords"]["y"] + Config.Houses[currentHouse]["furniture"][k]["coords"]["y"], Config.Houses[currentHouse]["coords"]["z"] + Config.Houses[currentHouse]["furniture"][k]["coords"]["z"] - Config.MinZOffset, 'Searching..')
end
else
DrawText3Ds(Config.Houses[currentHouse]["coords"]["x"] + Config.Houses[currentHouse]["furniture"][k]["coords"]["x"], Config.Houses[currentHouse]["coords"]["y"] + Config.Houses[currentHouse]["furniture"][k]["coords"]["y"], Config.Houses[currentHouse]["coords"]["z"] + Config.Houses[currentHouse]["furniture"][k]["coords"]["z"] - Config.MinZOffset, 'Empty..')
end
end
end
end
if not inside then
Wait(5000)
end
Wait(3)
end
end)
-- Util Command (can be commented out - used for setting new spots in the config)
RegisterCommand('gethroffset', function()
local coords = GetEntityCoords(PlayerPedId())
local houseCoords = vector3(
Config.Houses[currentHouse]["coords"]["x"],
Config.Houses[currentHouse]["coords"]["y"],
Config.Houses[currentHouse]["coords"]["z"] - Config.MinZOffset
)
if inside then
local xdist = coords.x - houseCoords.x
local ydist = coords.y - houseCoords.y
local zdist = coords.z - houseCoords.z
print('X: '..xdist)
print('Y: '..ydist)
print('Z: '..zdist)
end
end, false)