Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(update): refactored code to make it more readable #36

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 64 additions & 64 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,49 @@ TriggerEvent('esx_society:registerSociety', 'taxi', 'Taxi', 'society_taxi', 'soc
type = 'public'
})

RegisterNetEvent('esx_taxijob:success')
AddEventHandler('esx_taxijob:success', function()
RegisterNetEvent('esx_taxijob:success', function()
local xPlayer = ESX.GetPlayerFromId(source)
local timeNow = os.clock()

if not xPlayer.job.name == 'taxi' then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be ~=

print(('[^3WARNING^7] Player ^5%s^7 attempted to ^5esx_taxijob:success^7 (cheating)'):format(source))
return
end

if xPlayer.job.name == 'taxi' then
if not lastPlayerSuccess[source] or timeNow - lastPlayerSuccess[source] > 5 then
lastPlayerSuccess[source] = timeNow
if not lastPlayerSuccess[source] or timeNow - lastPlayerSuccess[source] > 5 then
lastPlayerSuccess[source] = timeNow

math.randomseed(os.time())
local total = math.random(Config.NPCJobEarnings.min, Config.NPCJobEarnings.max)
local total = math.random(Config.NPCJobEarnings.min, Config.NPCJobEarnings.max)

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)
if account then
local playerMoney = ESX.Math.Round(total / 100 * 30)
local societyMoney = ESX.Math.Round(total / 100 * 70)

xPlayer.addMoney(playerMoney, "Taxi Fair")
account.addMoney(societyMoney)
xPlayer.addMoney(playerMoney, "Taxi Fair")
account.addMoney(societyMoney)

xPlayer.showNotification(TranslateCap('comp_earned', societyMoney, playerMoney))
else
xPlayer.addMoney(total, "Taxi Fair")
xPlayer.showNotification(TranslateCap('have_earned', total))
end
end)
end
else
print(('[^3WARNING^7] Player ^5%s^7 attempted to ^5esx_taxijob:success^7 (cheating)'):format(source))
xPlayer.showNotification(TranslateCap('comp_earned', societyMoney, playerMoney))
else
xPlayer.addMoney(total, "Taxi Fair")
xPlayer.showNotification(TranslateCap('have_earned', total))
end
end)
end
end)

ESX.RegisterServerCallback("esx_taxijob:SpawnVehicle", function(source, cb, model , props)
local xPlayer = ESX.GetPlayerFromId(source)

if xPlayer.job.name ~= "taxi" then
if not xPlayer.job.name == "taxi" then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same thing here use ~=

print(('[^3WARNING^7] Player ^5%s^7 attempted to Exploit Vehicle Spawing!!'):format(source))
return
end

local SpawnPoint = vector3(Config.Zones.VehicleSpawnPoint.Pos.x, Config.Zones.VehicleSpawnPoint.Pos.y, Config.Zones.VehicleSpawnPoint.Pos.z)
ESX.OneSync.SpawnVehicle(joaat(model), SpawnPoint, Config.Zones.VehicleSpawnPoint.Heading, props, function(vehicle)
local vehicle = NetworkGetEntityFromNetworkId(vehicle)
Expand All @@ -63,31 +63,31 @@ ESX.RegisterServerCallback("esx_taxijob:SpawnVehicle", function(source, cb, mode
cb()
end)

RegisterNetEvent('esx_taxijob:getStockItem')
AddEventHandler('esx_taxijob:getStockItem', function(itemName, count)
RegisterNetEvent('esx_taxijob:getStockItem', function(itemName, count)
local xPlayer = ESX.GetPlayerFromId(source)

if not xPlayer.job.name == 'taxi' then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same thing here ~=

print(('[^3WARNING^7] Player ^5%s^7 attempted ^5esx_taxijob:getStockItem^7 (cheating)'):format(source))
return
end

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(TranslateCap('have_withdrawn', count, item.label))
else
xPlayer.showNotification(TranslateCap('player_cannot_hold'))
end
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same thing here should get rid of nestling

-- can the player carry the said amount of x item?
if xPlayer.canCarryItem(itemName, count) then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be
if not xPlayer.canCarryItem(itemName, count) then
return xPlayer.showNotification(TranslateCap('player_cannot_hold'))
end

-- rest of the code here

inventory.removeItem(itemName, count)
xPlayer.addInventoryItem(itemName, count)
xPlayer.showNotification(TranslateCap('have_withdrawn', count, item.label))
else
xPlayer.showNotification(TranslateCap('quantity_invalid'))
xPlayer.showNotification(TranslateCap('player_cannot_hold'))
end
end)
else
print(('[^3WARNING^7] Player ^5%s^7 attempted ^5esx_taxijob:getStockItem^7 (cheating)'):format(source))
end
else
xPlayer.showNotification(TranslateCap('quantity_invalid'))
end
end)
end)

ESX.RegisterServerCallback('esx_taxijob:getStockItems', function(source, cb)
Expand All @@ -96,26 +96,26 @@ ESX.RegisterServerCallback('esx_taxijob:getStockItems', function(source, cb)
end)
end)

RegisterNetEvent('esx_taxijob:putStockItems')
AddEventHandler('esx_taxijob:putStockItems', function(itemName, count)
RegisterNetEvent('esx_taxijob:putStockItems', function(itemName, count)
local xPlayer = ESX.GetPlayerFromId(source)
local sourceItem = xPlayer.getInventoryItem(itemName)

if xPlayer.job.name == 'taxi' then
TriggerEvent('esx_addoninventory:getSharedInventory', 'society_taxi', function(inventory)
local item = inventory.getItem(itemName)

if sourceItem.count >= count and count > 0 then
xPlayer.removeInventoryItem(itemName, count)
inventory.addItem(itemName, count)
xPlayer.showNotification(TranslateCap('have_deposited', count, item.label))
else
xPlayer.showNotification(TranslateCap('quantity_invalid'))
end
end)
else
local sourceItem = xPlayer.getInventoryItem(itemName)

if not xPlayer.job.name == 'taxi' then
print(('[^3WARNING^7] Player ^5%s^7 attempted ^5esx_taxijob:putStockItems^7 (cheating)'):format(source))
return
end

TriggerEvent('esx_addoninventory:getSharedInventory', 'society_taxi', function(inventory)
local item = inventory.getItem(itemName)

if sourceItem.count >= count and count > 0 then
xPlayer.removeInventoryItem(itemName, count)
inventory.addItem(itemName, count)
xPlayer.showNotification(TranslateCap('have_deposited', count, item.label))
else
xPlayer.showNotification(TranslateCap('quantity_invalid'))
end
end)
end)

ESX.RegisterServerCallback('esx_taxijob:getPlayerInventory', function(source, cb)
Expand Down
Loading