henoireil

Untitled

May 14th, 2017
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.80 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 isnear
  71. end
  72.  
  73. function getQuantityItem()
  74.     local quantity = exports.vdkinv:getQuantity(JOBS[jobId].raw_id) or 0
  75.     return quantity
  76. end
  77.  
  78. -- Display the message of recolting/treating/selling and trigger the associated event(s)
  79. function recolt(text, rl)
  80.     if (text == 'Récolte') then
  81.         if( getQuantityItem() <=32) then
  82.           TriggerEvent("notif:missiontext", text .. ' en cours de ~g~' .. tostring(JOBS[jobId].raw_item) .. '~s~...', timeForRecolt - 800)
  83.           Citizen.Wait(timeForRecolt - 800)
  84.           TriggerEvent("player:receiveItem", tonumber(JOBS[jobId].raw_id), 1)
  85.           TriggerEvent("notif:missiontext", rl .. ' ~g~' .. tostring(JOBS[jobId].raw_item) .. '~s~...', 800)
  86.         end
  87.     elseif (text == 'Traitement') then
  88.         TriggerEvent("notif:missiontext", text .. ' en cours de ~g~' .. tostring(JOBS[jobId].raw_item) .. '~s~...', timeForRecolt - 800)
  89.         Citizen.Wait(timeForRecolt - 800)
  90.         TriggerEvent("player:looseItem", tonumber(JOBS[jobId].raw_id), 1)
  91.         TriggerEvent("player:receiveItem", tonumber(JOBS[jobId].treat_id), 1)
  92.         TriggerEvent("notif:missiontext", rl .. ' ~g~' .. tostring(JOBS[jobId].treat_item) .. '~s~...', 800)
  93.     elseif (text == 'Vente') then
  94.         TriggerEvent("notif:missiontext", text .. ' en cours de ~g~' .. tostring(JOBS[jobId].treat_item) .. '~s~...', timeForRecolt - 800)
  95.         Citizen.Wait(timeForRecolt - 800)
  96.         TriggerEvent("player:sellItem", tonumber(JOBS[jobId].treat_id), tonumber(JOBS[jobId].price))
  97.         TriggerEvent("notif:missiontext", rl .. ' ~g~' .. tostring(JOBS[jobId].treat_item) .. '~s~...', 800)
  98.     end
  99.     Citizen.Wait(800)
  100. end
  101.  
  102. function setBlip(x, y, z, num)
  103.     local blip = AddBlipForCoord(x, y, z)
  104.     SetBlipSprite(blip, tonumber(num))
  105.     SetBlipAsShortRange(blip, true)
  106. end
  107.  
  108. -- Constantly check the position of the player
  109. Citizen.CreateThread(function()
  110.     Citizen.Wait(5000)
  111.     while true do
  112.         Citizen.Wait(1)
  113.         near = IsNear()
  114.         drawTxt('Near : ' .. near,0,1,0.5,0.8,0.6,255,255,255,255)
  115.         if (near == 'field') then
  116.             recolt('Récolte', '+1')
  117.         elseif (near == 'treatment' and getQuantityItem() > 0) then
  118.             recolt('Traitement', '+1')
  119.         elseif (near == 'seller' and getQuantityItem() > 0) then
  120.             recolt('Vente', '-1')
  121.         end
  122.     end
  123. end)
  124.  
  125. function Chat(debugg)
  126.     TriggerEvent("chatMessage", '', { 0, 0x99, 255 }, tostring(debugg))
  127. end
Advertisement
Add Comment
Please, Sign In to add comment