Advertisement
Guest User

Untitled

a guest
Jun 1st, 2023
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.11 KB | None | 0 0
  1. MAV = MAV or {}
  2. Core = Core or nil
  3.  
  4. -- Here you can modify all the functions that the HUD uses, in case you use a different ESX or QB or even another framework.
  5.  
  6. MAV.Debug = function(...)
  7. if not Config.Debug then return end
  8. print(('^4[' .. GetCurrentResourceName() .. ']^7 # %s'):format(...))
  9. end
  10.  
  11. if GetResourceState('es_extended') == 'started' then
  12. Core = exports['es_extended']:getSharedObject()
  13. MAV.Debug('framework - esx')
  14. end
  15.  
  16. if GetResourceState('qb-core') == 'started' then
  17. Core = exports['qb-core']:GetCoreObject()
  18. MAV.Debug('framework - qbcore')
  19. end
  20.  
  21. -- ? Events
  22. MAV.Events = MAV.Events or {}
  23.  
  24. MAV.Events.OnPlayerLoaded = function ()
  25. local events = {
  26. ['qb'] = 'QBCore:Client:OnPlayerLoaded',
  27. ['esx'] = 'esx:playerLoaded'
  28. }
  29. return events[Config.Framework]
  30. end
  31.  
  32. MAV.Events.OnPlayerUnload = function()
  33. local events = {
  34. ['qb'] = 'QBCore:Client:OnPlayerUnload',
  35. ['esx'] = 'esx:onPlayerLogout'
  36. }
  37. return events[Config.Framework]
  38. end
  39.  
  40. MAV.Events.OnJobUpdate = function()
  41. local events = {
  42. ['qb'] = 'QBCore:Client:OnJobUpdate',
  43. ['esx'] = 'esx:setJob'
  44. }
  45. return events[Config.Framework]
  46. end
  47.  
  48. MAV.Events.OnUpdateNeeds = function()
  49. local events = {
  50. ['qb'] = 'hud:client:UpdateNeeds',
  51. ['esx'] = 'esx_status:onTick'
  52. }
  53. return events[Config.Framework]
  54. end
  55.  
  56. MAV.Events.OnMoneyChange = function()
  57. local events = {
  58. ['qb'] = 'hud:client:OnMoneyChange',
  59. ['esx'] = 'esx:setAccountMoney'
  60. }
  61. return events[Config.Framework]
  62. end
  63.  
  64. -- ? Functions
  65. MAV.Functions = MAV.Functions or {}
  66.  
  67. -- Get the notification
  68. -- @return void
  69. MAV.Functions.Notify = function(message, type)
  70. if Config.Framework == 'qb' then
  71. Core.Functions.Notify(message, type)
  72. end
  73. if Config.Framework == 'esx' then
  74. Core.ShowNotification(message, type, 3000)
  75. end
  76. end
  77.  
  78. -- Get the current fuel of the vehicle
  79. -- @param vehicle
  80. -- @return number
  81. MAV.Functions.GetFuel = function(vehicle)
  82. if Config.Framework == 'qb' then
  83. return exports["bit-fuel"]:GetFuelLevel(vehicle)
  84. end
  85. if Config.Framework == 'esx' then
  86. local level = GetVehicleFuelLevel(vehicle)
  87. return Core.Math.Round(level, 1)
  88. end
  89. end
  90.  
  91. -- Get the current job of the player
  92. -- @param job
  93. -- @return table
  94. MAV.Functions.GetJob = function(job)
  95. if Config.Framework == 'qb' then
  96. return {
  97. name = job.name,
  98. level = Config.Jobs[job.name][job.grade.level]
  99. }
  100. end
  101. if Config.Framework == 'esx' then
  102. return {
  103. name = job.name,
  104. level = job.grade_name
  105. }
  106. end
  107. end
  108.  
  109. -- Get the current player data
  110. -- @return object
  111. MAV.Functions.GetPlayerData = function()
  112. if Config.Framework == 'qb' then
  113. return Core.Functions.GetPlayerData()
  114. end
  115. if Config.Framework == 'esx' then
  116. return Core.GetPlayerData()
  117. end
  118. end
  119.  
  120. -- Get account money of the current player
  121. -- @return table
  122. MAV.Functions.GetAccount = function()
  123. if Config.Framework == 'qb' then
  124. local data = MAV.Functions.GetPlayerData()
  125. return {
  126. wallet = data.money['cash'],
  127. bank = data.money['bank']
  128. }
  129. end
  130. if Config.Framework == 'esx' then
  131. local data = MAV.Functions.GetPlayerData()
  132. return {
  133. wallet = data.accounts[2].money,
  134. bank = data.accounts[1].money
  135. }
  136. end
  137. end
  138.  
  139. -- Check if the player is logged or not
  140. -- @return boolean
  141. MAV.Functions.PlayerIsLogged = function()
  142. if Config.Framework == 'qb' then return LocalPlayer.state.isLoggedIn end
  143. if Config.Framework == 'esx' then return Core.IsPlayerLoaded() end
  144. end
  145.  
  146. -- Check if the weapon is whitelisted for the stress
  147. -- @return boolean
  148. MAV.Functions.IsWhitelistedWeaponStress = function(weapon)
  149. if weapon then
  150. for _, v in pairs(Config.WhitelistedWeaponStress) do
  151. if weapon == v then
  152. return true
  153. end
  154. end
  155. end
  156. return false
  157. end
  158.  
  159. -- Get the effect interval
  160. -- @param level
  161. -- @return number
  162. MAV.Functions.GetEffectInterval = function(level)
  163. for _, v in pairs(Config.EffectInterval) do
  164. if level >= v.min and level <= v.max then
  165. return v.timeout
  166. end
  167. end
  168. return 60000
  169. end
  170.  
  171. -- Get the blur intensity
  172. -- @param stress
  173. -- @return number
  174. MAV.Functions.GetBlurIntensity = function(stress)
  175. for _, v in pairs(Config.Intensity['BLUR']) do
  176. if stress >= v.min and stress <= v.max then
  177. return v.intensity
  178. end
  179. end
  180. return 1500
  181. end
  182.  
  183. MAV.Functions.PlaySound = function(Data)
  184. if Data.Enabled then
  185. PlaySoundFrontend(-1, Data.AudioName, Data.AudioRef, true)
  186. end
  187. end
  188.  
  189. if Config.Debug then
  190. for cb, _ in pairs(MAV.Functions) do
  191. MAV.Debug(('function - MAV.Functions.%s'):format(
  192. cb
  193. ))
  194. end
  195. for _, event in pairs(MAV.Events) do
  196. MAV.Debug(('event - %s'):format(
  197. event()
  198. ))
  199. end
  200. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement