Advertisement
Guest User

Untitled

a guest
Aug 17th, 2018
1,498
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.06 KB | None | 0 0
  1. ESX = nil
  2. local Weapons = {}
  3. local Loaded = false
  4. -----------------------------------------------------------
  5. -----------------------------------------------------------
  6. Citizen.CreateThread(function()
  7. while ESX == nil do
  8. TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
  9. Wait(0)
  10. end
  11.  
  12. Citizen.SetTimeout(8000, function()
  13. if not Loaded then
  14. print("Force Load")
  15. Loaded=true
  16. RemoveGears()
  17. SetGears()
  18. end
  19. end)
  20. while not Loaded do
  21. Wait(250)
  22. end
  23.  
  24. while true do
  25. local playerPed = GetPlayerPed(-1)
  26. for i = 1, #Config.RealWeapons, 1 do
  27.  
  28. local weaponHash = GetHashKey(Config.RealWeapons[i].name)
  29. if HasPedGotWeapon(playerPed, weaponHash, false) then
  30. local onPlayer = false
  31. for k, entity in pairs(Weapons) do
  32. if entity then
  33. if k == Config.RealWeapons[i].name then
  34. onPlayer = true
  35. break
  36. end
  37. end
  38. end
  39. local hash = GetSelectedPedWeapon(playerPed)
  40. if not onPlayer and weaponHash ~= hash then
  41. SetGear(Config.RealWeapons[i].name)
  42. elseif onPlayer and weaponHash == hash then
  43. RemoveGear(Config.RealWeapons[i].name)
  44. end
  45. else
  46. RemoveGear(Config.RealWeapons[i].name)
  47. end
  48. end
  49. Citizen.Wait(1000)
  50. end
  51. end)
  52. -----------------------------------------------------------
  53. -----------------------------------------------------------
  54. AddEventHandler('skinchanger:modelLoaded', function()
  55. RemoveGears()
  56. SetGears()
  57. Loaded = true
  58. end)
  59. -----------------------------------------------------------
  60. -----------------------------------------------------------
  61. RegisterNetEvent('esx:removeWeapon')
  62. AddEventHandler('esx:removeWeapon', function(weaponName)
  63. RemoveGear(weaponName)
  64. end)
  65. -----------------------------------------------------------
  66. -----------------------------------------------------------
  67. -- Remove only one weapon that's on the ped
  68. function RemoveGear(weapon)
  69. local _Weapons = {}
  70. for weaponName, entity in pairs(Weapons) do
  71. if weaponName ~= weapon then
  72. _Weapons[weaponName] = entity
  73. else
  74. ESX.Game.DeleteObject(entity)
  75. end
  76. end
  77.  
  78. Weapons = _Weapons
  79. end
  80.  
  81. -----------------------------------------------------------
  82. -----------------------------------------------------------
  83. -- Remove all weapons that are on the ped
  84. function RemoveGears()
  85. for weaponName, entity in pairs(Weapons) do
  86. ESX.Game.DeleteObject(entity)
  87. end
  88. Weapons = {}
  89. end
  90.  
  91. -----------------------------------------------------------
  92. -----------------------------------------------------------
  93. -- Add one weapon on the ped
  94. function SetGear(weapon)
  95. local bone = nil
  96. local boneX = 0.0
  97. local boneY = 0.0
  98. local boneZ = 0.0
  99. local boneXRot = 0.0
  100. local boneYRot = 0.0
  101. local boneZRot = 0.0
  102. local playerPed = GetPlayerPed(-1)
  103. local model = nil
  104. local playerData = ESX.GetPlayerData()
  105.  
  106. for i = 1, #Config.RealWeapons, 1 do
  107. if Config.RealWeapons[i].name == weapon then
  108. bone = Config.RealWeapons[i].bone
  109. boneX = Config.RealWeapons[i].x
  110. boneY = Config.RealWeapons[i].y
  111. boneZ = Config.RealWeapons[i].z
  112. boneXRot = Config.RealWeapons[i].xRot
  113. boneYRot = Config.RealWeapons[i].yRot
  114. boneZRot = Config.RealWeapons[i].zRot
  115. model = Config.RealWeapons[i].model
  116. break
  117. end
  118. end
  119.  
  120. ESX.Game.SpawnObject(model, {
  121. x = x,
  122. y = y,
  123. z = z
  124. }, function(obj)
  125. local playerPed = GetPlayerPed(-1)
  126. local boneIndex = GetPedBoneIndex(playerPed, bone)
  127. local bonePos = GetWorldPositionOfEntityBone(playerPed, boneIndex)
  128. AttachEntityToEntity(obj, playerPed, boneIndex, boneX, boneY, boneZ, boneXRot, boneYRot, boneZRot, false, false, false, false, 2, true)
  129. Weapons[weapon] = obj
  130. end)
  131. end
  132.  
  133. -----------------------------------------------------------
  134. -----------------------------------------------------------
  135. -- Add all the weapons in the xPlayer's loadout
  136. -- on the ped
  137. function SetGears()
  138. local bone = nil
  139. local boneX = 0.0
  140. local boneY = 0.0
  141. local boneZ = 0.0
  142. local boneXRot = 0.0
  143. local boneYRot = 0.0
  144. local boneZRot = 0.0
  145. local playerPed = GetPlayerPed(-1)
  146. local model = nil
  147. local playerData = ESX.GetPlayerData()
  148. local weapon = nil
  149.  
  150. for i = 1, #playerData.loadout, 1 do
  151.  
  152. for j = 1, #Config.RealWeapons, 1 do
  153. if Config.RealWeapons[j].name == playerData.loadout[i].name then
  154.  
  155. bone = Config.RealWeapons[j].bone
  156. boneX = Config.RealWeapons[j].x
  157. boneY = Config.RealWeapons[j].y
  158. boneZ = Config.RealWeapons[j].z
  159. boneXRot = Config.RealWeapons[j].xRot
  160. boneYRot = Config.RealWeapons[j].yRot
  161. boneZRot = Config.RealWeapons[j].zRot
  162. model = Config.RealWeapons[j].model
  163. weapon = Config.RealWeapons[j].name
  164.  
  165. break
  166. end
  167. end
  168.  
  169. local _wait = true
  170.  
  171. ESX.Game.SpawnObject(model, {
  172. x = x,
  173. y = y,
  174. z = z
  175. }, function(obj)
  176.  
  177. local playerPed = GetPlayerPed(-1)
  178. local boneIndex = GetPedBoneIndex(playerPed, bone)
  179. local bonePos = GetWorldPositionOfEntityBone(playerPed, boneIndex)
  180.  
  181. AttachEntityToEntity(obj, playerPed, boneIndex, boneX, boneY, boneZ, boneXRot, boneYRot, boneZRot, false, false, false, false, 2, true)
  182.  
  183. Weapons[weapon] = obj
  184. _wait = false
  185. end)
  186.  
  187. while _wait do
  188. Wait(0)
  189. end
  190. end
  191. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement