Advertisement
Kyominii

VDK_Recolt__DynamicBlipsAndIllegalJob

Apr 27th, 2017
3,218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.74 KB | None | 0 0
  1. -- server.lua (job system) --
  2.  
  3. Just add : TriggerClientEvent("recolt:updateJobs", source, job) to update function
  4.  
  5. function updatejob(player, id)
  6. local job = id
  7. MySQL:executeQuery("UPDATE users SET `job`='@value' WHERE identifier = '@identifier'", {['@value'] = job, ['@identifier'] = player})
  8. TriggerClientEvent("recolt:updateJobs", source, job)
  9. end
  10.  
  11. -- server.lua (vdk_recolt) --
  12.  
  13. Here, I add a result variable (because if you run twice the SQL query, there is a weird error ^^') and modify the SQL Query
  14.  
  15. RegisterServerEvent("jobs:getJobs")
  16.  
  17. local jobs = {}
  18. local result = nil
  19.  
  20. AddEventHandler("jobs:getJobs", function ()
  21. jobs = {}
  22. if(not result) then
  23. local executed_query = MySQL:executeQuery("SELECT price, i1.`id` AS raw_id, i1.`libelle` AS raw_item, i2.`id` AS treat_id, i2.`libelle` AS treat_item, p1.x AS fx, p1.y AS fy, p1.z AS fz, p2.x AS tx, p2.y AS ty, p2.z AS tz, p3.x AS sx, p3.y AS sy, p3.z AS sz, job_id FROM recolt LEFT JOIN items i1 ON recolt.`raw_id`=i1.id LEFT JOIN items i2 ON recolt.`treated_id`=i2.id LEFT JOIN coordinates p1 ON recolt.`field_id`=p1.id LEFT JOIN coordinates p2 ON recolt.`treatment_id`=p2.id LEFT JOIN coordinates p3 ON recolt.`seller_id`=p3.id")
  24. result = MySQL:getResults(executed_query, { 'price', 'raw_id', 'raw_item', 'treat_id', 'treat_item', 'fx', 'fy', 'fz', 'tx', 'ty', 'tz', 'sx', 'sy', 'sz', 'job_id' })
  25. if (result) then
  26. jobs = result
  27. end
  28. else
  29. jobs = result
  30. end
  31. TriggerClientEvent("cli:getJobs", source, jobs)
  32. end)
  33.  
  34. -- Your Database --
  35.  
  36. Create a non-null job exclusive to all illegal jobs (mine is 6 for exemple) and change all illegal harvest job id to this new created ID
  37.  
  38. -- vdkrec.lua (vdk_recolt) --
  39.  
  40. Lot of modification, so there the complete file ^^'
  41. NOTE : change item.job_id == 6 by item.job_id == <Your Illegal Job Id> in IsNear function
  42.  
  43. local recoltDistance = 10
  44. local timeForRecolt = 4000 --1000 for 1 second
  45.  
  46. local near
  47. local jobId = 1
  48. JOBS = {}
  49. BLIPS = {}
  50.  
  51. RegisterNetEvent("jobs:getJobs")
  52. RegisterNetEvent("cli:getJobs")
  53. RegisterNetEvent("recolt:updateJobs")
  54.  
  55. AddEventHandler("recolt:updateJobs", function(id)
  56. jobId = id
  57. TriggerServerEvent("jobs:getJobs")
  58. end)
  59.  
  60. AddEventHandler("playerSpawned", function()
  61. TriggerServerEvent("jobs:getJobs")
  62. end)
  63.  
  64. -- Get the list of all jobs in the database and create the blip associated
  65. AddEventHandler("cli:getJobs", function(listJobs)
  66. JOBS = listJobs
  67.  
  68. for k, existingBlip in ipairs(BLIPS) do
  69. RemoveBlip(existingBlip)
  70. end
  71.  
  72. Citizen.CreateThread(function()
  73. for _, item in pairs(JOBS) do
  74. if(item.job_id == jobId) then
  75. setBlip(item.fx, item.fy, item.fz, 17)
  76. setBlip(item.tx, item.ty, item.tz, 18)
  77. setBlip(item.sx, item.sy, item.sz, 19)
  78. end
  79. end
  80. end)
  81. end)
  82.  
  83. -- Control if the player of is near of a place of job
  84. function IsNear()
  85. local ply = GetPlayerPed(-1)
  86. local plyCoords = GetEntityCoords(ply, 0)
  87. if(IsPedInAnyVehicle(ply, true) == false) then
  88. for k, item in ipairs(JOBS) do
  89. if(item.job_id == jobId or item.job_id == 6) then
  90. local distance_field = GetDistanceBetweenCoords(item.fx, item.fy, item.fz, plyCoords["x"], plyCoords["y"], plyCoords["z"], true)
  91. local distance_treatment = GetDistanceBetweenCoords(item.tx, item.ty, item.tz, plyCoords["x"], plyCoords["y"], plyCoords["z"], true)
  92. local distance_seller = GetDistanceBetweenCoords(item.sx, item.sy, item.sz, plyCoords["x"], plyCoords["y"], plyCoords["z"], true)
  93. if (distance_field <= recoltDistance) then
  94. --jobId = k
  95. return 'field', item
  96. elseif (distance_treatment <= recoltDistance) then
  97. --jobId = k
  98. return 'treatment', item
  99. elseif (distance_seller <= recoltDistance) then
  100. --jobId = k
  101. return 'seller', item
  102. end
  103. end
  104. end
  105. end
  106. end
  107.  
  108. -- Display the message of recolting/treating/selling and trigger the associated event(s)
  109. function recolt(text, item, rl)
  110. if (text == 'Récolte') then
  111. TriggerEvent("mt:missiontext", text .. ' en cours de ~g~' .. tostring(item.raw_item) .. '~s~...', timeForRecolt - 800)
  112. Citizen.Wait(timeForRecolt - 800)
  113. TriggerEvent("player:receiveItem", tonumber(item.raw_id), 1)
  114. TriggerEvent("mt:missiontext", rl .. ' ~g~' .. tostring(item.raw_item) .. '~s~...', 800)
  115. elseif (text == 'Traitement') then
  116. TriggerEvent("mt:missiontext", text .. ' en cours de ~g~' .. tostring(item.raw_item) .. '~s~...', timeForRecolt - 800)
  117. Citizen.Wait(timeForRecolt - 800)
  118. TriggerEvent("player:looseItem", tonumber(item.raw_id), 1)
  119. TriggerEvent("player:receiveItem", tonumber(item.treat_id), 1)
  120. TriggerEvent("mt:missiontext", rl .. ' ~g~' .. tostring(item.treat_item) .. '~s~...', 800)
  121. elseif (text == 'Vente') then
  122. TriggerEvent("mt:missiontext", text .. ' en cours de ~g~' .. tostring(item.treat_item) .. '~s~...', timeForRecolt - 800)
  123. Citizen.Wait(timeForRecolt - 800)
  124. TriggerEvent("player:sellItem", tonumber(item.treat_id), tonumber(item.price))
  125. TriggerEvent("mt:missiontext", rl .. ' ~g~' .. tostring(item.treat_item) .. '~s~...', 800)
  126. end
  127. Citizen.Wait(800)
  128. end
  129.  
  130. function setBlip(x, y, z, num)
  131. local blip = AddBlipForCoord(x, y, z)
  132. SetBlipSprite(blip, tonumber(num))
  133. SetBlipAsShortRange(blip, true)
  134. table.insert(BLIPS, blip)
  135. end
  136.  
  137. -- Constantly check the position of the player
  138. Citizen.CreateThread(function()
  139. Citizen.Wait(5000)
  140. while true do
  141. Citizen.Wait(1)
  142. near, item = IsNear()
  143. if (exports.vdk_inventory:notFull() == true) then
  144. if (near == 'field') then
  145. recolt('Récolte', item, '+1')
  146. elseif (near == 'treatment' and exports.vdk_inventory:getQuantity(item.raw_id) > 0) then
  147. recolt('Traitement', item, '+1')
  148. elseif (near == 'seller' and exports.vdk_inventory:getQuantity(item.treat_id) > 0) then
  149. recolt('Vente', item, '-1')
  150. end
  151. else
  152. if (near == 'treatment' and exports.vdk_inventory:getQuantity(item.raw_id) > 0) then
  153. recolt('Traitement', item, '+1')
  154. elseif (near == 'seller' and exports.vdk_inventory:getQuantity(item.treat_id) > 0) then
  155. recolt('Vente', item, '-1')
  156. end
  157. end
  158. end
  159. end)
  160.  
  161. function Chat(debugg)
  162. TriggerEvent("chatMessage", '', { 0, 0x99, 255 }, tostring(debugg))
  163. end
  164.  
  165. -- Optional : GUI.lua (vdk_inventory < v1.5) --
  166.  
  167. If you want to prevent adding / remove items in the inventory (it fix also when you have a controller and make bug UI when you run)
  168.  
  169. Comment line 62 and line 63 :
  170. --elseif IsControlJustPressed(1, Keys["NENTER"]) then
  171. -- MenuCallFunction(Menu.GUI[Menu.selection +1]["func"], Menu.GUI[Menu.selection +1]["args"])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement