client.lua
ESX = nil QBcore = nil PlayerJob = nil PlayerData = nil CreateThread(function() while ESX == nil do TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) Wait(0) end while not ESX.IsPlayerLoaded() do Wait(100) end PlayerData = ESX.GetPlayerData() CreateThread(function() while true do if PlayerData ~= nil then PlayerJob = PlayerData.job.name break end Wait(100) end end) RegisterNetEvent('esx:setJob', function(job) PlayerJob = job.name PlayerGrade = job.grade end) end) RegisterNetEvent('conor-territoryHarvest:Notify', function(message, type) if Config.UseCustomNotify then TriggerEvent('conor-territoryHarvest:CustomNotify',message, type) elseif Config.UseESX then ESX.ShowNotification(message) end end) CreateThread(function() while true do local Sleep = 2000 local Player = PlayerPedId() local Pos = GetEntityCoords(Player) for harvestName, harvestInfo in pairs(Config.HarvestList) do for index, data in pairs (harvestInfo) do if index == 'pickLocations' then for i = 1, #data, 1 do local Dist = #(Pos - data[i]) if Dist <= 50 then Sleep = 500 if Dist <= 10 then Sleep = 100 if Dist <= 5 then Sleep = 0 while true do Pos = GetEntityCoords(Player) Dist = #(Pos - data[i]) if Dist <= 3 then if IsControlJustReleased(0, 38) then TriggerServerEvent('conor-territoryHarvest:Server:Initiate', harvestInfo, PlayerJob) end end if Dist > 5 then break end Wait(Sleep) end end end end end end end end Wait(Sleep) end end) RegisterNetEvent('conor-territoryHarvest:Initiate', function(harvestInfo, owner) if PlayerJob == owner then TriggerEvent('conor-territoryHarvest:HarvestItem', harvestInfo) else TriggerEvent('conor-territoryHarvest:Server:PayFee', harvestInfo, owner) end end) RegisterNetEvent('conor-territoryHarvest:HarvestDefence', function(harvestInfo, owner) if PlayerJob == owner then TriggerEvent('conor-territoryHarvest:Notify', Config.Lang['harvest_defend']..harvestInfo.harvestName, Config.LangType['info']) if Config.MarkIllegalHavest then for index, data in pairs (harvestInfo) do if index == 'pickLocations' then for i = 1, #data, 1 do CreateThread(function() local Alpha = 500 local HarvestBlip = AddBlipForRadius(data[i][1],data[i][2],data[i][3], 25.0) SetBlipHighDetail(HarvestBlip, true) SetBlipColour(HarvestBlip, 1) SetBlipAlpha(HarvestBlip, Alpha) SetBlipAsShortRange(HarvestBlip, true) while Alpha ~= 0 do Wait(50) Alpha = Alpha - 1 SetBlipAlpha(HarvestBlip, Alpha) if Alpha == 0 then RemoveBlip(HarvestBlip) return end end end) end end end end end end) RegisterNetEvent('conor-territoryHarvest:HarvestItem', function(harvestInfo) TriggerServerEvent('conor-territoryHarvest:Server:ReceiveItem', harvestInfo, PlayerJob) end)
Leave a Comment