-
Notifications
You must be signed in to change notification settings - Fork 5
/
client.lua
255 lines (216 loc) · 8.49 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
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
local QBCore = exports['qb-core']:GetCoreObject()
function StartMinigame(combo)
local Coords = GetEntityCoords(PlayerPedId(), false)
local Object = GetClosestObjectOfType(Coords.x, Coords.y, Coords.z, 5.0, `v_ilev_gangsafedoor`, false, false, false)
local ObjectHeading = GetEntityHeading(Object)
local txd = CreateRuntimeTxd(SafeCracker.Config.TextureDict)
for i = 1, 2 do CreateRuntimeTextureFromImage(txd, tostring(i), "LockPart" .. i .. ".PNG") end
loadAnimDict("mini@safe_cracking")
TaskPlayAnim(PlayerPedId(), "mini@safe_cracking", "dial_turn_anti_fast_1", 3.0, 3.0, -1, 49, 0, 0, 0, 0)
FreezeEntityPosition(PlayerPedId(), true)
SetEntityHeading(PlayerPedId(), ObjectHeading)
SafeCracker.MinigameOpen = true
SafeCracker.SoundID = GetSoundId()
SafeCracker.Timer = GetGameTimer()
SafeCracker.StayClosed = false
if not RequestAmbientAudioBank(SafeCracker.Config.AudioBank, false) then RequestAmbientAudioBank(SafeCracker.Config.AudioBankName, false); end
if not HasStreamedTextureDictLoaded(SafeCracker.Config.TextureDict, false) then RequestStreamedTextureDict(SafeCracker.Config.TextureDict, false); end
CreateThread(function()
Update(combo)
end)
end
RegisterNetEvent('SafeCracker:StartMinigame', function(combo)
StartMinigame(combo);
end)
function Update(combo)
CreateThread(function() HandleMinigame(combo); end)
while SafeCracker.MinigameOpen do
InputCheck()
if IsEntityDead(PlayerPedId()) then EndMinigame(false, false); end
Wait(0)
end
end
function InputCheck()
local leftKeyPressed = IsControlPressed( 0, 174) or 0 -- Left
local rightKeyPressed = IsControlPressed( 0, 175) or 0 -- Right
if IsControlPressed( 0, 322) then -- Esc
EndMinigame(false)
end
if IsControlPressed( 0, 20) then -- Z
rotSpeed = 0.1
modifier = 33
elseif IsControlPressed( 0, 21) then -- Left Shift
rotSpeed = 1.0
modifier = 50
else
rotSpeed = 0.4
modifier = 90
end
local lockRotation = math.max(modifier / rotSpeed, 0.1)
if leftKeyPressed ~= 0 or rightKeyPressed ~= 0 then
SafeCracker.LockRotation = SafeCracker.LockRotation - ( rotSpeed * tonumber( leftKeyPressed ) )
SafeCracker.LockRotation = SafeCracker.LockRotation + ( rotSpeed * tonumber( rightKeyPressed ) )
if (GetGameTimer() - SafeCracker.Timer) > lockRotation then
PlaySoundFrontend(0, SafeCracker.Config.SafeTurnSound, SafeCracker.Config.SafeSoundset, false)
SafeCracker.Timer = GetGameTimer()
end
end
end
function HandleMinigame(combo)
local lockNumbers = {}
local correctGuesses = {}
lockNumbers = combo
if lockNumbers[1] <= 149 then
lockRot = math.random(150, 359)
else
lockRot = math.random(1, 149)
end
-----------------------
-- REDO LOCK NUMBERS --
-----------------------
-- Make numbers persist if chosen.
-- Add number count for difficulty.
-- Multiples of 2 are positive, 45 - 359;
-- Multiples of 3 are negative, 719 - 405;
-- Everything else is negative, 45 - 359;
---------------------------------------------
-- Still havn't done, you're welcome to ^^ --
---------------------------------------------
--[[for i = 1,5 do
print(math.floor((lockNumbers[i] % 360) / 3.60))
end]]--
--------------------------------------
-- Comment this out for a challenge --
--------------------------------------
local correctCount = 1
local hasRandomized = false
SafeCracker.LockRotation = 0.0 + lockRot
while SafeCracker.MinigameOpen do
--Texture Dictionary, Texture Name, xPos, yPos, xSize, ySize, Heading, R, G, B, A,
DrawSprite(SafeCracker.Config.TextureDict, "1", 0.8, 0.5, 0.15, 0.26, -SafeCracker.LockRotation, 255, 255, 255, 255)
DrawSprite(SafeCracker.Config.TextureDict, "2", 0.8, 0.5, 0.176, 0.306, -0.0, 255, 255, 255, 255)
hasRandomized = true
local lockVal = math.floor(SafeCracker.LockRotation)
if correctCount > 1 and correctCount < (#lockNumbers + 1) and lockVal + (SafeCracker.Config.LockTolerance * 3.60) < lockNumbers[correctCount - 1] and lockNumbers[correctCount - 1] < lockNumbers[correctCount] then EndMinigame(false); SafeCracker.MinigameOpen = false;
elseif correctCount > 1 and correctCount < (#lockNumbers + 1) and lockVal - (SafeCracker.Config.LockTolerance * 3.60) > lockNumbers[correctCount - 1] and lockNumbers[correctCount - 1] > lockNumbers[correctCount] then EndMinigame(false); SafeCracker.MinigameOpen = false;
elseif correctCount > #lockNumbers then EndMinigame(true)
end
for k,v in pairs(lockNumbers) do
if not hasRandomized then SafeCracker.LockRotation = lockRot; end
if lockVal == v and correctCount == k then
local canAdd = true
for key,val in pairs(correctGuesses) do
if val == lockVal and key == correctCount then
canAdd = false
end
end
if canAdd then
PlaySoundFrontend(-1, SafeCracker.Config.SafePinSound, SafeCracker.Config.SafeSoundset, true)
correctGuesses[correctCount] = lockVal
correctCount = correctCount + 1;
end
end
end
Wait(0)
end
end
function EndMinigame(won)
SafeCracker.MinigameOpen = false
if won then
PlaySoundFrontend(SafeCracker.SoundID, SafeCracker.Config.SafeFinalSound, SafeCracker.Config.SafeSoundset, true)
QBCore.Functions.Notify("Safe opened..", "success")
else
QBCore.Functions.Notify("Safe opening failed..", "error")
end
TriggerEvent('SafeCracker:EndMinigame', won)
FreezeEntityPosition(PlayerPedId(), false)
ClearPedTasksImmediately(PlayerPedId())
end
RegisterNetEvent('SafeCracker:EndGame', function()
EndMinigame();
end)
function OpenSafeDoor()
CreateThread(function(...)
local objs = {}
local doorHash = (GetHashKey(SafeCracker.SafeModels.Door) % 0x100000000)
for k,v in pairs(objs) do
if (GetEntityModel(v)% 0x100000000) == doorHash then
local doorHeading = GetEntityPhysicsHeading(v)
local doorPosition = GetEntityCoords(v)
SetEntityCollision(v, false, false)
FreezeEntityPosition(v, false)
local targetHeading = doorHeading + 150
local tick = 0
while targetHeading > GetEntityHeading(v) and tick < 500 do
tick = tick + 1
SetEntityHeading(v, GetEntityHeading(v) + 0.3)
SetEntityCoords(v, doorPosition, false, false, false, false)
Wait(0)
end
if not (GetEntityHeading(v) >= targetHeading) then SetEntityHeading(v, targetHeading); end
end
end
end)
end
function loadAnimDict( dict )
while ( not HasAnimDictLoaded( dict ) ) do
RequestAnimDict( dict )
Wait( 5 )
end
end
function SpawnSafeObject(table, position, heading)
if not table then table = SafeCracker.SafeObjects; end
if not table or not position or not heading then return; end
if type(table) ~= 'table' or type(position) ~= 'vector3' or type(heading) ~= 'number' then return; end
LoadModelTable(SafeCracker.SafeModels)
local retTable = {}
local i = 0
for k,v in pairs(table) do
i = i + 1
local hash = GetHashKey(v.ModelName) % 0x100000000
local newHeading = heading + v.Heading
local newObj = CreateObject(hash, v.Pos.x + position.x, v.Pos.y + position.y, v.Pos.z + position.z, false, false, false)
if v.ModelName == SafeCracker.SafeModels.Door then
SafeCracker.DoorObj = newObj
SafeCracker.DoorHeading = GetEntityHeading(SafeCracker.DoorObj)
end
SetEntityAsMissionEntity(newObj, true)
FreezeEntityPosition(newObj, true)
SetEntityHeading(newObj, newHeading)
if v.Rot.x ~= 0.0 or v.Rot.y ~= 0.0 or v.Rot.z ~= 0.0 then SetEntityRotation(newObj, v.Rot.x, v.Rot.y, v.Rot.z, 1, true); end
retTable[v.ModelName] = newObj
end
ReleaseModelTable(SafeCracker.SafeModels)
SafeCracker.Objects = retTable
return retTable
end
function DelSafe()
for k,v in pairs(SafeCracker.Objects) do DeleteObject(v); end
end
RegisterNetEvent('SafeCracker:SpawnSafe', function(tab, pos, heading, cb)
if cb then cb(SpawnSafeObject(tab,pos,heading)) else SpawnSafeObject(tab,pos,heading); end; end)
function LoadModelTable(table)
if type(table) ~= 'table' then return false; end
for k,v in pairs(table) do
if type(v) == 'string' then
local hk = GetHashKey(v) % 0x100000000
while not HasModelLoaded(hk) do
RequestModel(hk)
Wait(0)
end
end
end
return true
end
function ReleaseModelTable(table)
if type(table) ~= 'table' then return false; end
for k,v in pairs(table) do
if type(v) == 'string' then
local hk = GetHashKey(v) % 0x100000000
if HasModelLoaded(hk) then
SetModelAsNoLongerNeeded(hk)
end
end
end
return true
end