Advertisement
Guest User

Untitled

a guest
Mar 13th, 2020
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.71 KB | None | 0 0
  1. GlobalFunction = function(event, data)
  2. local options = {
  3. event = event,
  4. data = data
  5. }
  6.  
  7. TriggerServerEvent("safebreach:globalEvent", options)
  8. end
  9.  
  10. TryToCrack = function(safeEntity)
  11. local currentStreetName = GetCurrentStreetName()
  12.  
  13. if Config.Debug then
  14. local breachObjects = SpawnBreachObjects(safeEntity)
  15. local safeCoords = GetEntityCoords(safeEntity)
  16.  
  17. GlobalFunction("open_door", {
  18. ["store"] = currentStreetName,
  19. ["doorCoords"] = {
  20. ["x"] = safeCoords["x"],
  21. ["y"] = safeCoords["y"],
  22. ["z"] = safeCoords["z"]
  23. },
  24. ["objects"] = breachObjects,
  25. ["streetName"] = currentStreetName,
  26. ["save"] = true
  27. })
  28.  
  29. return
  30. end
  31.  
  32. ESX.TriggerServerCallback("safebreach:checkIfSafeIsBreachable", function(state)
  33. if state then
  34. StartCrackingSafe(safeEntity)
  35. else
  36. ESX.ShowNotification("Du kan inte cracka detta!")
  37. end
  38. end, currentStreetName)
  39. end
  40.  
  41. StartCrackingSafe = function(safeEntity)
  42. if isCracking then
  43. return
  44. end
  45.  
  46. isCracking = true
  47.  
  48. currentSafeCorrectPosition = math.random(1, 350)
  49.  
  50. while not HasStreamedTextureDictLoaded("MPSafeCracking") do
  51. Citizen.Wait(0)
  52.  
  53. RequestStreamedTextureDict("MPSafeCracking", false)
  54. end
  55.  
  56. RequestAmbientAudioBank("SAFE_CRACK", false)
  57.  
  58. while not HasAnimDictLoaded("mini@safe_cracking") do
  59. Citizen.Wait(0)
  60.  
  61. RequestAnimDict("mini@safe_cracking")
  62. end
  63.  
  64. TaskPlayAnim(PlayerPedId(), "mini@safe_cracking", "dial_turn_clock_normal", 0.5, 1.0, -1, 11, 0.0, 0, 0, 0)
  65.  
  66. HandleControls(safeEntity)
  67.  
  68. Citizen.CreateThread(function()
  69. while isCracking do
  70. Citizen.Wait(0)
  71.  
  72. DrawSprite("MPSafeCracking", "Dial_BG", 0.5, 0.4, 0.2, 0.3, 0.0, 255, 255, 255, 255)
  73. DrawSprite("MPSafeCracking", "Dial", 0.5, 0.4, 0.2 * 0.5, 0.3 * 0.5, dialRotation, 255, 255, 255, 255)
  74.  
  75. DrawButtons({
  76. {
  77. ["label"] = "Vänster snabbt",
  78. ["button"] = "~INPUT_CELLPHONE_RIGHT~"
  79. },
  80. {
  81. ["label"] = "Vänster långsamt",
  82. ["button"] = "~INPUT_CELLPHONE_DOWN~"
  83. },
  84. {
  85. ["label"] = "Höger långsamt",
  86. ["button"] = "~INPUT_CELLPHONE_UP~"
  87. },
  88. {
  89. ["label"] = "Höger snabbt",
  90. ["button"] = "~INPUT_CELLPHONE_LEFT~"
  91. },
  92. {
  93. ["label"] = "Testa kombination",
  94. ["button"] = "~INPUT_JUMP~"
  95. },
  96. {
  97. ["label"] = "Avbryt",
  98. ["button"] = "~INPUT_DETONATE~"
  99. }
  100. })
  101.  
  102. if not IsEntityPlayingAnim(PlayerPedId(), "mini@safe_cracking", "dial_turn_clock_normal", 3) and isCracking then
  103. TaskPlayAnim(PlayerPedId(), "mini@safe_cracking", "dial_turn_clock_normal", 0.5, 1.0, -1, 11, 0.0, 0, 0, 0)
  104. end
  105.  
  106. for i = 1, Config.TotalLocks do
  107. local lockState = safeLocks[i] and "lock_open" or "lock_closed"
  108.  
  109. DrawSprite("MPSafeCracking", lockState, 0.25 + (i / 10), 0.6, 0.2 * 0.2, 0.3 * 0.2, 0.0, 255, 255, 255, 255)
  110. end
  111. end
  112.  
  113. RemoveAnimDict("mini@safe_cracking")
  114. end)
  115. end
  116.  
  117. ResetCrackingGame = function()
  118. isCracking = false
  119.  
  120. safeLocks = {}
  121.  
  122. ReleaseAmbientAudioBank("SAFE_CRACK")
  123. SetStreamedTextureDictAsNoLongerNeeded("MPSafeCracking")
  124.  
  125. if IsEntityPlayingAnim(PlayerPedId(), "mini@safe_cracking", "dial_turn_clock_normal", 3) then
  126. ClearPedTasks(PlayerPedId())
  127. end
  128. end
  129.  
  130. HandleControls = function(safeEntity)
  131. Citizen.CreateThread(function()
  132. while isCracking do
  133. DisableControlAction(0, 38, true)
  134.  
  135. if IsControlJustPressed(0, 22) then
  136. if dialRotation == currentSafeCorrectPosition then
  137. PlaySoundFrontend(0, "TUMBLER_PIN_FALL", "SAFE_CRACK_SOUNDSET", 1)
  138.  
  139. safeLocks[#safeLocks + 1] = true
  140.  
  141. if #safeLocks < Config.TotalLocks then
  142. currentSafeCorrectPosition = math.random(1, 350)
  143. else
  144. ResetCrackingGame()
  145.  
  146. local closestSafeaAtCoords = GetEntityCoords(safeEntity)
  147. local currentStreetName = GetCurrentStreetName()
  148.  
  149. ESX.TriggerServerCallback("safebreach:safeBreached", function(breached)
  150. if breached then
  151. local breachObjects = SpawnBreachObjects(safeEntity)
  152.  
  153. GlobalFunction("open_door", {
  154. ["store"] = currentStreetName,
  155. ["doorCoords"] = {
  156. ["x"] = closestSafeaAtCoords["x"],
  157. ["y"] = closestSafeaAtCoords["y"],
  158. ["z"] = closestSafeaAtCoords["z"]
  159. },
  160. ["objects"] = breachObjects,
  161. ["streetName"] = currentStreetName,
  162. ["save"] = true
  163. })
  164.  
  165. ESX.ShowNotification("Du lyckades cracka kassaskåpet")
  166. else
  167. ESX.ShowNotification("Kassaskåpet är redan öppet!")
  168. end
  169. end, {
  170. ["store"] = currentStreetName,
  171. ["doorCoords"] = {
  172. ["x"] = closestSafeaAtCoords["x"],
  173. ["y"] = closestSafeaAtCoords["y"],
  174. ["z"] = closestSafeaAtCoords["z"]
  175. },
  176. ["doorRotation"] = GetEntityRotation(safeEntity)
  177. })
  178. end
  179. else
  180. ESX.ShowNotification("Fel kombination försök igen.")
  181. end
  182. elseif IsControlJustPressed(0, 47) then
  183. ResetCrackingGame()
  184. elseif IsControlJustPressed(0, 172) then
  185. MoveSafeDial(true)
  186. elseif IsControlJustPressed(0, 173) then
  187. MoveSafeDial(false)
  188. elseif IsControlPressed(0, 174) then
  189. MoveSafeDial(true)
  190. elseif IsControlPressed(0, 175) then
  191. MoveSafeDial(false)
  192. end
  193.  
  194. Citizen.Wait(5)
  195. end
  196. end)
  197. end
  198.  
  199. MoveSafeDial = function(clockwise)
  200. if clockwise then
  201. dialRotation = dialRotation + 1
  202.  
  203. if dialRotation == currentSafeCorrectPosition then
  204. PlaySoundFrontend(0, "TUMBLER_PIN_FALL", "SAFE_CRACK_SOUNDSET", 1)
  205. else
  206. PlaySoundFrontend(0, "TUMBLER_TURN", "SAFE_CRACK_SOUNDSET", 1)
  207. end
  208.  
  209. if dialRotation >= 360 then
  210. dialRotation = 0.0
  211. end
  212. else
  213. dialRotation = dialRotation - 1
  214.  
  215. if dialRotation == currentSafeCorrectPosition then
  216. PlaySoundFrontend(0, "TUMBLER_PIN_FALL", "SAFE_CRACK_SOUNDSET", 1)
  217. else
  218. PlaySoundFrontend(0, "TUMBLER_TURN", "SAFE_CRACK_SOUNDSET", 1)
  219. end
  220.  
  221. if dialRotation <= 0 then
  222. dialRotation = 360.0
  223. end
  224. end
  225.  
  226. Citizen.Wait(10)
  227. end
  228.  
  229. ControlDoor = function(close, safeEntity)
  230. Citizen.CreateThread(function()
  231. local runs = 0
  232.  
  233. while runs < 140 do
  234. Citizen.Wait(10)
  235.  
  236. local oldSafeHeading = GetEntityHeading(safeEntity)
  237.  
  238. if close then
  239. SetEntityHeading(safeEntity, oldSafeHeading - 0.7)
  240. else
  241. SetEntityHeading(safeEntity, oldSafeHeading + 0.7)
  242. end
  243.  
  244. runs = runs + 1
  245. end
  246.  
  247. FreezeEntityPosition(safeEntity, true)
  248. end)
  249. end
  250.  
  251. SpawnBreachObjects = function(safeEntity)
  252. local breachObjects = {}
  253.  
  254. local startX = -0.1
  255.  
  256. while not HasModelLoaded(GetHashKey("prop_anim_cash_pile_02")) do
  257. Citizen.Wait(0)
  258.  
  259. RequestModel(GetHashKey("prop_anim_cash_pile_02"))
  260. end
  261.  
  262. for cashPileIndex = 1, 4 do
  263. local cashPileCoords = GetOffsetFromEntityInWorldCoords(safeEntity, startX, 0.4, 0.09)
  264. local cashPile = CreateObject(GetHashKey("prop_anim_cash_pile_02"), cashPileCoords, true)
  265.  
  266. table.insert(breachObjects, ObjToNet(cashPile))
  267.  
  268. startX = startX - 0.15
  269. end
  270.  
  271. return breachObjects
  272. end
  273.  
  274. TakeSafeItem = function(itemEntity, safeData)
  275. while not HasAnimDictLoaded("mp_missheist_ornatebank") do
  276. Citizen.Wait(0)
  277.  
  278. RequestAnimDict("mp_missheist_ornatebank")
  279. end
  280.  
  281. TaskPlayAnim(PlayerPedId(), "mp_missheist_ornatebank", "put_cash_into_bag_loop", 1.0, 1.0, 1250, 63, 0.0, 0, 0, 0)
  282.  
  283. Citizen.Wait(200)
  284.  
  285. while IsEntityPlayingAnim(PlayerPedId(), "mp_missheist_ornatebank", "put_cash_into_bag_loop", 3) do
  286. Citizen.Wait(0)
  287. end
  288.  
  289. if DoesEntityExist(itemEntity) then
  290. while not NetworkHasControlOfEntity(itemEntity) do
  291. Citizen.Wait(0)
  292.  
  293. NetworkRequestControlOfEntity(itemEntity)
  294. end
  295.  
  296. local stoleItem = GetEntityModel(itemEntity) == GetHashKey("prop_anim_cash_pile_02") and "money"
  297.  
  298. ESX.TriggerServerCallback("safebreach:receiveReward", function(received)
  299. if received then
  300. end
  301. end, stoleItem)
  302.  
  303. DeleteEntity(itemEntity)
  304. else
  305. ESX.ShowNotification("Någon tog det innan dig")
  306. end
  307. end
  308.  
  309. DrawButtons = function(buttonsToDraw)
  310. Citizen.CreateThread(function()
  311. local instructionScaleform = RequestScaleformMovie("instructional_buttons")
  312.  
  313. while not HasScaleformMovieLoaded(instructionScaleform) do
  314. Wait(0)
  315. end
  316.  
  317. PushScaleformMovieFunction(instructionScaleform, "CLEAR_ALL")
  318. PushScaleformMovieFunction(instructionScaleform, "TOGGLE_MOUSE_BUTTONS")
  319. PushScaleformMovieFunctionParameterBool(0)
  320. PopScaleformMovieFunctionVoid()
  321.  
  322. for buttonIndex, buttonValues in ipairs(buttonsToDraw) do
  323. PushScaleformMovieFunction(instructionScaleform, "SET_DATA_SLOT")
  324. PushScaleformMovieFunctionParameterInt(buttonIndex - 1)
  325.  
  326. PushScaleformMovieMethodParameterButtonName(buttonValues["button"])
  327. PushScaleformMovieFunctionParameterString(buttonValues["label"])
  328. PopScaleformMovieFunctionVoid()
  329. end
  330.  
  331. PushScaleformMovieFunction(instructionScaleform, "DRAW_INSTRUCTIONAL_BUTTONS")
  332. PushScaleformMovieFunctionParameterInt(-1)
  333. PopScaleformMovieFunctionVoid()
  334. DrawScaleformMovieFullscreen(instructionScaleform, 255, 255, 255, 255)
  335. end)
  336. end
  337.  
  338. GetCurrentStreetName = function()
  339. local pedCoords = GetEntityCoords(PlayerPedId())
  340.  
  341. local currentStreetHash, intersectStreetHash = GetStreetNameAtCoord(pedCoords["x"], pedCoords["y"], pedCoords["z"], currentStreetHash, intersectStreetHash)
  342. local currentStreetName = GetStreetNameFromHashKey(currentStreetHash)
  343.  
  344. return currentStreetName
  345. end
  346.  
  347. DrawScriptMarker = function(markerData)
  348. DrawMarker(markerData["type"] or 1, markerData["pos"] or vector3(0.0, 0.0, 0.0), 0.0, 0.0, 0.0, (markerData["type"] == 6 and -90.0 or markerData["rotate"] and -180.0) or 0.0, 0.0, 0.0, markerData["sizeX"] or 1.0, markerData["sizeY"] or 1.0, markerData["sizeZ"] or 1.0, markerData["r"] or 1.0, markerData["g"] or 1.0, markerData["b"] or 1.0, 100, false, true, 2, false, false, false, false)
  349. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement