Performance improvements

This commit is contained in:
ElPumpo
2018-09-20 22:45:00 +02:00
parent c07cdde7c8
commit 810949fe09
3 changed files with 60 additions and 57 deletions
+3 -5
View File
@@ -60,7 +60,7 @@ AddEventHandler('playerSpawned', function()
-- Restore position
if ESX.PlayerData.lastPosition ~= nil then
SetEntityCoords(playerPed, ESX.PlayerData.lastPosition.x, ESX.PlayerData.lastPosition.y, ESX.PlayerData.lastPosition.z)
SetEntityCoords(playerPed, ESX.PlayerData.lastPosition.x, ESX.PlayerData.lastPosition.y, ESX.PlayerData.lastPosition.z)
end
TriggerEvent('esx:restoreLoadout') -- restore loadout
@@ -401,7 +401,7 @@ end)
-- Pause menu disable HUD display
Citizen.CreateThread(function()
while true do
Citizen.Wait(1)
Citizen.Wait(500)
if IsPauseMenuActive() and not IsPaused then
IsPaused = true
@@ -419,7 +419,7 @@ end)
Citizen.CreateThread(function()
while true do
Citizen.Wait(1)
Citizen.Wait(500)
local playerPed = PlayerPedId()
local loadout = {}
@@ -504,7 +504,6 @@ if Config.DisableWantedLevel then
Citizen.CreateThread(function()
while true do
Citizen.Wait(10)
local playerId = PlayerId()
@@ -512,7 +511,6 @@ if Config.DisableWantedLevel then
SetPlayerWantedLevel(playerId, 0, false)
SetPlayerWantedLevelNow(playerId, false)
end
end
end)
+53 -47
View File
@@ -12,11 +12,13 @@ function CreateExtendedPlayer(player, accounts, inventory, job, loadout, name, l
self.source = self.player.get('source')
self.identifier = self.player.get('identifier')
self.setMoney = function(m)
if m >= 0 then
self.player.setMoney(m)
self.setMoney = function(money)
money = ESX.Round(money)
if money >= 0 then
self.player.setMoney(money)
else
print('es_extended: ' .. self.name .. ' (' .. self.identifier .. ') attempted exploiting! (reason: player tried setting -1 cash balance)')
print(('es_extended: %s attempted exploiting! (reason: player tried setting -1 cash balance)'):format(self.identifier))
end
end
@@ -24,11 +26,13 @@ function CreateExtendedPlayer(player, accounts, inventory, job, loadout, name, l
return self.player.get('money')
end
self.setBankBalance = function(m)
if m >= 0 then
self.player.setBankBalance(m)
self.setBankBalance = function(money)
money = ESX.Round(money)
if money >= 0 then
self.player.setBankBalance(money)
else
print('es_extended: ' .. self.name .. ' (' .. self.identifier .. ') attempted exploiting! (reason: player tried setting -1 bank balance)')
print(('es_extended: %s attempted exploiting! (reason: player tried setting -1 bank balance)'):format(self.identifier))
end
end
@@ -48,44 +52,52 @@ function CreateExtendedPlayer(player, accounts, inventory, job, loadout, name, l
self.player.kick(r)
end
self.addMoney = function(m)
if m >= 0 then
self.player.addMoney(m)
self.addMoney = function(money)
money = ESX.Round(money)
if money >= 0 then
self.player.addMoney(money)
else
print('es_extended: ' .. self.name .. ' (' .. self.identifier .. ') attempted exploiting! (reason: player tried adding -1 cash balance)')
print(('es_extended: %s attempted exploiting! (reason: player tried adding -1 cash balance)'):format(self.identifier))
end
end
self.removeMoney = function(m)
if m >= 0 then
self.player.removeMoney(m)
self.removeMoney = function(money)
money = ESX.Round(money)
if money >= 0 then
self.player.removeMoney(money)
else
print('es_extended: ' .. self.name .. ' (' .. self.identifier .. ') attempted exploiting! (reason: player tried removing -1 cash balance)')
print(('es_extended: %s attempted exploiting! (reason: player tried removing -1 cash balance)'):format(self.identifier))
end
end
self.addBank = function(m)
if m >= 0 then
self.player.addBank(m)
self.addBank = function(money)
money = ESX.Round(money)
if money >= 0 then
self.player.addBank(money)
else
print('es_extended: ' .. self.name .. ' (' .. self.identifier .. ') attempted exploiting! (reason: player tried adding -1 bank balance)')
print(('es_extended: %s attempted exploiting! (reason: player tried adding -1 bank balance)'):format(self.identifier))
end
end
self.removeBank = function(m)
if m >= 0 then
self.player.removeBank(m)
self.removeBank = function(money)
money = ESX.Round(money)
if money >= 0 then
self.player.removeBank(money)
else
print('es_extended: ' .. self.name .. ' (' .. self.identifier .. ') attempted exploiting! (reason: player tried removing -1 bank balance)')
print(('es_extended: %s attempted exploiting! (reason: player tried removing -1 bank balance)'):format(self.identifier))
end
end
self.displayMoney = function(m)
self.player.displayMoney(m)
self.displayMoney = function(money)
self.player.displayMoney(money)
end
self.displayBank = function(m)
self.player.displayBank(m)
self.displayBank = function(money)
self.player.displayBank(money)
end
self.setSessionVar = function(key, value)
@@ -190,13 +202,10 @@ function CreateExtendedPlayer(player, accounts, inventory, job, loadout, name, l
MySQL.Async.fetchAll('SELECT * FROM `user_accounts` WHERE `identifier` = @identifier', {
['@identifier'] = self.getIdentifier()
}, function(result)
local missingAccounts = {}
for i=1, #Config.Accounts, 1 do
if Config.Accounts[i] ~= 'bank' then
local found = false
for j=1, #result, 1 do
@@ -208,13 +217,10 @@ function CreateExtendedPlayer(player, accounts, inventory, job, loadout, name, l
if not found then
table.insert(missingAccounts, Config.Accounts[i])
end
end
end
cb(missingAccounts)
end)
end
@@ -232,37 +238,37 @@ function CreateExtendedPlayer(player, accounts, inventory, job, loadout, name, l
end
end
self.setAccountMoney = function(a, m)
if m < 0 then
print('es_extended: ' .. self.name .. ' (' .. self.identifier .. ') attempted exploiting! (reason: player tried setting -1 account balance)')
self.setAccountMoney = function(acc, money)
if money < 0 then
print(('es_extended: %s attempted exploiting! (reason: player tried setting -1 account balance)'):format(self.identifier))
return
end
local account = self.getAccount(a)
local account = self.getAccount(acc)
local prevMoney = account.money
local newMoney = m
local newMoney = ESX.Round(money)
account.money = newMoney
if a == 'bank' then
if acc == 'bank' then
self.set('bank', newMoney)
end
TriggerClientEvent('esx:setAccountMoney', self.source, account)
end
self.addAccountMoney = function(a, m)
if m < 0 then
print('es_extended: ' .. self.name .. ' (' .. self.identifier .. ') attempted exploiting! (reason: player tried adding -1 account balance)')
self.addAccountMoney = function(acc, money)
if money < 0 then
print(('es_extended: %s attempted exploiting! (reason: player tried adding -1 account balance)'):format(self.identifier))
return
end
local account = self.getAccount(a)
local newMoney = account.money + m
local account = self.getAccount(acc)
local newMoney = account.money + ESX.Round(money)
account.money = newMoney
if a == 'bank' then
if acc == 'bank' then
self.set('bank', newMoney)
end
@@ -271,7 +277,7 @@ function CreateExtendedPlayer(player, accounts, inventory, job, loadout, name, l
self.removeAccountMoney = function(a, m)
if m < 0 then
print('es_extended: ' .. self.name .. ' (' .. self.identifier .. ') attempted exploiting! (reason: player tried removing -1 account balance)')
print(('es_extended: %s attempted exploiting! (reason: player tried removing -1 account balance)'):format(self.identifier))
return
end
+4 -5
View File
@@ -251,17 +251,16 @@ end)
RegisterServerEvent('esx:updateLoadout')
AddEventHandler('esx:updateLoadout', function(loadout)
local xPlayer = ESX.GetPlayerFromId(source)
xPlayer.loadout = loadout
local xPlayer = ESX.GetPlayerFromId(source)
xPlayer.loadout = loadout
end)
RegisterServerEvent('esx:updateLastPosition')
AddEventHandler('esx:updateLastPosition', function(position)
local xPlayer = ESX.GetPlayerFromId(source)
xPlayer.lastPosition = position
local xPlayer = ESX.GetPlayerFromId(source)
xPlayer.lastPosition = position
end)
RegisterServerEvent('esx:giveInventoryItem')
AddEventHandler('esx:giveInventoryItem', function(target, type, itemName, itemCount)
local _source = source