Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.97 KB | None | 0 0
  1. ESX = nil
  2.  
  3. TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
  4.  
  5. if Config.MaxInService ~= -1 then
  6. TriggerEvent('esx_service:activateService', 'ballas', Config.MaxInService)
  7. end
  8.  
  9. TriggerEvent('esx_phone:registerNumber', 'ballas', _U('alert_ballas'), true, true)
  10. TriggerEvent('esx_society:registerSociety', 'ballas', 'ballas', 'society_ballas', 'society_ballas', 'society_ballas', {type = 'public'})
  11.  
  12. RegisterServerEvent('esx_ballasjob:confiscatePlayerItem')
  13. AddEventHandler('esx_ballasjob:confiscatePlayerItem', function(target, itemType, itemName, amount)
  14. local _source = source
  15. local sourceXPlayer = ESX.GetPlayerFromId(_source)
  16. local targetXPlayer = ESX.GetPlayerFromId(target)
  17.  
  18. if sourceXPlayer.job.name ~= 'ballas' then
  19. print(('esx_ballasjob: %s attempted to confiscate!'):format(xPlayer.identifier))
  20. return
  21. end
  22.  
  23. if itemType == 'item_standard' then
  24. local targetItem = targetXPlayer.getInventoryItem(itemName)
  25. local sourceItem = sourceXPlayer.getInventoryItem(itemName)
  26.  
  27. -- does the target player have enough in their inventory?
  28. if targetItem.count > 0 and targetItem.count <= amount then
  29.  
  30. -- can the player carry the said amount of x item?
  31. if sourceItem.limit ~= -1 and (sourceItem.count + amount) > sourceItem.limit then
  32. TriggerClientEvent('esx:showNotification', _source, _U('quantity_invalid'))
  33. else
  34. targetXPlayer.removeInventoryItem(itemName, amount)
  35. sourceXPlayer.addInventoryItem (itemName, amount)
  36. TriggerClientEvent('esx:showNotification', _source, _U('you_confiscated', amount, sourceItem.label, targetXPlayer.name))
  37. TriggerClientEvent('esx:showNotification', target, _U('got_confiscated', amount, sourceItem.label, sourceXPlayer.name))
  38. end
  39. else
  40. TriggerClientEvent('esx:showNotification', _source, _U('quantity_invalid'))
  41. end
  42.  
  43. elseif itemType == 'item_account' then
  44. targetXPlayer.removeAccountMoney(itemName, amount)
  45. sourceXPlayer.addAccountMoney (itemName, amount)
  46.  
  47. TriggerClientEvent('esx:showNotification', _source, _U('you_confiscated_account', amount, itemName, targetXPlayer.name))
  48. TriggerClientEvent('esx:showNotification', target, _U('got_confiscated_account', amount, itemName, sourceXPlayer.name))
  49.  
  50. elseif itemType == 'item_weapon' then
  51. if amount == nil then amount = 0 end
  52. targetXPlayer.removeWeapon(itemName, amount)
  53. sourceXPlayer.addWeapon (itemName, amount)
  54.  
  55. TriggerClientEvent('esx:showNotification', _source, _U('you_confiscated_weapon', ESX.GetWeaponLabel(itemName), targetXPlayer.name, amount))
  56. TriggerClientEvent('esx:showNotification', target, _U('got_confiscated_weapon', ESX.GetWeaponLabel(itemName), amount, sourceXPlayer.name))
  57. end
  58. end)
  59.  
  60. RegisterServerEvent('esx_ballasjob:handcuff')
  61. AddEventHandler('esx_ballasjob:handcuff', function(target)
  62. local xPlayer = ESX.GetPlayerFromId(source)
  63.  
  64. if xPlayer.job.name == 'ballas' then
  65. TriggerClientEvent('esx_ballasjob:handcuff', target)
  66. else
  67. print(('esx_ballasjob: %s attempted to handcuff a player (not cop)!'):format(xPlayer.identifier))
  68. end
  69. end)
  70.  
  71. RegisterServerEvent('esx_ballasjob:drag')
  72. AddEventHandler('esx_ballasjob:drag', function(target)
  73. local xPlayer = ESX.GetPlayerFromId(source)
  74.  
  75. if xPlayer.job.name == 'ballas' then
  76. TriggerClientEvent('esx_ballasjob:drag', target, source)
  77. else
  78. print(('esx_ballasjob: %s attempted to drag (not cop)!'):format(xPlayer.identifier))
  79. end
  80. end)
  81.  
  82. RegisterServerEvent('esx_ballasjob:putInVehicle')
  83. AddEventHandler('esx_ballasjob:putInVehicle', function(target)
  84. local xPlayer = ESX.GetPlayerFromId(source)
  85.  
  86. if xPlayer.job.name == 'ballas' then
  87. TriggerClientEvent('esx_ballasjob:putInVehicle', target)
  88. else
  89. print(('esx_ballasjob: %s attempted to put in vehicle (not cop)!'):format(xPlayer.identifier))
  90. end
  91. end)
  92.  
  93. RegisterServerEvent('esx_ballasjob:OutVehicle')
  94. AddEventHandler('esx_ballasjob:OutVehicle', function(target)
  95. local xPlayer = ESX.GetPlayerFromId(source)
  96.  
  97. if xPlayer.job.name == 'ballas' then
  98. TriggerClientEvent('esx_ballasjob:OutVehicle', target)
  99. else
  100. print(('esx_ballasjob: %s attempted to drag out from vehicle (not cop)!'):format(xPlayer.identifier))
  101. end
  102. end)
  103.  
  104. RegisterServerEvent('esx_ballasjob:getStockItem')
  105. AddEventHandler('esx_ballasjob:getStockItem', function(itemName, count)
  106. local _source = source
  107. local xPlayer = ESX.GetPlayerFromId(_source)
  108. local sourceItem = xPlayer.getInventoryItem(itemName)
  109.  
  110. TriggerEvent('esx_addoninventory:getSharedInventory', 'society_ballas', function(inventory)
  111.  
  112. local inventoryItem = inventory.getItem(itemName)
  113.  
  114. -- is there enough in the society?
  115. if count > 0 and inventoryItem.count >= count then
  116.  
  117. -- can the player carry the said amount of x item?
  118. if sourceItem.limit ~= -1 and (sourceItem.count + count) > sourceItem.limit then
  119. TriggerClientEvent('esx:showNotification', _source, _U('quantity_invalid'))
  120. else
  121. inventory.removeItem(itemName, count)
  122. xPlayer.addInventoryItem(itemName, count)
  123. TriggerClientEvent('esx:showNotification', _source, _U('have_withdrawn', count, inventoryItem.label))
  124. end
  125. else
  126. TriggerClientEvent('esx:showNotification', _source, _U('quantity_invalid'))
  127. end
  128. end)
  129.  
  130. end)
  131.  
  132. RegisterServerEvent('esx_ballasjob:putStockItems')
  133. AddEventHandler('esx_ballasjob:putStockItems', function(itemName, count)
  134. local xPlayer = ESX.GetPlayerFromId(source)
  135. local sourceItem = xPlayer.getInventoryItem(itemName)
  136.  
  137. TriggerEvent('esx_addoninventory:getSharedInventory', 'society_ballas', function(inventory)
  138.  
  139. local inventoryItem = inventory.getItem(itemName)
  140.  
  141. -- does the player have enough of the item?
  142. if sourceItem.count >= count and count > 0 then
  143. xPlayer.removeInventoryItem(itemName, count)
  144. inventory.addItem(itemName, count)
  145. TriggerClientEvent('esx:showNotification', xPlayer.source, _U('have_deposited', count, inventoryItem.label))
  146. else
  147. TriggerClientEvent('esx:showNotification', xPlayer.source, _U('quantity_invalid'))
  148. end
  149.  
  150. end)
  151.  
  152. end)
  153.  
  154. ESX.RegisterServerCallback('esx_ballasjob:getOtherPlayerData', function(source, cb, target)
  155.  
  156. if Config.EnableESXIdentity then
  157.  
  158. local xPlayer = ESX.GetPlayerFromId(target)
  159.  
  160. local result = MySQL.Sync.fetchAll('SELECT firstname, lastname, sex, dateofbirth, height FROM users WHERE identifier = @identifier', {
  161. ['@identifier'] = xPlayer.identifier
  162. })
  163.  
  164. local firstname = result[1].firstname
  165. local lastname = result[1].lastname
  166. local sex = result[1].sex
  167. local dob = result[1].dateofbirth
  168. local height = result[1].height
  169.  
  170. local data = {
  171. name = GetPlayerName(target),
  172. job = xPlayer.job,
  173. inventory = xPlayer.inventory,
  174. accounts = xPlayer.accounts,
  175. weapons = xPlayer.loadout,
  176. firstname = firstname,
  177. lastname = lastname,
  178. sex = sex,
  179. dob = dob,
  180. height = height
  181. }
  182.  
  183. TriggerEvent('esx_status:getStatus', target, 'drunk', function(status)
  184. if status ~= nil then
  185. data.drunk = math.floor(status.percent)
  186. end
  187. end)
  188.  
  189. if Config.EnableLicenses then
  190. TriggerEvent('esx_license:getLicenses', target, function(licenses)
  191. data.licenses = licenses
  192. cb(data)
  193. end)
  194. else
  195. cb(data)
  196. end
  197.  
  198. else
  199.  
  200. local xPlayer = ESX.GetPlayerFromId(target)
  201.  
  202. local data = {
  203. name = GetPlayerName(target),
  204. job = xPlayer.job,
  205. inventory = xPlayer.inventory,
  206. accounts = xPlayer.accounts,
  207. weapons = xPlayer.loadout
  208. }
  209.  
  210. TriggerEvent('esx_status:getStatus', target, 'drunk', function(status)
  211. if status ~= nil then
  212. data.drunk = math.floor(status.percent)
  213. end
  214. end)
  215.  
  216. TriggerEvent('esx_license:getLicenses', target, function(licenses)
  217. data.licenses = licenses
  218. end)
  219.  
  220. cb(data)
  221.  
  222. end
  223.  
  224. end)
  225.  
  226. ESX.RegisterServerCallback('esx_ballasjob:getArmoryWeapons', function(source, cb)
  227.  
  228. TriggerEvent('esx_datastore:getSharedDataStore', 'society_ballas', function(store)
  229. local weapons = store.get('weapons')
  230.  
  231. if weapons == nil then
  232. weapons = {}
  233. end
  234.  
  235. cb(weapons)
  236. end)
  237.  
  238. end)
  239.  
  240. ESX.RegisterServerCallback('esx_ballasjob:addArmoryWeapon', function(source, cb, weaponName, removeWeapon)
  241.  
  242. local xPlayer = ESX.GetPlayerFromId(source)
  243.  
  244. if removeWeapon then
  245. xPlayer.removeWeapon(weaponName)
  246. end
  247.  
  248. TriggerEvent('esx_datastore:getSharedDataStore', 'society_ballas', function(store)
  249.  
  250. local weapons = store.get('weapons')
  251.  
  252. if weapons == nil then
  253. weapons = {}
  254. end
  255.  
  256. local foundWeapon = false
  257.  
  258. for i=1, #weapons, 1 do
  259. if weapons[i].name == weaponName then
  260. weapons[i].count = weapons[i].count + 1
  261. foundWeapon = true
  262. break
  263. end
  264. end
  265.  
  266. if not foundWeapon then
  267. table.insert(weapons, {
  268. name = weaponName,
  269. count = 1
  270. })
  271. end
  272.  
  273. store.set('weapons', weapons)
  274. cb()
  275. end)
  276.  
  277. end)
  278.  
  279. ESX.RegisterServerCallback('esx_ballasjob:removeArmoryWeapon', function(source, cb, weaponName)
  280.  
  281. local xPlayer = ESX.GetPlayerFromId(source)
  282.  
  283. xPlayer.addWeapon(weaponName, 500)
  284.  
  285. TriggerEvent('esx_datastore:getSharedDataStore', 'society_ballas', function(store)
  286.  
  287. local weapons = store.get('weapons')
  288.  
  289. if weapons == nil then
  290. weapons = {}
  291. end
  292.  
  293. local foundWeapon = false
  294.  
  295. for i=1, #weapons, 1 do
  296. if weapons[i].name == weaponName then
  297. weapons[i].count = (weapons[i].count > 0 and weapons[i].count - 1 or 0)
  298. foundWeapon = true
  299. break
  300. end
  301. end
  302.  
  303. if not foundWeapon then
  304. table.insert(weapons, {
  305. name = weaponName,
  306. count = 0
  307. })
  308. end
  309.  
  310. store.set('weapons', weapons)
  311. cb()
  312. end)
  313.  
  314. end)
  315.  
  316. ESX.RegisterServerCallback('esx_ballasjob:buyWeapon', function(source, cb, weaponName, type, componentNum)
  317. local xPlayer = ESX.GetPlayerFromId(source)
  318. local authorizedWeapons, selectedWeapon = Config.AuthorizedWeapons[xPlayer.job.grade_name]
  319.  
  320. for k,v in ipairs(authorizedWeapons) do
  321. if v.weapon == weaponName then
  322. selectedWeapon = v
  323. break
  324. end
  325. end
  326.  
  327. if not selectedWeapon then
  328. print(('esx_ballasjob: %s attempted to buy an invalid weapon.'):format(xPlayer.identifier))
  329. cb(false)
  330. end
  331.  
  332. -- Weapon
  333. if type == 1 then
  334. if xPlayer.getMoney() >= selectedWeapon.price then
  335. xPlayer.removeMoney(selectedWeapon.price)
  336. xPlayer.addWeapon(weaponName, 100)
  337.  
  338. cb(true)
  339. else
  340. cb(false)
  341. end
  342.  
  343. -- Weapon Component
  344. elseif type == 2 then
  345. local price = selectedWeapon.components[componentNum]
  346. local weaponNum, weapon = ESX.GetWeapon(weaponName)
  347.  
  348. local component = weapon.components[componentNum]
  349.  
  350. if component then
  351. if xPlayer.getMoney() >= price then
  352. xPlayer.removeMoney(price)
  353. xPlayer.addWeaponComponent(weaponName, component.name)
  354.  
  355. cb(true)
  356. else
  357. cb(false)
  358. end
  359. else
  360. print(('esx_ballasjob: %s attempted to buy an invalid weapon component.'):format(xPlayer.identifier))
  361. cb(false)
  362. end
  363. end
  364. end)
  365.  
  366.  
  367. ESX.RegisterServerCallback('esx_ballasjob:buyJobVehicle', function(source, cb, vehicleProps, type)
  368. local xPlayer = ESX.GetPlayerFromId(source)
  369. local price = getPriceFromHash(vehicleProps.model, xPlayer.job.grade_name, type)
  370.  
  371. -- vehicle model not found
  372. if price == 0 then
  373. print(('esx_ballasjob: %s attempted to exploit the shop! (invalid vehicle model)'):format(xPlayer.identifier))
  374. cb(false)
  375. end
  376.  
  377. if xPlayer.getMoney() >= price then
  378. xPlayer.removeMoney(price)
  379.  
  380. MySQL.Async.execute('INSERT INTO owned_vehicles (owner, vehicle, plate, type, job, `stored`) VALUES (@owner, @vehicle, @plate, @type, @job, @stored)', {
  381. ['@owner'] = xPlayer.identifier,
  382. ['@vehicle'] = json.encode(vehicleProps),
  383. ['@plate'] = vehicleProps.plate,
  384. ['@type'] = type,
  385. ['@job'] = xPlayer.job.name,
  386. ['@stored'] = true
  387. }, function (rowsChanged)
  388. cb(true)
  389. end)
  390. else
  391. cb(false)
  392. end
  393. end)
  394.  
  395. ESX.RegisterServerCallback('esx_ballasjob:storeNearbyVehicle', function(source, cb, nearbyVehicles)
  396. local xPlayer = ESX.GetPlayerFromId(source)
  397. local foundPlate, foundNum
  398.  
  399. for k,v in ipairs(nearbyVehicles) do
  400. local result = MySQL.Sync.fetchAll('SELECT plate FROM owned_vehicles WHERE owner = @owner AND plate = @plate AND job = @job', {
  401. ['@owner'] = xPlayer.identifier,
  402. ['@plate'] = v.plate,
  403. ['@job'] = xPlayer.job.name
  404. })
  405.  
  406. if result[1] then
  407. foundPlate, foundNum = result[1].plate, k
  408. break
  409. end
  410. end
  411.  
  412. if not foundPlate then
  413. cb(false)
  414. else
  415. MySQL.Async.execute('UPDATE owned_vehicles SET `stored` = true WHERE owner = @owner AND plate = @plate AND job = @job', {
  416. ['@owner'] = xPlayer.identifier,
  417. ['@plate'] = foundPlate,
  418. ['@job'] = xPlayer.job.name
  419. }, function (rowsChanged)
  420. if rowsChanged == 0 then
  421. print(('esx_ballasjob: %s has exploited the garage!'):format(xPlayer.identifier))
  422. cb(false)
  423. else
  424. cb(true, foundNum)
  425. end
  426. end)
  427. end
  428.  
  429. end)
  430.  
  431. function getPriceFromHash(hashKey, jobGrade, type)
  432. if type == 'car' then
  433. local vehicles = Config.AuthorizedVehicles[jobGrade]
  434. local shared = Config.AuthorizedVehicles['Shared']
  435.  
  436. for k,v in ipairs(vehicles) do
  437. if GetHashKey(v.model) == hashKey then
  438. return v.price
  439. end
  440. end
  441.  
  442. for k,v in ipairs(shared) do
  443. if GetHashKey(v.model) == hashKey then
  444. return v.price
  445. end
  446. end
  447. end
  448.  
  449. return 0
  450. end
  451.  
  452. ESX.RegisterServerCallback('esx_ballasjob:getStockItems', function(source, cb)
  453. TriggerEvent('esx_addoninventory:getSharedInventory', 'society_ballas', function(inventory)
  454. cb(inventory.items)
  455. end)
  456. end)
  457.  
  458. ESX.RegisterServerCallback('esx_ballasjob:getPlayerInventory', function(source, cb)
  459. local xPlayer = ESX.GetPlayerFromId(source)
  460. local items = xPlayer.inventory
  461.  
  462. cb( { items = items } )
  463. end)
  464.  
  465. AddEventHandler('playerDropped', function()
  466. -- Save the source in case we lose it (which happens a lot)
  467. local _source = source
  468.  
  469. -- Did the player ever join?
  470. if _source ~= nil then
  471. local xPlayer = ESX.GetPlayerFromId(_source)
  472.  
  473. -- Is it worth telling all clients to refresh?
  474. if xPlayer ~= nil and xPlayer.job ~= nil and xPlayer.job.name == 'ballas' then
  475. Citizen.Wait(5000)
  476. TriggerClientEvent('esx_ballasjob:updateBlip', -1)
  477. end
  478. end
  479. end)
  480.  
  481. RegisterServerEvent('esx_ballasjob:spawned')
  482. AddEventHandler('esx_ballasjob:spawned', function()
  483. local _source = source
  484. local xPlayer = ESX.GetPlayerFromId(_source)
  485.  
  486. if xPlayer ~= nil and xPlayer.job ~= nil and xPlayer.job.name == 'ballas' then
  487. Citizen.Wait(5000)
  488. TriggerClientEvent('esx_ballasjob:updateBlip', -1)
  489. end
  490. end)
  491.  
  492. RegisterServerEvent('esx_ballasjob:forceBlip')
  493. AddEventHandler('esx_ballasjob:forceBlip', function()
  494. TriggerClientEvent('esx_ballasjob:updateBlip', -1)
  495. end)
  496.  
  497. AddEventHandler('onResourceStart', function(resource)
  498. if resource == GetCurrentResourceName() then
  499. Citizen.Wait(5000)
  500. TriggerClientEvent('esx_ballasjob:updateBlip', -1)
  501. end
  502. end)
  503.  
  504. AddEventHandler('onResourceStop', function(resource)
  505. if resource == GetCurrentResourceName() then
  506. TriggerEvent('esx_phone:removeNumber', 'ballas')
  507. end
  508. end)
  509.  
  510. RegisterServerEvent('esx_ballasjob:message')
  511. AddEventHandler('esx_ballasjob:message', function(target, msg)
  512. TriggerClientEvent('esx:showNotification', target, msg)
  513. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement