server.lua
ESX = nil TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) TriggerEvent('qs-core:getSharedObject', function(obj) QS = obj end) RegisterNetEvent('conor-territoryHarvest:Server:Initiate', function(harvestInfo, job) local src = source local owner = nil exports.oxmysql:query("SELECT harvest, faction FROM conor_terrharvest WHERE reputation = (select MAX(reputation) FROM conor_terrharvest AS a WHERE a.harvest=conor_terrharvest.harvest) GROUP BY harvest, reputation", {}, function (result) local table = table.unpack(result) if table ~= nil then for i = 1, #result, 1 do if result[i].harvest == harvestInfo.harvestName then owner = tostring(result[i].faction) break end end end TriggerClientEvent('conor-territoryHarvest:Initiate', src, harvestInfo, owner) end) end) RegisterNetEvent('conor-territoryHarvest:Server:ReceiveItem', function(harvestInfo, job) local src = source local database = false exports.oxmysql:query("SELECT * FROM conor_terrharvest WHERE faction = @faction", { ['@faction'] = job, }, function (result) for i = 1, #result, 1 do if result[i].harvest == harvestInfo.harvestName then database = true break end end if database then MySQL.Async.execute('UPDATE conor_terrharvest SET reputation = reputation+1 WHERE harvest = @harvest AND faction = @faction', { ['@harvest'] = harvestInfo.harvestName, ['@faction'] = job, }, function (rowsChanged) end) else MySQL.Async.execute('INSERT INTO conor_terrharvest (harvest, faction, reputation) VALUES (@harvest, @faction, @reputation)', { ['@harvest'] = harvestInfo.harvestName, ['@faction'] = job, ['@reputation'] = 1, }, function (rowsChanged) end) end end) end) RegisterNetEvent('conor-territoryHarvest:Server:PayFee', function(harvestInfo, owner) local src = source local paid = false local xPlayer = ESX.GetPlayerFromId(src) local amount = harvestInfo.harvestFee if xPlayer.getAccount('bank') >= amount then xPlayer.removeAccountMoney('bank', amount) TriggerClientEvent('conor-territoryHarvest:HarvestItem', src, harvestInfo) paid = true else TriggerClientEvent('conor-territoryHarvest:Notify',src, Config.Lang['no_cash'],Config.LangType['error']) end if Config.PaymentToSociety and paid then TriggerEvent('conor-territoryHarvest:PaySociety', amount, owner) end TriggerClientEvent('conor-territoryHarvest:HarvestDefence', -1, harvestInfo, owner) end)
Leave a Comment