diff --git a/client/main.lua b/client/main.lua index becd6c01..0d953449 100644 --- a/client/main.lua +++ b/client/main.lua @@ -392,19 +392,14 @@ end function OpenPutStocksMenu() ESX.TriggerServerCallback('esx_taxijob:getPlayerInventory', function(inventory) - local elements = {} - for i=1, #inventory.items, 1 do - local item = inventory.items[i] - - if item.count > 0 then - table.insert(elements, { - label = item.label .. ' x' .. item.count, - type = 'item_standard', -- not used - value = item.name - }) - end + for k,v in ipairs(inventory) do + table.insert(elements, { + label = v.label .. ' x' .. v.count, + type = 'item_standard', -- not used + value = v.name + }) end ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'stocks_menu', { diff --git a/config.lua b/config.lua index cebf1139..8b887be6 100644 --- a/config.lua +++ b/config.lua @@ -1,23 +1,18 @@ Config = {} -Config.DrawDistance = 100.0 +Config.DrawDistance = 100 Config.NPCJobEarnings = {min = 300, max = 600} Config.MinimumDistance = 3000 -- Minimum NPC job destination distance from the pickup in GTA units, a higher number prevents nearby destionations. Config.MaxInService = -1 -Config.EnablePlayerManagement = false +Config.EnablePlayerManagement = true Config.EnableSocietyOwnedVehicles = false Config.Locale = 'fr' Config.AuthorizedVehicles = { - - { - model = 'taxi', - label = 'Taxi' - } - + {model = 'taxi', label = 'Taxi'} } Config.Zones = { diff --git a/server/main.lua b/server/main.lua index ab64c9f0..1667071c 100644 --- a/server/main.lua +++ b/server/main.lua @@ -1,4 +1,5 @@ ESX = nil +local lastPlayerSuccess = {} TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) @@ -9,70 +10,67 @@ end TriggerEvent('esx_phone:registerNumber', 'taxi', _U('taxi_client'), true, true) TriggerEvent('esx_society:registerSociety', 'taxi', 'Taxi', 'society_taxi', 'society_taxi', 'society_taxi', {type = 'public'}) -RegisterServerEvent('esx_taxijob:success') +RegisterNetEvent('esx_taxijob:success') AddEventHandler('esx_taxijob:success', function() local xPlayer = ESX.GetPlayerFromId(source) + local timeNow = os.clock() - if xPlayer.job.name ~= 'taxi' then - print(('esx_taxijob: %s attempted to trigger success!'):format(xPlayer.identifier)) - return - end + if xPlayer.job.name == 'taxi' then + if not lastPlayerSuccess[source] or timeNow - lastPlayerSuccess[source] > 5 then + lastPlayerSuccess[source] = timeNow - math.randomseed(os.time()) + math.randomseed(os.time()) + local total = math.random(Config.NPCJobEarnings.min, Config.NPCJobEarnings.max) - local total = math.random(Config.NPCJobEarnings.min, Config.NPCJobEarnings.max) - local societyAccount + if xPlayer.job.grade >= 3 then + total = total * 2 + end - if xPlayer.job.grade >= 3 then - total = total * 2 - end + TriggerEvent('esx_addonaccount:getSharedAccount', 'society_taxi', function(account) + if account then + local playerMoney = ESX.Math.Round(total / 100 * 30) + local societyMoney = ESX.Math.Round(total / 100 * 70) - TriggerEvent('esx_addonaccount:getSharedAccount', 'society_taxi', function(account) - societyAccount = account - end) + xPlayer.addMoney(playerMoney) + account.addMoney(societyMoney) - if societyAccount then - local playerMoney = ESX.Math.Round(total / 100 * 30) - local societyMoney = ESX.Math.Round(total / 100 * 70) - - xPlayer.addMoney(playerMoney) - societyAccount.addMoney(societyMoney) - - xPlayer.showNotification(_U('comp_earned', societyMoney, playerMoney)) + xPlayer.showNotification(_U('comp_earned', societyMoney, playerMoney)) + else + xPlayer.addMoney(total) + xPlayer.showNotification(_U('have_earned', total)) + end + end) + end else - xPlayer.addMoney(total) - xPlayer.showNotification(_U('have_earned', total)) + print(('[esx_taxijob] [^3WARNING^7] %s attempted to trigger success (cheating)'):format(xPlayer.identifier)) end - end) -RegisterServerEvent('esx_taxijob:getStockItem') +RegisterNetEvent('esx_taxijob:getStockItem') AddEventHandler('esx_taxijob:getStockItem', function(itemName, count) local xPlayer = ESX.GetPlayerFromId(source) - if xPlayer.job.name ~= 'taxi' then - print(('esx_taxijob: %s attempted to trigger getStockItem!'):format(xPlayer.identifier)) - return - end - - TriggerEvent('esx_addoninventory:getSharedInventory', 'society_taxi', function(inventory) - local item = inventory.getItem(itemName) + if xPlayer.job.name == 'taxi' then + TriggerEvent('esx_addoninventory:getSharedInventory', 'society_taxi', function(inventory) + local item = inventory.getItem(itemName) - -- is there enough in the society? - if count > 0 and item.count >= count then - - -- can the player carry the said amount of x item? - if xPlayer.canCarryItem(itemName, count) then - inventory.removeItem(itemName, count) - xPlayer.addInventoryItem(itemName, count) - xPlayer.showNotification(_U('have_withdrawn', count, item.label)) + -- is there enough in the society? + if count > 0 and item.count >= count then + -- can the player carry the said amount of x item? + if xPlayer.canCarryItem(itemName, count) then + inventory.removeItem(itemName, count) + xPlayer.addInventoryItem(itemName, count) + xPlayer.showNotification(_U('have_withdrawn', count, item.label)) + else + xPlayer.showNotification(_U('player_cannot_hold')) + end else - xPlayer.showNotification(_U('player_cannot_hold')) + xPlayer.showNotification(_U('quantity_invalid')) end - else - xPlayer.showNotification(_U('quantity_invalid')) - end - end) + end) + else + print(('[esx_taxijob] [^3WARNING^7] %s attempted to trigger getStockItem'):format(xPlayer.identifier)) + end end) ESX.RegisterServerCallback('esx_taxijob:getStockItems', function(source, cb) @@ -81,33 +79,28 @@ ESX.RegisterServerCallback('esx_taxijob:getStockItems', function(source, cb) end) end) -RegisterServerEvent('esx_taxijob:putStockItems') +RegisterNetEvent('esx_taxijob:putStockItems') AddEventHandler('esx_taxijob:putStockItems', function(itemName, count) local xPlayer = ESX.GetPlayerFromId(source) - if xPlayer.job.name ~= 'taxi' then - print(('esx_taxijob: %s attempted to trigger putStockItems!'):format(xPlayer.identifier)) - return + if xPlayer.job.name == 'taxi' then + TriggerEvent('esx_addoninventory:getSharedInventory', 'society_taxi', function(inventory) + local item = inventory.getItem(itemName) + + if item.count >= 0 then + xPlayer.removeInventoryItem(itemName, count) + inventory.addItem(itemName, count) + xPlayer.showNotification(_U('have_deposited', count, item.label)) + else + xPlayer.showNotification(_U('quantity_invalid')) + end + end) + else + print(('[esx_taxijob] [^3WARNING^7] %s attempted to trigger putStockItems'):format(xPlayer.identifier)) end - - TriggerEvent('esx_addoninventory:getSharedInventory', 'society_taxi', function(inventory) - local item = inventory.getItem(itemName) - - if item.count >= 0 then - xPlayer.removeInventoryItem(itemName, count) - inventory.addItem(itemName, count) - xPlayer.showNotification(_U('have_deposited', count, item.label)) - else - xPlayer.showNotification(_U('quantity_invalid')) - end - - end) - end) ESX.RegisterServerCallback('esx_taxijob:getPlayerInventory', function(source, cb) local xPlayer = ESX.GetPlayerFromId(source) - local items = xPlayer.inventory - - cb( { items = items } ) + cb(xPlayer.getInventory()) end)