Advertisement
henoireil

Untitled

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