Advertisement
Guest User

Untitled

a guest
May 29th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.38 KB | None | 0 0
  1. --Variables
  2. local recoltDistance = 10
  3. local timeForRecolt = 6000 --1000 for 1 second
  4.  
  5. local near
  6. local jobId = 1
  7. JOBS = {}
  8. BLIPS = {}
  9.  
  10. RegisterNetEvent("jobs:getJobs")
  11. RegisterNetEvent("cli:getJobs")
  12. RegisterNetEvent("recolt:updateJobs")
  13.  
  14. AddEventHandler("recolt:updateJobs", function(id)
  15. jobId = id
  16. TriggerServerEvent("jobs:getJobs")
  17. end)
  18.  
  19. AddEventHandler("playerSpawned", function()
  20. TriggerServerEvent("jobs:getJobs")
  21. end)
  22.  
  23. -- Get the list of all jobs in the database and create the blip associated
  24. AddEventHandler("cli:getJobs", function(listJobs)
  25. JOBS = listJobs
  26.  
  27. for k, existingBlip in ipairs(BLIPS) do
  28. RemoveBlip(existingBlip)
  29. end
  30.  
  31. Citizen.CreateThread(function()
  32. for _, item in pairs(JOBS) do
  33. if(item.job_id == jobId) then
  34. setBlip(item.fx, item.fy, item.fz, 17)
  35. setBlip(item.tx, item.ty, item.tz, 18)
  36. setBlip(item.sx, item.sy, item.sz, 19)
  37. end
  38. end
  39. end)
  40. end)
  41.  
  42. -- Control if the player of is near of a place of job
  43. function IsNear()
  44. local ply = GetPlayerPed(-1)
  45. local plyCoords = GetEntityCoords(ply, 0)
  46. if(IsPedInAnyVehicle(ply, true) == false) then
  47. for k, item in ipairs(JOBS) do
  48. if(item.job_id == jobId or item.job_id == 8) then
  49. local distance_field = GetDistanceBetweenCoords(item.fx, item.fy, item.fz, plyCoords["x"], plyCoords["y"], plyCoords["z"], true)
  50. local distance_treatment = GetDistanceBetweenCoords(item.tx, item.ty, item.tz, plyCoords["x"], plyCoords["y"], plyCoords["z"], true)
  51. local distance_seller = GetDistanceBetweenCoords(item.sx, item.sy, item.sz, plyCoords["x"], plyCoords["y"], plyCoords["z"], true)
  52. if (distance_field <= recoltDistance) then
  53. --jobId = k
  54. return 'field', item
  55. elseif (distance_treatment <= recoltDistance) then
  56. --jobId = k
  57. return 'treatment', item
  58. elseif (distance_seller <= recoltDistance) then
  59. --jobId = k
  60. return 'seller', item
  61. end
  62. end
  63. end
  64. end
  65. end
  66.  
  67. -- Display the message of recolting/treating/selling and trigger the associated event(s)
  68. function recolt(text, item, rl)
  69. if (text == 'Récolte') then
  70. TriggerEvent("mt:missiontext", text .. ' en cours de ~g~' .. tostring(item.raw_item) .. '~s~...', timeForRecolt - 800)
  71. Citizen.Wait(timeForRecolt - 800)
  72. TriggerEvent("player:receiveItem", tonumber(item.raw_id), 1)
  73. TriggerEvent("mt:missiontext", rl .. ' ~g~' .. tostring(item.raw_item) .. '~s~...', 800)
  74. elseif (text == 'Traitement') then
  75. TriggerEvent("mt:missiontext", text .. ' en cours de ~g~' .. tostring(item.raw_item) .. '~s~...', timeForRecolt - 800)
  76. Citizen.Wait(timeForRecolt - 800)
  77. TriggerEvent("player:looseItem", tonumber(item.raw_id), 1)
  78. TriggerEvent("player:receiveItem", tonumber(item.treat_id), 1)
  79. TriggerEvent("mt:missiontext", rl .. ' ~g~' .. tostring(item.treat_item) .. '~s~...', 800)
  80. elseif (text == 'Vente') then
  81. TriggerEvent("mt:missiontext", text .. ' en cours de ~g~' .. tostring(item.treat_item) .. '~s~...', timeForRecolt - 800)
  82. Citizen.Wait(timeForRecolt - 800)
  83. TriggerEvent("player:sellItem", tonumber(item.treat_id), tonumber(item.price))
  84. TriggerEvent("mt:missiontext", rl .. ' ~g~' .. tostring(item.treat_item) .. '~s~...', 800)
  85. end
  86. Citizen.Wait(800)
  87. end
  88.  
  89. function setBlip(x, y, z, num)
  90. local blip = AddBlipForCoord(x, y, z)
  91. SetBlipSprite(blip, tonumber(num))
  92. SetBlipAsShortRange(blip, true)
  93. table.insert(BLIPS, blip)
  94. local name = ""
  95. if(tonumber(num) == 17) then
  96. name = "Recolte"
  97. else
  98. if(tonumber(num) == 18) then
  99. name = "Traitement"
  100. else
  101. name = "Vente"
  102. end
  103. end
  104.  
  105. BeginTextCommandSetBlipName("STRING")
  106. AddTextComponentString(name)
  107. EndTextCommandSetBlipName(blip)
  108. end
  109.  
  110. -- Constantly check the position of the player
  111. Citizen.CreateThread(function()
  112. Citizen.Wait(5000)
  113. while true do
  114. Citizen.Wait(1)
  115. near, item = IsNear()
  116. if (exports.vdk_inventory:notFull() == true) then
  117. if (near == 'field'and exports.vdk_inventory:getQuantity(item.raw_id) < item.raw_lim ) then
  118. recolt('Récolte', item, '+1')
  119. elseif (near == 'treatment' and exports.vdk_inventory:getQuantity(item.raw_id) > 0 and exports.vdk_inventory:getQuantity(item.treat_id) < item.treat_lim) then
  120. recolt('Traitement', item, '+1')
  121. elseif (near == 'seller' and exports.vdk_inventory:getQuantity(item.treat_id) > 0) then
  122. recolt('Vente', item, '-1')
  123. end
  124. else
  125. if (near == 'treatment' and exports.vdk_inventory:getQuantity(item.raw_id) > 0 and exports.vdk_inventory:getQuantity(item.treat_id) < item.treat_lim) then
  126. recolt('Traitement', item, '+1')
  127. elseif (near == 'seller' and exports.vdk_inventory:getQuantity(item.treat_id) > 0) then
  128. recolt('Vente', item, '-1')
  129. end
  130. end
  131. end
  132. end)
  133.  
  134. function Chat(debugg)
  135. TriggerEvent("chatMessage", '', { 0, 0x99, 255 }, tostring(debugg))
  136. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement