henoireil

Untitled

May 14th, 2017
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.77 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 isnear = "Unknown"
  51.     local ply = GetPlayerPed(-1)
  52.     local plyCoords = GetEntityCoords(ply, 0)
  53.     for k, item in ipairs(JOBS) do
  54.         local distance_field = GetDistanceBetweenCoords(item.fx, item.fy, item.fz, plyCoords["x"], plyCoords["y"], plyCoords["z"], true)
  55.         local distance_treatment = GetDistanceBetweenCoords(item.tx, item.ty, item.tz, plyCoords["x"], plyCoords["y"], plyCoords["z"], true)
  56.         local distance_seller = GetDistanceBetweenCoords(item.sx, item.sy, item.sz, plyCoords["x"], plyCoords["y"], plyCoords["z"], true)
  57.         -- TriggerEvent("notif:info", tostring(distance_field))
  58.         if (distance_field <= recoltDistance) then
  59.             jobId = k
  60.             info = item.raw_id
  61.             isnear = "field"
  62.         elseif (distance_treatment <= recoltDistance) then
  63.             jobId = k
  64.             isnear = "treatment"
  65.         elseif (distance_seller <= recoltDistance) then
  66.             jobId = k
  67.             isnear = "seller"
  68.         end
  69.     end
  70.     return during
  71. end
  72.  
  73. -- Display the message of recolting/treating/selling and trigger the associated event(s)
  74. function recolt(text, rl)
  75.     if (text == 'Récolte') then
  76.         if( exports.vdkinv:getQuantity(JOBS[jobId].raw_id) <=32) then
  77.           TriggerEvent("notif:missiontext", text .. ' en cours de ~g~' .. tostring(JOBS[jobId].raw_item) .. '~s~...', timeForRecolt - 800)
  78.           Citizen.Wait(timeForRecolt - 800)
  79.           TriggerEvent("player:receiveItem", tonumber(JOBS[jobId].raw_id), 1)
  80.           TriggerEvent("notif:missiontext", rl .. ' ~g~' .. tostring(JOBS[jobId].raw_item) .. '~s~...', 800)
  81.         end
  82.     elseif (text == 'Traitement') then
  83.         TriggerEvent("notif:missiontext", text .. ' en cours de ~g~' .. tostring(JOBS[jobId].raw_item) .. '~s~...', timeForRecolt - 800)
  84.         Citizen.Wait(timeForRecolt - 800)
  85.         TriggerEvent("player:looseItem", tonumber(JOBS[jobId].raw_id), 1)
  86.         TriggerEvent("player:receiveItem", tonumber(JOBS[jobId].treat_id), 1)
  87.         TriggerEvent("notif:missiontext", rl .. ' ~g~' .. tostring(JOBS[jobId].treat_item) .. '~s~...', 800)
  88.     elseif (text == 'Vente') then
  89.         TriggerEvent("notif:missiontext", text .. ' en cours de ~g~' .. tostring(JOBS[jobId].treat_item) .. '~s~...', timeForRecolt - 800)
  90.         Citizen.Wait(timeForRecolt - 800)
  91.         TriggerEvent("player:sellItem", tonumber(JOBS[jobId].treat_id), tonumber(JOBS[jobId].price))
  92.         TriggerEvent("notif:missiontext", rl .. ' ~g~' .. tostring(JOBS[jobId].treat_item) .. '~s~...', 800)
  93.     end
  94.     Citizen.Wait(800)
  95. end
  96.  
  97. function setBlip(x, y, z, num)
  98.     local blip = AddBlipForCoord(x, y, z)
  99.     SetBlipSprite(blip, tonumber(num))
  100.     SetBlipAsShortRange(blip, true)
  101. end
  102.  
  103. -- Constantly check the position of the player
  104. Citizen.CreateThread(function()
  105.     Citizen.Wait(5000)
  106.     while true do
  107.         Citizen.Wait(1)
  108.         near = IsNear()
  109.         drawTxt('Near : ' .. near,0,1,0.5,0.8,0.6,255,255,255,255)
  110.         if (near == 'field') then
  111.             recolt('Récolte', '+1')
  112.         elseif (near == 'treatment' and exports.vdkinv:getQuantity(JOBS[jobId].raw_id) > 0) then
  113.             recolt('Traitement', '+1')
  114.         elseif (near == 'seller' and exports.vdkinv:getQuantity(JOBS[jobId].treat_id) > 0) then
  115.             recolt('Vente', '-1')
  116.         end
  117.     end
  118. end)
  119.  
  120. function Chat(debugg)
  121.     TriggerEvent("chatMessage", '', { 0, 0x99, 255 }, tostring(debugg))
  122. end
Advertisement
Add Comment
Please, Sign In to add comment