Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- server.lua (job system) --
- Just add : TriggerClientEvent("recolt:updateJobs", source, job) to update function
- function updatejob(player, id)
- local job = id
- MySQL:executeQuery("UPDATE users SET `job`='@value' WHERE identifier = '@identifier'", {['@value'] = job, ['@identifier'] = player})
- TriggerClientEvent("recolt:updateJobs", source, job)
- end
- -- server.lua (vdk_recolt) --
- Here, I add a result variable (because if you run twice the SQL query, there is a weird error ^^') and modify the SQL Query
- RegisterServerEvent("jobs:getJobs")
- local jobs = {}
- local result = nil
- AddEventHandler("jobs:getJobs", function ()
- jobs = {}
- if(not result) then
- 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")
- 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' })
- if (result) then
- jobs = result
- end
- else
- jobs = result
- end
- TriggerClientEvent("cli:getJobs", source, jobs)
- end)
- -- Your Database --
- 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
- -- vdkrec.lua (vdk_recolt) --
- Lot of modification, so there the complete file ^^'
- NOTE : change item.job_id == 6 by item.job_id == <Your Illegal Job Id> in IsNear function
- local recoltDistance = 10
- local timeForRecolt = 4000 --1000 for 1 second
- local near
- local jobId = 1
- JOBS = {}
- BLIPS = {}
- RegisterNetEvent("jobs:getJobs")
- RegisterNetEvent("cli:getJobs")
- RegisterNetEvent("recolt:updateJobs")
- AddEventHandler("recolt:updateJobs", function(id)
- jobId = id
- TriggerServerEvent("jobs:getJobs")
- end)
- AddEventHandler("playerSpawned", function()
- TriggerServerEvent("jobs:getJobs")
- end)
- -- Get the list of all jobs in the database and create the blip associated
- AddEventHandler("cli:getJobs", function(listJobs)
- JOBS = listJobs
- for k, existingBlip in ipairs(BLIPS) do
- RemoveBlip(existingBlip)
- end
- Citizen.CreateThread(function()
- for _, item in pairs(JOBS) do
- if(item.job_id == jobId) then
- setBlip(item.fx, item.fy, item.fz, 17)
- setBlip(item.tx, item.ty, item.tz, 18)
- setBlip(item.sx, item.sy, item.sz, 19)
- end
- end
- end)
- end)
- -- Control if the player of is near of a place of job
- function IsNear()
- local ply = GetPlayerPed(-1)
- local plyCoords = GetEntityCoords(ply, 0)
- if(IsPedInAnyVehicle(ply, true) == false) then
- for k, item in ipairs(JOBS) do
- if(item.job_id == jobId or item.job_id == 6) then
- local distance_field = GetDistanceBetweenCoords(item.fx, item.fy, item.fz, plyCoords["x"], plyCoords["y"], plyCoords["z"], true)
- local distance_treatment = GetDistanceBetweenCoords(item.tx, item.ty, item.tz, plyCoords["x"], plyCoords["y"], plyCoords["z"], true)
- local distance_seller = GetDistanceBetweenCoords(item.sx, item.sy, item.sz, plyCoords["x"], plyCoords["y"], plyCoords["z"], true)
- if (distance_field <= recoltDistance) then
- --jobId = k
- return 'field', item
- elseif (distance_treatment <= recoltDistance) then
- --jobId = k
- return 'treatment', item
- elseif (distance_seller <= recoltDistance) then
- --jobId = k
- return 'seller', item
- end
- end
- end
- end
- end
- -- Display the message of recolting/treating/selling and trigger the associated event(s)
- function recolt(text, item, rl)
- if (text == 'Récolte') then
- TriggerEvent("mt:missiontext", text .. ' en cours de ~g~' .. tostring(item.raw_item) .. '~s~...', timeForRecolt - 800)
- Citizen.Wait(timeForRecolt - 800)
- TriggerEvent("player:receiveItem", tonumber(item.raw_id), 1)
- TriggerEvent("mt:missiontext", rl .. ' ~g~' .. tostring(item.raw_item) .. '~s~...', 800)
- elseif (text == 'Traitement') then
- TriggerEvent("mt:missiontext", text .. ' en cours de ~g~' .. tostring(item.raw_item) .. '~s~...', timeForRecolt - 800)
- Citizen.Wait(timeForRecolt - 800)
- TriggerEvent("player:looseItem", tonumber(item.raw_id), 1)
- TriggerEvent("player:receiveItem", tonumber(item.treat_id), 1)
- TriggerEvent("mt:missiontext", rl .. ' ~g~' .. tostring(item.treat_item) .. '~s~...', 800)
- elseif (text == 'Vente') then
- TriggerEvent("mt:missiontext", text .. ' en cours de ~g~' .. tostring(item.treat_item) .. '~s~...', timeForRecolt - 800)
- Citizen.Wait(timeForRecolt - 800)
- TriggerEvent("player:sellItem", tonumber(item.treat_id), tonumber(item.price))
- TriggerEvent("mt:missiontext", rl .. ' ~g~' .. tostring(item.treat_item) .. '~s~...', 800)
- end
- Citizen.Wait(800)
- end
- function setBlip(x, y, z, num)
- local blip = AddBlipForCoord(x, y, z)
- SetBlipSprite(blip, tonumber(num))
- SetBlipAsShortRange(blip, true)
- table.insert(BLIPS, blip)
- end
- -- Constantly check the position of the player
- Citizen.CreateThread(function()
- Citizen.Wait(5000)
- while true do
- Citizen.Wait(1)
- near, item = IsNear()
- if (exports.vdk_inventory:notFull() == true) then
- if (near == 'field') then
- recolt('Récolte', item, '+1')
- elseif (near == 'treatment' and exports.vdk_inventory:getQuantity(item.raw_id) > 0) then
- recolt('Traitement', item, '+1')
- elseif (near == 'seller' and exports.vdk_inventory:getQuantity(item.treat_id) > 0) then
- recolt('Vente', item, '-1')
- end
- else
- if (near == 'treatment' and exports.vdk_inventory:getQuantity(item.raw_id) > 0) then
- recolt('Traitement', item, '+1')
- elseif (near == 'seller' and exports.vdk_inventory:getQuantity(item.treat_id) > 0) then
- recolt('Vente', item, '-1')
- end
- end
- end
- end)
- function Chat(debugg)
- TriggerEvent("chatMessage", '', { 0, 0x99, 255 }, tostring(debugg))
- end
- -- Optional : GUI.lua (vdk_inventory < v1.5) --
- 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)
- Comment line 62 and line 63 :
- --elseif IsControlJustPressed(1, Keys["NENTER"]) then
- -- MenuCallFunction(Menu.GUI[Menu.selection +1]["func"], Menu.GUI[Menu.selection +1]["args"])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement