Indent cleanup

This commit is contained in:
ElPumpo
2019-04-17 11:38:12 +02:00
parent 16a78f4613
commit 3d27e2b0a6
3 changed files with 7 additions and 44 deletions
+3 -7
View File
@@ -1138,7 +1138,7 @@ ESX.ShowInventory = function()
local players = ESX.Game.GetPlayersInArea(GetEntityCoords(playerPed), 3.0) local players = ESX.Game.GetPlayersInArea(GetEntityCoords(playerPed), 3.0)
local foundPlayers = false local foundPlayers = false
local elements = {} local elements = {}
for i=1, #players, 1 do for i=1, #players, 1 do
if players[i] ~= PlayerId() then if players[i] ~= PlayerId() then
foundPlayers = true foundPlayers = true
@@ -1168,7 +1168,7 @@ ESX.ShowInventory = function()
for i=1, #players, 1 do for i=1, #players, 1 do
if players[i] ~= PlayerId() then if players[i] ~= PlayerId() then
if players[i] == data2.current.player then if players[i] == data2.current.player then
foundPlayers = true foundPlayers = true
nearbyPlayer = players[i] nearbyPlayer = players[i]
@@ -1347,20 +1347,16 @@ end)
-- SetTimeout -- SetTimeout
Citizen.CreateThread(function() Citizen.CreateThread(function()
while true do while true do
Citizen.Wait(0) Citizen.Wait(0)
local currTime = GetGameTimer() local currTime = GetGameTimer()
for i=1, #ESX.TimeoutCallbacks, 1 do for i=1, #ESX.TimeoutCallbacks, 1 do
if ESX.TimeoutCallbacks[i] then
if ESX.TimeoutCallbacks[i] ~= nil then
if currTime >= ESX.TimeoutCallbacks[i].time then if currTime >= ESX.TimeoutCallbacks[i].time then
ESX.TimeoutCallbacks[i].cb() ESX.TimeoutCallbacks[i].cb()
ESX.TimeoutCallbacks[i] = nil ESX.TimeoutCallbacks[i] = nil
end end
end end
end end
end end
end) end)
+2 -11
View File
@@ -37,14 +37,12 @@ ESX.TriggerServerCallback = function(name, requestId, source, cb, ...)
end end
ESX.SavePlayer = function(xPlayer, cb) ESX.SavePlayer = function(xPlayer, cb)
local asyncTasks = {} local asyncTasks = {}
xPlayer.setLastPosition(xPlayer.getCoords()) xPlayer.setLastPosition(xPlayer.getCoords())
-- User accounts -- User accounts
for i=1, #xPlayer.accounts, 1 do for i=1, #xPlayer.accounts, 1 do
if ESX.LastPlayerData[xPlayer.source].accounts[xPlayer.accounts[i].name] ~= xPlayer.accounts[i].money then if ESX.LastPlayerData[xPlayer.source].accounts[xPlayer.accounts[i].name] ~= xPlayer.accounts[i].money then
table.insert(asyncTasks, function(cb) table.insert(asyncTasks, function(cb)
MySQL.Async.execute('UPDATE user_accounts SET `money` = @money WHERE identifier = @identifier AND name = @name', { MySQL.Async.execute('UPDATE user_accounts SET `money` = @money WHERE identifier = @identifier AND name = @name', {
['@money'] = xPlayer.accounts[i].money, ['@money'] = xPlayer.accounts[i].money,
@@ -56,16 +54,12 @@ ESX.SavePlayer = function(xPlayer, cb)
end) end)
ESX.LastPlayerData[xPlayer.source].accounts[xPlayer.accounts[i].name] = xPlayer.accounts[i].money ESX.LastPlayerData[xPlayer.source].accounts[xPlayer.accounts[i].name] = xPlayer.accounts[i].money
end end
end end
-- Inventory items -- Inventory items
for i=1, #xPlayer.inventory, 1 do for i=1, #xPlayer.inventory, 1 do
if ESX.LastPlayerData[xPlayer.source].items[xPlayer.inventory[i].name] ~= xPlayer.inventory[i].count then if ESX.LastPlayerData[xPlayer.source].items[xPlayer.inventory[i].name] ~= xPlayer.inventory[i].count then
table.insert(asyncTasks, function(cb) table.insert(asyncTasks, function(cb)
MySQL.Async.execute('UPDATE user_inventory SET `count` = @count WHERE identifier = @identifier AND item = @item', { MySQL.Async.execute('UPDATE user_inventory SET `count` = @count WHERE identifier = @identifier AND item = @item', {
['@count'] = xPlayer.inventory[i].count, ['@count'] = xPlayer.inventory[i].count,
@@ -77,9 +71,7 @@ ESX.SavePlayer = function(xPlayer, cb)
end) end)
ESX.LastPlayerData[xPlayer.source].items[xPlayer.inventory[i].name] = xPlayer.inventory[i].count ESX.LastPlayerData[xPlayer.source].items[xPlayer.inventory[i].name] = xPlayer.inventory[i].count
end end
end end
-- Job, loadout and position -- Job, loadout and position
@@ -96,13 +88,12 @@ ESX.SavePlayer = function(xPlayer, cb)
end) end)
Async.parallel(asyncTasks, function(results) Async.parallel(asyncTasks, function(results)
RconPrint('[SAVED] ' .. xPlayer.name .. "\n") RconPrint('[SAVED] ' .. xPlayer.name .. "^7\n")
if cb ~= nil then if cb ~= nil then
cb() cb()
end end
end) end)
end end
ESX.SavePlayers = function(cb) ESX.SavePlayers = function(cb)
+2 -26
View File
@@ -12,7 +12,6 @@ AddEventHandler('es:playerLoaded', function(source, _player)
} }
TriggerEvent('es:getPlayerFromId', _source, function(player) TriggerEvent('es:getPlayerFromId', _source, function(player)
-- Update user name in DB -- Update user name in DB
table.insert(tasks, function(cb) table.insert(tasks, function(cb)
MySQL.Async.execute('UPDATE `users` SET `name` = @name WHERE `identifier` = @identifier', { MySQL.Async.execute('UPDATE `users` SET `name` = @name WHERE `identifier` = @identifier', {
@@ -78,7 +77,6 @@ AddEventHandler('es:playerLoaded', function(source, _player)
end end
if not found then if not found then
table.insert(userData.inventory, { table.insert(userData.inventory, {
name = k, name = k,
count = 0, count = 0,
@@ -90,7 +88,6 @@ AddEventHandler('es:playerLoaded', function(source, _player)
}) })
local scope = function(item, identifier) local scope = function(item, identifier)
table.insert(tasks2, function(cb2) table.insert(tasks2, function(cb2)
MySQL.Async.execute('INSERT INTO user_inventory (identifier, item, count) VALUES (@identifier, @item, @count)', { MySQL.Async.execute('INSERT INTO user_inventory (identifier, item, count) VALUES (@identifier, @item, @count)', {
['@identifier'] = identifier, ['@identifier'] = identifier,
@@ -100,11 +97,9 @@ AddEventHandler('es:playerLoaded', function(source, _player)
cb2() cb2()
end) end)
end) end)
end end
scope(k, player.getIdentifier()) scope(k, player.getIdentifier())
end end
end end
@@ -204,11 +199,9 @@ AddEventHandler('es:playerLoaded', function(source, _player)
-- Run Tasks -- Run Tasks
Async.parallel(tasks, function(results) Async.parallel(tasks, function(results)
local xPlayer = CreateExtendedPlayer(player, userData.accounts, userData.inventory, userData.job, userData.loadout, userData.playerName, userData.lastPosition) local xPlayer = CreateExtendedPlayer(player, userData.accounts, userData.inventory, userData.job, userData.loadout, userData.playerName, userData.lastPosition)
xPlayer.getMissingAccounts(function(missingAccounts) xPlayer.getMissingAccounts(function(missingAccounts)
if #missingAccounts > 0 then if #missingAccounts > 0 then
for i=1, #missingAccounts, 1 do for i=1, #missingAccounts, 1 do
@@ -237,24 +230,21 @@ AddEventHandler('es:playerLoaded', function(source, _player)
}) })
xPlayer.displayMoney(xPlayer.getMoney()) xPlayer.displayMoney(xPlayer.getMoney())
end) end)
end) end)
end) end)
end) end)
AddEventHandler('playerDropped', function(reason) AddEventHandler('playerDropped', function(reason)
local _source = source local _source = source
local xPlayer = ESX.GetPlayerFromId(_source) local xPlayer = ESX.GetPlayerFromId(_source)
if xPlayer ~= nil then if xPlayer then
TriggerEvent('esx:playerDropped', _source, reason) TriggerEvent('esx:playerDropped', _source, reason)
ESX.SavePlayer(xPlayer, function() ESX.SavePlayer(xPlayer, function()
ESX.Players[_source] = nil ESX.Players[_source] = nil
ESX.LastPlayerData[_source] = nil ESX.LastPlayerData[_source] = nil
end) end)
end end
@@ -303,13 +293,11 @@ AddEventHandler('esx:giveInventoryItem', function(target, type, itemName, itemCo
elseif type == 'item_money' then elseif type == 'item_money' then
if itemCount > 0 and sourceXPlayer.getMoney() >= itemCount then if itemCount > 0 and sourceXPlayer.getMoney() >= itemCount then
sourceXPlayer.removeMoney(itemCount) sourceXPlayer.removeMoney(itemCount)
targetXPlayer.addMoney (itemCount) targetXPlayer.addMoney (itemCount)
TriggerClientEvent('esx:showNotification', _source, _U('gave_money', ESX.Math.GroupDigits(itemCount), targetXPlayer.name)) TriggerClientEvent('esx:showNotification', _source, _U('gave_money', ESX.Math.GroupDigits(itemCount), targetXPlayer.name))
TriggerClientEvent('esx:showNotification', target, _U('received_money', ESX.Math.GroupDigits(itemCount), sourceXPlayer.name)) TriggerClientEvent('esx:showNotification', target, _U('received_money', ESX.Math.GroupDigits(itemCount), sourceXPlayer.name))
else else
TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_amount')) TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_amount'))
end end
@@ -317,13 +305,11 @@ AddEventHandler('esx:giveInventoryItem', function(target, type, itemName, itemCo
elseif type == 'item_account' then elseif type == 'item_account' then
if itemCount > 0 and sourceXPlayer.getAccount(itemName).money >= itemCount then if itemCount > 0 and sourceXPlayer.getAccount(itemName).money >= itemCount then
sourceXPlayer.removeAccountMoney(itemName, itemCount) sourceXPlayer.removeAccountMoney(itemName, itemCount)
targetXPlayer.addAccountMoney (itemName, itemCount) targetXPlayer.addAccountMoney (itemName, itemCount)
TriggerClientEvent('esx:showNotification', _source, _U('gave_account_money', ESX.Math.GroupDigits(itemCount), Config.AccountLabels[itemName], targetXPlayer.name)) TriggerClientEvent('esx:showNotification', _source, _U('gave_account_money', ESX.Math.GroupDigits(itemCount), Config.AccountLabels[itemName], targetXPlayer.name))
TriggerClientEvent('esx:showNotification', target, _U('received_account_money', ESX.Math.GroupDigits(itemCount), Config.AccountLabels[itemName], sourceXPlayer.name)) TriggerClientEvent('esx:showNotification', target, _U('received_account_money', ESX.Math.GroupDigits(itemCount), Config.AccountLabels[itemName], sourceXPlayer.name))
else else
TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_amount')) TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_amount'))
end end
@@ -331,7 +317,6 @@ AddEventHandler('esx:giveInventoryItem', function(target, type, itemName, itemCo
elseif type == 'item_weapon' then elseif type == 'item_weapon' then
if not targetXPlayer.hasWeapon(itemName) then if not targetXPlayer.hasWeapon(itemName) then
sourceXPlayer.removeWeapon(itemName) sourceXPlayer.removeWeapon(itemName)
targetXPlayer.addWeapon(itemName, itemCount) targetXPlayer.addWeapon(itemName, itemCount)
@@ -344,14 +329,12 @@ AddEventHandler('esx:giveInventoryItem', function(target, type, itemName, itemCo
TriggerClientEvent('esx:showNotification', _source, _U('gave_weapon', weaponLabel, targetXPlayer.name)) TriggerClientEvent('esx:showNotification', _source, _U('gave_weapon', weaponLabel, targetXPlayer.name))
TriggerClientEvent('esx:showNotification', target, _U('received_weapon', weaponLabel, sourceXPlayer.name)) TriggerClientEvent('esx:showNotification', target, _U('received_weapon', weaponLabel, sourceXPlayer.name))
end end
else else
TriggerClientEvent('esx:showNotification', _source, _U('gave_weapon_hasalready', targetXPlayer.name, weaponLabel)) TriggerClientEvent('esx:showNotification', _source, _U('gave_weapon_hasalready', targetXPlayer.name, weaponLabel))
TriggerClientEvent('esx:showNotification', _source, _U('received_weapon_hasalready', sourceXPlayer.name, weaponLabel)) TriggerClientEvent('esx:showNotification', _source, _U('received_weapon_hasalready', sourceXPlayer.name, weaponLabel))
end end
end end
end) end)
RegisterServerEvent('esx:removeInventoryItem') RegisterServerEvent('esx:removeInventoryItem')
@@ -363,7 +346,6 @@ AddEventHandler('esx:removeInventoryItem', function(type, itemName, itemCount)
if itemCount == nil or itemCount < 1 then if itemCount == nil or itemCount < 1 then
TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_quantity')) TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_quantity'))
else else
local xPlayer = ESX.GetPlayerFromId(source) local xPlayer = ESX.GetPlayerFromId(source)
local xItem = xPlayer.getInventoryItem(itemName) local xItem = xPlayer.getInventoryItem(itemName)
@@ -376,7 +358,6 @@ AddEventHandler('esx:removeInventoryItem', function(type, itemName, itemCount)
ESX.CreatePickup('item_standard', itemName, itemCount, pickupLabel, _source) ESX.CreatePickup('item_standard', itemName, itemCount, pickupLabel, _source)
TriggerClientEvent('esx:showNotification', _source, _U('threw_standard', itemCount, xItem.label)) TriggerClientEvent('esx:showNotification', _source, _U('threw_standard', itemCount, xItem.label))
end end
end end
elseif type == 'item_money' then elseif type == 'item_money' then
@@ -384,7 +365,6 @@ AddEventHandler('esx:removeInventoryItem', function(type, itemName, itemCount)
if itemCount == nil or itemCount < 1 then if itemCount == nil or itemCount < 1 then
TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_amount')) TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_amount'))
else else
local xPlayer = ESX.GetPlayerFromId(source) local xPlayer = ESX.GetPlayerFromId(source)
local playerCash = xPlayer.getMoney() local playerCash = xPlayer.getMoney()
@@ -397,7 +377,6 @@ AddEventHandler('esx:removeInventoryItem', function(type, itemName, itemCount)
ESX.CreatePickup('item_money', 'money', itemCount, pickupLabel, _source) ESX.CreatePickup('item_money', 'money', itemCount, pickupLabel, _source)
TriggerClientEvent('esx:showNotification', _source, _U('threw_money', ESX.Math.GroupDigits(itemCount))) TriggerClientEvent('esx:showNotification', _source, _U('threw_money', ESX.Math.GroupDigits(itemCount)))
end end
end end
elseif type == 'item_account' then elseif type == 'item_account' then
@@ -405,7 +384,6 @@ AddEventHandler('esx:removeInventoryItem', function(type, itemName, itemCount)
if itemCount == nil or itemCount < 1 then if itemCount == nil or itemCount < 1 then
TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_amount')) TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_amount'))
else else
local xPlayer = ESX.GetPlayerFromId(source) local xPlayer = ESX.GetPlayerFromId(source)
local account = xPlayer.getAccount(itemName) local account = xPlayer.getAccount(itemName)
@@ -418,7 +396,6 @@ AddEventHandler('esx:removeInventoryItem', function(type, itemName, itemCount)
ESX.CreatePickup('item_account', itemName, itemCount, pickupLabel, _source) ESX.CreatePickup('item_account', itemName, itemCount, pickupLabel, _source)
TriggerClientEvent('esx:showNotification', _source, _U('threw_account', ESX.Math.GroupDigits(itemCount), string.lower(account.label))) TriggerClientEvent('esx:showNotification', _source, _U('threw_account', ESX.Math.GroupDigits(itemCount), string.lower(account.label)))
end end
end end
elseif type == 'item_weapon' then elseif type == 'item_weapon' then
@@ -449,7 +426,6 @@ AddEventHandler('esx:removeInventoryItem', function(type, itemName, itemCount)
end end
end end
end) end)
RegisterServerEvent('esx:useItem') RegisterServerEvent('esx:useItem')