Advertisement
Guest User

identifier

a guest
Jan 25th, 2022
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. ESX.RegisterServerCallback(‘Hideout_VehFinance:PlayerLogin’, function(source,cb)
  2.  
  3. local xPlayer = ESX.GetPlayerFromId(source)
  4.  
  5. local tick = 0
  6.  
  7. while not xPlayer and tick < 100 do
  8.  
  9. Citizen.Wait(0)
  10.  
  11. tick = tick + 1
  12.  
  13. local xPlayer = ESX.GetPlayerFromId(source)
  14.  
  15. end
  16.  
  17. local data = MySQL.Sync.fetchAll('SELECT * FROM owned_vehicles WHERE owner=@owner',{['@owner'] = xPlayer.getIdentifier()})
  18.  
  19. if not data or not data[1] then return; end
  20.  
  21. local cbData = false
  22.  
  23. for k,v in pairs(data) do
  24.  
  25. if v.finance > 0 and v.financetimer <= 0 then
  26.  
  27. if not cbData then cbData = {}; end
  28.  
  29. table.insert(cbData, v)
  30.  
  31. end
  32.  
  33. end
  34.  
  35. cb(cbData)
  36. end)
  37.  
  38. AddEventHandler(“playerConnecting”, function()
  39.  
  40. local src = source
  41.  
  42. local identifiers, steamIdentifier = GetPlayerIdentifiers(source)
  43.  
  44. for _, v in pairs(identifiers) do
  45.  
  46. if string.find(v, "steam") then
  47.  
  48. steamIdentifier = v
  49.  
  50. break
  51.  
  52. end
  53.  
  54. end
  55.  
  56. table.insert(JVF.PlayerTable, {sourceID = steamIdentifier, timeJoined = GetGameTimer()})
  57. end)
  58.  
  59. AddEventHandler(‘playerDropped’, function()
  60.  
  61. local identifiers, steamIdentifier = GetPlayerIdentifiers(source)
  62. for _, v in pairs(identifiers) do
  63.  
  64. if string.find(v, "steam") then
  65.  
  66. steamIdentifier = v
  67.  
  68. break
  69.  
  70. end
  71. end
  72.  
  73. local timeJoined, ky
  74.  
  75. for k,v in pairs(JVF.PlayerTable) do
  76.  
  77. if v.sourceID == steamIdentifier then timeJoined = v.timeJoined; ky = k; end
  78.  
  79. end
  80.  
  81. if not timeJoined then return; end
  82.  
  83. local identifier = steamIdentifier
  84.  
  85. local data = MySQL.Sync.fetchAll("SELECT * FROM owned_vehicles WHERE owner=@identifier",{['@identifier'] = identifier})
  86.  
  87. if not data then return; end
  88.  
  89. for k,v in pairs(data) do
  90.  
  91. if v.finance and v.finance > 0 then
  92.  
  93. MySQL.Sync.execute('UPDATE owned_vehicles SET financetimer=@financetimer WHERE plate=@plate', {['@financetimer'] = math.floor(v.financetimer - (((GetGameTimer() - timeJoined) / 1000) / 60)), ['@plate'] = v.plate} )
  94.  
  95. end
  96.  
  97. end
  98.  
  99. table.remove(JVF.PlayerTable, ky)
  100. end)
  101.  
  102. AddEventHandler(‘onResourceStart’, function()
  103.  
  104. local identifiers, steamIdentifier = GetPlayerIdentifiers(source)
  105. for _, v in pairs(identifiers) do
  106.  
  107. if string.find(v, "steam") then
  108.  
  109. steamIdentifier = v
  110.  
  111. break
  112.  
  113. end
  114. end
  115.  
  116. local timeJoined, ky
  117.  
  118. for k,v in pairs(JVF.PlayerTable) do
  119.  
  120. if v.sourceID == steamIdentifier then timeJoined = v.timeJoined; ky = k; end
  121.  
  122. end
  123.  
  124. if not timeJoined then return; end
  125.  
  126. local identifier = steamIdentifier
  127.  
  128. local data = MySQL.Sync.fetchAll("SELECT * FROM owned_vehicles WHERE owner=@identifier",{['@identifier'] = identifier})
  129.  
  130. if not data then return; end
  131.  
  132. for k,v in pairs(data) do
  133.  
  134. if v.finance and v.finance > 0 then
  135.  
  136. MySQL.Sync.execute('UPDATE owned_vehicles SET financetimer=@financetimer WHERE plate=@plate', {['@financetimer'] = math.floor(v.financetimer - (((GetGameTimer() - timeJoined) / 1000) / 60)), ['@plate'] = v.plate} )
  137.  
  138. end
  139.  
  140. end
  141.  
  142. table.remove(JVF.PlayerTable, ky)
  143. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement