Tab indent update

This commit is contained in:
ElPumpo
2018-09-01 17:43:35 +02:00
parent 7e31fc90f4
commit c07cdde7c8
14 changed files with 2058 additions and 2407 deletions
+413 -454
View File
@@ -1,462 +1,421 @@
function CreateExtendedPlayer(player, accounts, inventory, job, loadout, name, lastPosition)
local self = {}
self.player = player
self.accounts = accounts
self.inventory = inventory
self.job = job
self.loadout = loadout
self.name = name
self.lastPosition = lastPosition
self.source = self.player.get('source')
self.identifier = self.player.get('identifier')
self.setMoney = function(m)
if m >= 0 then
self.player.setMoney(m)
else
print('es_extended: ' .. self.name .. ' (' .. self.identifier .. ') attempted exploiting! (reason: player tried setting -1 cash balance)')
end
end
self.getMoney = function()
return self.player.get('money')
end
self.setBankBalance = function(m)
if m >= 0 then
self.player.setBankBalance(m)
else
print('es_extended: ' .. self.name .. ' (' .. self.identifier .. ') attempted exploiting! (reason: player tried setting -1 bank balance)')
end
end
self.getBank = function()
return self.player.get('bank')
end
self.getCoords = function()
return self.player.get('coords')
end
self.setCoords = function(x, y, z)
self.player.coords = {x = x, y = y, z = z}
end
self.kick = function(r)
self.player.kick(r)
end
self.addMoney = function(m)
if m >= 0 then
self.player.addMoney(m)
else
print('es_extended: ' .. self.name .. ' (' .. self.identifier .. ') attempted exploiting! (reason: player tried adding -1 cash balance)')
end
end
self.removeMoney = function(m)
if m >= 0 then
self.player.removeMoney(m)
else
print('es_extended: ' .. self.name .. ' (' .. self.identifier .. ') attempted exploiting! (reason: player tried removing -1 cash balance)')
end
end
self.addBank = function(m)
if m >= 0 then
self.player.addBank(m)
else
print('es_extended: ' .. self.name .. ' (' .. self.identifier .. ') attempted exploiting! (reason: player tried adding -1 bank balance)')
end
end
self.removeBank = function(m)
if m >= 0 then
self.player.removeBank(m)
else
print('es_extended: ' .. self.name .. ' (' .. self.identifier .. ') attempted exploiting! (reason: player tried removing -1 bank balance)')
end
end
self.displayMoney = function(m)
self.player.displayMoney(m)
end
self.displayBank = function(m)
self.player.displayBank(m)
end
self.setSessionVar = function(key, value)
self.player.setSessionVar(key, value)
end
self.getSessionVar = function(k)
return self.player.getSessionVar(k)
end
self.getPermissions = function()
return self.player.getPermissions()
end
self.setPermissions = function(p)
self.player.setPermissions(p)
end
self.getIdentifier = function()
return self.player.getIdentifier()
end
self.getGroup = function()
return self.player.getGroup()
end
self.set = function(k, v)
self.player.set(k, v)
end
self.get = function(k)
return self.player.get(k)
end
self.getPlayer = function()
return self.player
end
self.getAccounts = function()
local accounts = {}
for i=1, #Config.Accounts, 1 do
if Config.Accounts[i] == 'bank' then
table.insert(accounts, {
name = 'bank',
money = self.get('bank'),
label = Config.AccountLabels['bank']
})
else
for j=1, #self.accounts, 1 do
if self.accounts[j].name == Config.Accounts[i] then
table.insert(accounts, self.accounts[j])
end
end
end
end
return accounts
end
self.getAccount = function(a)
if a == 'bank' then
return {
name = 'bank',
money = self.get('bank'),
label = Config.AccountLabels['bank']
}
end
for i=1, #self.accounts, 1 do
if self.accounts[i].name == a then
return self.accounts[i]
end
end
end
self.getInventory = function()
return self.inventory
end
self.getJob = function()
return self.job
end
self.getLoadout = function()
return self.loadout
end
local self = {}
self.player = player
self.accounts = accounts
self.inventory = inventory
self.job = job
self.loadout = loadout
self.name = name
self.lastPosition = lastPosition
self.source = self.player.get('source')
self.identifier = self.player.get('identifier')
self.setMoney = function(m)
if m >= 0 then
self.player.setMoney(m)
else
print('es_extended: ' .. self.name .. ' (' .. self.identifier .. ') attempted exploiting! (reason: player tried setting -1 cash balance)')
end
end
self.getMoney = function()
return self.player.get('money')
end
self.setBankBalance = function(m)
if m >= 0 then
self.player.setBankBalance(m)
else
print('es_extended: ' .. self.name .. ' (' .. self.identifier .. ') attempted exploiting! (reason: player tried setting -1 bank balance)')
end
end
self.getBank = function()
return self.player.get('bank')
end
self.getCoords = function()
return self.player.get('coords')
end
self.setCoords = function(x, y, z)
self.player.coords = {x = x, y = y, z = z}
end
self.kick = function(r)
self.player.kick(r)
end
self.addMoney = function(m)
if m >= 0 then
self.player.addMoney(m)
else
print('es_extended: ' .. self.name .. ' (' .. self.identifier .. ') attempted exploiting! (reason: player tried adding -1 cash balance)')
end
end
self.removeMoney = function(m)
if m >= 0 then
self.player.removeMoney(m)
else
print('es_extended: ' .. self.name .. ' (' .. self.identifier .. ') attempted exploiting! (reason: player tried removing -1 cash balance)')
end
end
self.addBank = function(m)
if m >= 0 then
self.player.addBank(m)
else
print('es_extended: ' .. self.name .. ' (' .. self.identifier .. ') attempted exploiting! (reason: player tried adding -1 bank balance)')
end
end
self.removeBank = function(m)
if m >= 0 then
self.player.removeBank(m)
else
print('es_extended: ' .. self.name .. ' (' .. self.identifier .. ') attempted exploiting! (reason: player tried removing -1 bank balance)')
end
end
self.displayMoney = function(m)
self.player.displayMoney(m)
end
self.displayBank = function(m)
self.player.displayBank(m)
end
self.setSessionVar = function(key, value)
self.player.setSessionVar(key, value)
end
self.getSessionVar = function(k)
return self.player.getSessionVar(k)
end
self.getPermissions = function()
return self.player.getPermissions()
end
self.setPermissions = function(p)
self.player.setPermissions(p)
end
self.getIdentifier = function()
return self.player.getIdentifier()
end
self.getGroup = function()
return self.player.getGroup()
end
self.set = function(k, v)
self.player.set(k, v)
end
self.get = function(k)
return self.player.get(k)
end
self.getName = function()
return self.name
end
self.getPlayer = function()
return self.player
end
self.getLastPosition = function()
return self.lastPosition
end
self.getAccounts = function()
self.getMissingAccounts = function(cb)
MySQL.Async.fetchAll('SELECT * FROM `user_accounts` WHERE `identifier` = @identifier', {
['@identifier'] = self.getIdentifier()
}, function(result)
local accounts = {}
local missingAccounts = {}
for i=1, #Config.Accounts, 1 do
if Config.Accounts[i] == 'bank' then
table.insert(accounts, {
name = 'bank',
money = self.get('bank'),
label = Config.AccountLabels['bank']
})
else
for j=1, #self.accounts, 1 do
if self.accounts[j].name == Config.Accounts[i] then
table.insert(accounts, self.accounts[j])
end
end
end
end
return accounts
end
self.getAccount = function(a)
if a == 'bank' then
return {
name = 'bank',
money = self.get('bank'),
label = Config.AccountLabels['bank']
}
end
for i=1, #self.accounts, 1 do
if self.accounts[i].name == a then
return self.accounts[i]
end
end
end
self.getInventory = function()
return self.inventory
end
self.getJob = function()
return self.job
end
self.getLoadout = function()
return self.loadout
end
self.getName = function()
return self.name
end
self.getLastPosition = function()
return self.lastPosition
end
self.getMissingAccounts = function(cb)
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
if Config.Accounts[i] == result[j].name then
found = true
end
end
if not found then
table.insert(missingAccounts, Config.Accounts[i])
end
end
end
cb(missingAccounts)
end
)
end
self.createAccounts = function(missingAccounts, cb)
for i=1, #missingAccounts, 1 do
MySQL.Async.execute(
'INSERT INTO `user_accounts` (identifier, name) VALUES (@identifier, @name)',
{
['@identifier'] = self.getIdentifier(),
['@name'] = missingAccounts[i]
},
function(rowsChanged)
if cb ~= nil then
cb()
end
end
)
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)')
return
end
local account = self.getAccount(a)
local prevMoney = account.money
local newMoney = m
account.money = newMoney
if a == '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)')
return
end
local account = self.getAccount(a)
local newMoney = account.money + m
account.money = newMoney
if a == 'bank' then
self.set('bank', newMoney)
end
TriggerClientEvent('esx:setAccountMoney', self.source, account)
end
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)')
return
end
local account = self.getAccount(a)
local newMoney = account.money - m
account.money = newMoney
if a == 'bank' then
self.set('bank', newMoney)
end
TriggerClientEvent('esx:setAccountMoney', self.source, account)
end
self.getInventoryItem = function(name)
for i=1, #self.inventory, 1 do
if self.inventory[i].name == name then
return self.inventory[i]
end
end
end
self.addInventoryItem = function(name, count)
local item = self.getInventoryItem(name)
local newCount = item.count + count
item.count = newCount
TriggerEvent("esx:onAddInventoryItem", self.source, item, count)
TriggerClientEvent("esx:addInventoryItem", self.source, item, count)
end
self.removeInventoryItem = function(name, count)
local item = self.getInventoryItem(name)
local newCount = item.count - count
item.count = newCount
TriggerEvent("esx:onRemoveInventoryItem", self.source, item, count)
TriggerClientEvent("esx:removeInventoryItem", self.source, item, count)
end
self.setInventoryItem = function(name, count)
local item = self.getInventoryItem(name)
local oldCount = item.count
item.count = count
if oldCount > item.count then
TriggerEvent("esx:onRemoveInventoryItem", self.source, item, oldCount - item.count )
TriggerClientEvent("esx:removeInventoryItem", self.source, item, oldCount - item.count )
else
TriggerEvent("esx:onAddInventoryItem", self.source, item, item.count - oldCount)
TriggerClientEvent("esx:addInventoryItem", self.source, item, item.count - oldCount)
end
end
self.setJob = function(name, grade)
local lastJob = json.decode(json.encode(self.job))
MySQL.Async.fetchAll(
'SELECT * FROM `jobs` WHERE `name` = @name',
{
['@name'] = name
},
function(result)
self.job['id'] = result[1].id
self.job['name'] = result[1].name
self.job['label'] = result[1].label
MySQL.Async.fetchAll(
'SELECT * FROM `job_grades` WHERE `job_name` = @job_name AND `grade` = @grade',
{
['@job_name'] = name,
['@grade'] = grade
},
function(result)
self.job['grade'] = grade
self.job['grade_name'] = result[1].name
self.job['grade_label'] = result[1].label
self.job['grade_salary'] = result[1].salary
self.job['skin_male'] = nil
self.job['skin_female'] = nil
if result[1].skin_male ~= nil then
self.job['skin_male'] = json.decode(result[1].skin_male)
end
if result[1].skin_female ~= nil then
self.job['skin_female'] = json.decode(result[1].skin_female)
end
TriggerEvent("esx:setJob", self.source, self.job, lastJob)
TriggerClientEvent("esx:setJob", self.source, self.job)
end
)
end
)
end
self.addWeapon = function(weaponName, ammo)
local weaponLabel = weaponName
for i=1, #Config.Weapons, 1 do
if Config.Weapons[i].name == weaponName then
weaponLabel = Config.Weapons[i].label
break
end
end
local foundWeapon = false
for i=1, #self.loadout, 1 do
if self.loadout[i].name == weaponName then
foundWeapon = true
end
end
if not foundWeapon then
table.insert(self.loadout, {
name = weaponName,
ammo = ammo,
label = weaponLabel
})
end
TriggerClientEvent('esx:addWeapon', self.source, weaponName, ammo)
TriggerClientEvent('esx:addInventoryItem', self.source, {label = weaponLabel}, 1)
end
self.removeWeapon = function(weaponName, ammo)
local weaponLabel = weaponName
for i=1, #Config.Weapons, 1 do
if Config.Weapons[i].name == weaponName then
weaponLabel = Config.Weapons[i].label
break
end
end
local foundWeapon = false
for i=1, #self.loadout, 1 do
if self.loadout[i].name == weaponName then
table.remove(self.loadout, i)
break
end
end
TriggerClientEvent('esx:removeWeapon', self.source, weaponName, ammo)
TriggerClientEvent('esx:removeInventoryItem', self.source, {label = weaponLabel}, 1)
end
return self
for i=1, #Config.Accounts, 1 do
if Config.Accounts[i] ~= 'bank' then
local found = false
for j=1, #result, 1 do
if Config.Accounts[i] == result[j].name then
found = true
end
end
if not found then
table.insert(missingAccounts, Config.Accounts[i])
end
end
end
cb(missingAccounts)
end)
end
self.createAccounts = function(missingAccounts, cb)
for i=1, #missingAccounts, 1 do
MySQL.Async.execute('INSERT INTO `user_accounts` (identifier, name) VALUES (@identifier, @name)',
{
['@identifier'] = self.getIdentifier(),
['@name'] = missingAccounts[i]
}, function(rowsChanged)
if cb ~= nil then
cb()
end
end)
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)')
return
end
local account = self.getAccount(a)
local prevMoney = account.money
local newMoney = m
account.money = newMoney
if a == '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)')
return
end
local account = self.getAccount(a)
local newMoney = account.money + m
account.money = newMoney
if a == 'bank' then
self.set('bank', newMoney)
end
TriggerClientEvent('esx:setAccountMoney', self.source, account)
end
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)')
return
end
local account = self.getAccount(a)
local newMoney = account.money - m
account.money = newMoney
if a == 'bank' then
self.set('bank', newMoney)
end
TriggerClientEvent('esx:setAccountMoney', self.source, account)
end
self.getInventoryItem = function(name)
for i=1, #self.inventory, 1 do
if self.inventory[i].name == name then
return self.inventory[i]
end
end
end
self.addInventoryItem = function(name, count)
local item = self.getInventoryItem(name)
local newCount = item.count + count
item.count = newCount
TriggerEvent("esx:onAddInventoryItem", self.source, item, count)
TriggerClientEvent("esx:addInventoryItem", self.source, item, count)
end
self.removeInventoryItem = function(name, count)
local item = self.getInventoryItem(name)
local newCount = item.count - count
item.count = newCount
TriggerEvent("esx:onRemoveInventoryItem", self.source, item, count)
TriggerClientEvent("esx:removeInventoryItem", self.source, item, count)
end
self.setInventoryItem = function(name, count)
local item = self.getInventoryItem(name)
local oldCount = item.count
item.count = count
if oldCount > item.count then
TriggerEvent("esx:onRemoveInventoryItem", self.source, item, oldCount - item.count)
TriggerClientEvent("esx:removeInventoryItem", self.source, item, oldCount - item.count)
else
TriggerEvent("esx:onAddInventoryItem", self.source, item, item.count - oldCount)
TriggerClientEvent("esx:addInventoryItem", self.source, item, item.count - oldCount)
end
end
self.setJob = function(name, grade)
local lastJob = json.decode(json.encode(self.job))
MySQL.Async.fetchAll('SELECT * FROM `jobs` WHERE `name` = @name', {
['@name'] = name
}, function(result)
self.job['id'] = result[1].id
self.job['name'] = result[1].name
self.job['label'] = result[1].label
MySQL.Async.fetchAll('SELECT * FROM `job_grades` WHERE `job_name` = @job_name AND `grade` = @grade', {
['@job_name'] = name,
['@grade'] = grade
}, function(result)
self.job['grade'] = grade
self.job['grade_name'] = result[1].name
self.job['grade_label'] = result[1].label
self.job['grade_salary'] = result[1].salary
self.job['skin_male'] = nil
self.job['skin_female'] = nil
if result[1].skin_male ~= nil then
self.job['skin_male'] = json.decode(result[1].skin_male)
end
if result[1].skin_female ~= nil then
self.job['skin_female'] = json.decode(result[1].skin_female)
end
TriggerEvent("esx:setJob", self.source, self.job, lastJob)
TriggerClientEvent("esx:setJob", self.source, self.job)
end)
end)
end
self.addWeapon = function(weaponName, ammo)
local weaponLabel = weaponName
for i=1, #Config.Weapons, 1 do
if Config.Weapons[i].name == weaponName then
weaponLabel = Config.Weapons[i].label
break
end
end
local foundWeapon = false
for i=1, #self.loadout, 1 do
if self.loadout[i].name == weaponName then
foundWeapon = true
end
end
if not foundWeapon then
table.insert(self.loadout, {
name = weaponName,
ammo = ammo,
label = weaponLabel
})
end
TriggerClientEvent('esx:addWeapon', self.source, weaponName, ammo)
TriggerClientEvent('esx:addInventoryItem', self.source, {label = weaponLabel}, 1)
end
self.removeWeapon = function(weaponName, ammo)
local weaponLabel = weaponName
for i=1, #Config.Weapons, 1 do
if Config.Weapons[i].name == weaponName then
weaponLabel = Config.Weapons[i].label
break
end
end
local foundWeapon = false
for i=1, #self.loadout, 1 do
if self.loadout[i].name == weaponName then
table.remove(self.loadout, i)
break
end
end
TriggerClientEvent('esx:removeWeapon', self.source, weaponName, ammo)
TriggerClientEvent('esx:removeInventoryItem', self.source, {label = weaponLabel}, 1)
end
return self
end
+52 -59
View File
@@ -13,7 +13,7 @@ TriggerEvent('es:addGroupCommand', 'tp', 'admin', function(source, args, user)
TriggerClientEvent('chatMessage', source, "SYSTEM", {255, 0, 0}, "Invalid coordinates!")
end
end, function(source, args, user)
TriggerClientEvent('chat:addMessage', source, { args = { '^1SYSTEM', 'Insufficient Permissions.' } })
TriggerClientEvent('chat:addMessage', source, { args = { '^1SYSTEM', 'Insufficient Permissions.' } })
end, {help = "Teleport to coordinates", params = {{name = "x", help = "X coords"}, {name = "y", help = "Y coords"}, {name = "z", help = "Z coords"}}})
TriggerEvent('es:addGroupCommand', 'setjob', 'jobmaster', function(source, args, user)
@@ -28,37 +28,37 @@ TriggerEvent('es:addGroupCommand', 'setjob', 'jobmaster', function(source, args,
TriggerClientEvent('chatMessage', source, "SYSTEM", {255, 0, 0}, "Invalid usage.")
end
end, function(source, args, user)
TriggerClientEvent('chat:addMessage', source, { args = { '^1SYSTEM', 'Insufficient Permissions.' } })
TriggerClientEvent('chat:addMessage', source, { args = { '^1SYSTEM', 'Insufficient Permissions.' } })
end, {help = _U('setjob'), params = {{name = "id", help = _U('id_param')}, {name = "job", help = _U('setjob_param2')}, {name = "grade_id", help = _U('setjob_param3')}}})
TriggerEvent('es:addGroupCommand', 'loadipl', 'admin', function(source, args, user)
TriggerClientEvent('esx:loadIPL', -1, args[1])
TriggerClientEvent('esx:loadIPL', -1, args[1])
end, function(source, args, user)
TriggerClientEvent('chat:addMessage', source, { args = { '^1SYSTEM', 'Insufficient Permissions.' } })
TriggerClientEvent('chat:addMessage', source, { args = { '^1SYSTEM', 'Insufficient Permissions.' } })
end, {help = _U('load_ipl')})
TriggerEvent('es:addGroupCommand', 'unloadipl', 'admin', function(source, args, user)
TriggerClientEvent('esx:unloadIPL', -1, args[1])
TriggerClientEvent('esx:unloadIPL', -1, args[1])
end, function(source, args, user)
TriggerClientEvent('chat:addMessage', source, { args = { '^1SYSTEM', 'Insufficient Permissions.' } })
TriggerClientEvent('chat:addMessage', source, { args = { '^1SYSTEM', 'Insufficient Permissions.' } })
end, {help = _U('unload_ipl')})
TriggerEvent('es:addGroupCommand', 'playanim', 'admin', function(source, args, user)
TriggerClientEvent('esx:playAnim', -1, args[1], args[3])
TriggerClientEvent('esx:playAnim', -1, args[1], args[3])
end, function(source, args, user)
TriggerClientEvent('chat:addMessage', source, { args = { '^1SYSTEM', 'Insufficient Permissions.' } })
TriggerClientEvent('chat:addMessage', source, { args = { '^1SYSTEM', 'Insufficient Permissions.' } })
end, {help = _U('play_anim')})
TriggerEvent('es:addGroupCommand', 'playemote', 'admin', function(source, args, user)
TriggerClientEvent('esx:playEmote', -1, args[1])
TriggerClientEvent('esx:playEmote', -1, args[1])
end, function(source, args, user)
TriggerClientEvent('chat:addMessage', source, { args = { '^1SYSTEM', 'Insufficient Permissions.' } })
TriggerClientEvent('chat:addMessage', source, { args = { '^1SYSTEM', 'Insufficient Permissions.' } })
end, {help = _U('play_emote')})
TriggerEvent('es:addGroupCommand', 'car', 'admin', function(source, args, user)
TriggerClientEvent('esx:spawnVehicle', source, args[1])
TriggerClientEvent('esx:spawnVehicle', source, args[1])
end, function(source, args, user)
TriggerClientEvent('chat:addMessage', source, { args = { '^1SYSTEM', 'Insufficient Permissions.' } })
TriggerClientEvent('chat:addMessage', source, { args = { '^1SYSTEM', 'Insufficient Permissions.' } })
end, {help = _U('spawn_car'), params = {{name = "car", help = _U('spawn_car_param')}}})
TriggerEvent('es:addGroupCommand', 'cardel', 'admin', function(source, args, user)
@@ -68,26 +68,25 @@ end, function(source, args, user)
end, {help = _U('delete_vehicle')})
TriggerEvent('es:addGroupCommand', 'dv', 'admin', function(source, args, user)
TriggerClientEvent('esx:deleteVehicle', source)
TriggerClientEvent('esx:deleteVehicle', source)
end, function(source, args, user)
TriggerClientEvent('chat:addMessage', source, { args = { '^1SYSTEM', 'Insufficient Permissions.' } })
TriggerClientEvent('chat:addMessage', source, { args = { '^1SYSTEM', 'Insufficient Permissions.' } })
end, {help = _U('delete_vehicle')})
TriggerEvent('es:addGroupCommand', 'spawnped', 'admin', function(source, args, user)
TriggerClientEvent('esx:spawnPed', source, args[1])
TriggerClientEvent('esx:spawnPed', source, args[1])
end, function(source, args, user)
TriggerClientEvent('chat:addMessage', source, { args = { '^1SYSTEM', 'Insufficient Permissions.' } })
TriggerClientEvent('chat:addMessage', source, { args = { '^1SYSTEM', 'Insufficient Permissions.' } })
end, {help = _U('spawn_ped'), params = {{name = "name", help = _U('spawn_ped_param')}}})
TriggerEvent('es:addGroupCommand', 'spawnobject', 'admin', function(source, args, user)
TriggerClientEvent('esx:spawnObject', source, args[1])
TriggerClientEvent('esx:spawnObject', source, args[1])
end, function(source, args, user)
TriggerClientEvent('chat:addMessage', source, { args = { '^1SYSTEM', 'Insufficient Permissions.' } })
TriggerClientEvent('chat:addMessage', source, { args = { '^1SYSTEM', 'Insufficient Permissions.' } })
end, {help = _U('spawn_object'), params = {{name = "name"}}})
TriggerEvent('es:addGroupCommand', 'setmoney', 'admin', function(source, args, user)
local _source = source
local target = tonumber(args[1])
local money_type = args[2]
local money_amount = tonumber(args[3])
@@ -113,63 +112,57 @@ TriggerEvent('es:addGroupCommand', 'setmoney', 'admin', function(source, args, u
print('es_extended: ' .. GetPlayerName(source) .. ' just set $' .. money_amount .. ' (' .. money_type .. ') to ' .. xPlayer.name)
if xPlayer.source ~= _source then
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('money_set', money_amount, money_type))
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('money_set', money_amount, money_type))
end
end, function(source, args, user)
TriggerClientEvent('chat:addMessage', source, { args = { '^1SYSTEM', 'Insufficient Permissions.' } })
end, {help = _U('setmoney'), params = {{name = "id", help = _U('id_param')}, {name = "money type", help = _U('money_type')}, {name = "amount", help = _U('money_amount')}}})
TriggerEvent('es:addGroupCommand', 'giveaccountmoney', 'admin', function(source, args, user)
local _source = source
local xPlayer = ESX.GetPlayerFromId(args[1])
local account = args[2]
local amount = tonumber(args[3])
local _source = source
local xPlayer = ESX.GetPlayerFromId(args[1])
local account = args[2]
local amount = tonumber(args[3])
if amount ~= nil then
if xPlayer.getAccount(account) ~= nil then
xPlayer.addAccountMoney(account, amount)
else
TriggerClientEvent('esx:showNotification', _source, _U('invalid_account'))
end
else
TriggerClientEvent('esx:showNotification', _source, _U('amount_invalid'))
end
if amount ~= nil then
if xPlayer.getAccount(account) ~= nil then
xPlayer.addAccountMoney(account, amount)
else
TriggerClientEvent('esx:showNotification', _source, _U('invalid_account'))
end
else
TriggerClientEvent('esx:showNotification', _source, _U('amount_invalid'))
end
end, function(source, args, user)
TriggerClientEvent('chat:addMessage', source, { args = { '^1SYSTEM', 'Insufficient Permissions.' } })
TriggerClientEvent('chat:addMessage', source, { args = { '^1SYSTEM', 'Insufficient Permissions.' } })
end, {help = _U('giveaccountmoney'), params = {{name = "id", help = _U('id_param')}, {name = "account", help = _U('account')}, {name = "amount", help = _U('money_amount')}}})
TriggerEvent('es:addGroupCommand', 'giveitem', 'admin', function(source, args, user)
local _source = source
local xPlayer = ESX.GetPlayerFromId(args[1])
local item = args[2]
local count = (args[3] == nil and 1 or tonumber(args[3]))
local _source = source
local xPlayer = ESX.GetPlayerFromId(args[1])
local item = args[2]
local count = (args[3] == nil and 1 or tonumber(args[3]))
if count ~= nil then
if xPlayer.getInventoryItem(item) ~= nil then
xPlayer.addInventoryItem(item, count)
else
TriggerClientEvent('esx:showNotification', _source, _U('invalid_item'))
end
else
TriggerClientEvent('esx:showNotification', _source, _U('invalid_amount'))
end
if count ~= nil then
if xPlayer.getInventoryItem(item) ~= nil then
xPlayer.addInventoryItem(item, count)
else
TriggerClientEvent('esx:showNotification', _source, _U('invalid_item'))
end
else
TriggerClientEvent('esx:showNotification', _source, _U('invalid_amount'))
end
end, function(source, args, user)
TriggerClientEvent('chat:addMessage', source, { args = { '^1SYSTEM', 'Insufficient Permissions.' } })
TriggerClientEvent('chat:addMessage', source, { args = { '^1SYSTEM', 'Insufficient Permissions.' } })
end, {help = _U('giveitem'), params = {{name = "id", help = _U('id_param')}, {name = "item", help = _U('item')}, {name = "amount", help = _U('amount')}}})
TriggerEvent('es:addGroupCommand', 'giveweapon', 'admin', function(source, args, user)
local xPlayer = ESX.GetPlayerFromId(args[1])
local weaponName = string.upper(args[2])
local xPlayer = ESX.GetPlayerFromId(args[1])
local weaponName = string.upper(args[2])
xPlayer.addWeapon(weaponName, tonumber(args[3]))
xPlayer.addWeapon(weaponName, tonumber(args[3]))
end, function(source, args, user)
TriggerClientEvent('chat:addMessage', source, { args = { '^1SYSTEM', 'Insufficient Permissions.' } })
TriggerClientEvent('chat:addMessage', source, { args = { '^1SYSTEM', 'Insufficient Permissions.' } })
end, {help = _U('giveweapon'), params = {{name = "id", help = _U('id_param')}, {name = "weapon", help = _U('weapon')}, {name = "ammo", help = _U('amountammo')}}})
TriggerEvent('es:addGroupCommand', 'disc', 'admin', function(source, args, user)
@@ -206,4 +199,4 @@ TriggerEvent('es:addGroupCommand', 'clearall', 'admin', function(source, args, u
TriggerClientEvent('chat:clear', -1)
end, function(source, args, user)
TriggerClientEvent('chat:addMessage', source, { args = { '^1SYSTEM', 'Insufficient Permissions.' } })
end, {help = _U('chat_clear_all')})
end, {help = _U('chat_clear_all')})
+32 -45
View File
@@ -10,70 +10,57 @@ ESX.Pickups = {}
ESX.PickupId = 0
AddEventHandler('esx:getSharedObject', function(cb)
cb(ESX)
cb(ESX)
end)
function getSharedObject()
return ESX
return ESX
end
AddEventHandler('onMySQLReady', function()
MySQL.Async.fetchAll(
'SELECT * FROM items',
{},
function(result)
for i=1, #result, 1 do
ESX.Items[result[i].name] = {
label = result[i].label,
limit = result[i].limit,
rare = (result[i].rare == 1 and true or false),
canRemove = (result[i].can_remove == 1 and true or false),
}
end
end
)
MySQL.Async.fetchAll('SELECT * FROM items', {}, function(result)
for i=1, #result, 1 do
ESX.Items[result[i].name] = {
label = result[i].label,
limit = result[i].limit,
rare = (result[i].rare == 1 and true or false),
canRemove = (result[i].can_remove == 1 and true or false),
}
end
end)
end)
AddEventHandler('esx:playerLoaded', function(source)
local xPlayer = ESX.GetPlayerFromId(source)
local accounts = {}
local items = {}
local xPlayerAccounts = xPlayer.getAccounts()
local xPlayerItems = xPlayer.getInventory()
local xPlayer = ESX.GetPlayerFromId(source)
local accounts = {}
local items = {}
local xPlayerAccounts = xPlayer.getAccounts()
local xPlayerItems = xPlayer.getInventory()
for i=1, #xPlayerAccounts, 1 do
accounts[xPlayerAccounts[i].name] = xPlayerAccounts[i].money
end
for i=1, #xPlayerAccounts, 1 do
accounts[xPlayerAccounts[i].name] = xPlayerAccounts[i].money
end
for i=1, #xPlayerItems, 1 do
items[xPlayerItems[i].name] = xPlayerItems[i].count
end
ESX.LastPlayerData[source] = {
accounts = accounts,
items = items
}
for i=1, #xPlayerItems, 1 do
items[xPlayerItems[i].name] = xPlayerItems[i].count
end
ESX.LastPlayerData[source] = {
accounts = accounts,
items = items
}
end)
RegisterServerEvent('esx:clientLog')
AddEventHandler('esx:clientLog', function(msg)
RconPrint(msg .. "\n")
RconPrint(msg .. "\n")
end)
RegisterServerEvent('esx:triggerServerCallback')
AddEventHandler('esx:triggerServerCallback', function(name, requestId, ...)
local _source = source
local _source = source
ESX.TriggerServerCallback(name, requestID, _source, function(...)
TriggerClientEvent('esx:serverCallback', _source, requestId, ...)
end, ...)
ESX.TriggerServerCallback(name, requestID, _source, function(...)
TriggerClientEvent('esx:serverCallback', _source, requestId, ...)
end, ...)
end)
+122 -182
View File
@@ -1,226 +1,171 @@
local Charset = {}
for i = 48, 57 do table.insert(Charset, string.char(i)) end
for i = 65, 90 do table.insert(Charset, string.char(i)) end
for i = 97, 122 do table.insert(Charset, string.char(i)) end
ESX.Trace = function(str)
if Config.EnableDebug then
print('ESX> ' .. str)
end
end
ESX.GetConfig = function()
return Config
end
ESX.GetRandomString = function(length)
math.randomseed(os.time())
if length > 0 then
return ESX.GetRandomString(length - 1) .. Charset[math.random(1, #Charset)]
else
return ''
end
if Config.EnableDebug then
print('ESX> ' .. str)
end
end
ESX.SetTimeout = function(msec, cb)
local id = ESX.TimeoutCount + 1
local id = ESX.TimeoutCount + 1
SetTimeout(msec, function()
if ESX.CancelledTimeouts[id] then
ESX.CancelledTimeouts[id] = nil
else
cb()
end
end)
SetTimeout(msec, function()
if ESX.CancelledTimeouts[id] then
ESX.CancelledTimeouts[id] = nil
else
cb()
end
end)
ESX.TimeoutCount = id
return id
ESX.TimeoutCount = id
return id
end
ESX.ClearTimeout = function(id)
ESX.CancelledTimeouts[id] = true
ESX.CancelledTimeouts[id] = true
end
ESX.RegisterServerCallback = function(name, cb)
ESX.ServerCallbacks[name] = cb
ESX.ServerCallbacks[name] = cb
end
ESX.TriggerServerCallback = function(name, requestId, source, cb, ...)
if ESX.ServerCallbacks[name] ~= nil then
ESX.ServerCallbacks[name](source, cb, ...)
else
print('TriggerServerCallback => [' .. name .. '] does not exist')
end
if ESX.ServerCallbacks[name] ~= nil then
ESX.ServerCallbacks[name](source, cb, ...)
else
print('es_extended: TriggerServerCallback => [' .. name .. '] does not exist')
end
end
ESX.SavePlayer = function(xPlayer, cb)
local asyncTasks = {}
xPlayer.lastPosition = xPlayer.get('coords')
local asyncTasks = {}
xPlayer.lastPosition = xPlayer.get('coords')
-- User accounts
for i=1, #xPlayer.accounts, 1 do
-- User accounts
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)
MySQL.Async.execute('UPDATE user_accounts SET `money` = @money WHERE identifier = @identifier AND name = @name',
{
['@money'] = xPlayer.accounts[i].money,
['@identifier'] = xPlayer.identifier,
['@name'] = xPlayer.accounts[i].name
}, function(rowsChanged)
cb()
end)
end)
table.insert(asyncTasks, function(cb)
ESX.LastPlayerData[xPlayer.source].accounts[xPlayer.accounts[i].name] = xPlayer.accounts[i].money
MySQL.Async.execute(
'UPDATE user_accounts SET `money` = @money WHERE identifier = @identifier AND name = @name',
{
['@money'] = xPlayer.accounts[i].money,
['@identifier'] = xPlayer.identifier,
['@name'] = xPlayer.accounts[i].name
},
function(rowsChanged)
cb()
end
)
end
end)
end
ESX.LastPlayerData[xPlayer.source].accounts[xPlayer.accounts[i].name] = xPlayer.accounts[i].money
-- Inventory items
for i=1, #xPlayer.inventory, 1 do
end
if ESX.LastPlayerData[xPlayer.source].items[xPlayer.inventory[i].name] ~= xPlayer.inventory[i].count then
end
table.insert(asyncTasks, function(cb)
MySQL.Async.execute('UPDATE user_inventory SET `count` = @count WHERE identifier = @identifier AND item = @item',
{
['@count'] = xPlayer.inventory[i].count,
['@identifier'] = xPlayer.identifier,
['@item'] = xPlayer.inventory[i].name
}, function(rowsChanged)
cb()
end)
end)
-- Inventory items
for i=1, #xPlayer.inventory, 1 do
ESX.LastPlayerData[xPlayer.source].items[xPlayer.inventory[i].name] = xPlayer.inventory[i].count
if ESX.LastPlayerData[xPlayer.source].items[xPlayer.inventory[i].name] ~= xPlayer.inventory[i].count then
end
table.insert(asyncTasks, function(cb)
end
MySQL.Async.execute(
'UPDATE user_inventory SET `count` = @count WHERE identifier = @identifier AND item = @item',
{
['@count'] = xPlayer.inventory[i].count,
['@identifier'] = xPlayer.identifier,
['@item'] = xPlayer.inventory[i].name
},
function(rowsChanged)
cb()
end
)
-- Job, loadout and position
table.insert(asyncTasks, function(cb)
MySQL.Async.execute('UPDATE users SET `job` = @job, `job_grade` = @job_grade, `loadout` = @loadout, `position` = @position WHERE identifier = @identifier',
{
['@job'] = xPlayer.job.name,
['@job_grade'] = xPlayer.job.grade,
['@loadout'] = json.encode(xPlayer.loadout),
['@position'] = json.encode(xPlayer.lastPosition),
['@identifier'] = xPlayer.identifier
}, function(rowsChanged)
cb()
end)
end)
end)
Async.parallel(asyncTasks, function(results)
RconPrint('[SAVED] ' .. xPlayer.name .. "\n")
ESX.LastPlayerData[xPlayer.source].items[xPlayer.inventory[i].name] = xPlayer.inventory[i].count
end
end
-- Job, loadout and position
table.insert(asyncTasks, function(cb)
MySQL.Async.execute(
'UPDATE users SET `job` = @job, `job_grade` = @job_grade, `loadout` = @loadout, `position` = @position WHERE identifier = @identifier',
{
['@job'] = xPlayer.job.name,
['@job_grade'] = xPlayer.job.grade,
['@loadout'] = json.encode(xPlayer.loadout),
['@position'] = json.encode(xPlayer.lastPosition),
['@identifier'] = xPlayer.identifier
},
function(rowsChanged)
cb()
end
)
end)
Async.parallel(asyncTasks, function(results)
RconPrint('[SAVED] ' .. xPlayer.name .. "\n")
if cb ~= nil then
cb()
end
end)
if cb ~= nil then
cb()
end
end)
end
ESX.SavePlayers = function(cb)
local asyncTasks = {}
local xPlayers = ESX.GetPlayers()
local asyncTasks = {}
local xPlayers = ESX.GetPlayers()
for i=1, #xPlayers, 1 do
table.insert(asyncTasks, function(cb)
local xPlayer = ESX.GetPlayerFromId(xPlayers[i])
ESX.SavePlayer(xPlayer, cb)
end)
end
for i=1, #xPlayers, 1 do
table.insert(asyncTasks, function(cb)
local xPlayer = ESX.GetPlayerFromId(xPlayers[i])
ESX.SavePlayer(xPlayer, cb)
end)
end
Async.parallelLimit(asyncTasks, 8, function(results)
RconPrint('[SAVED] All players' .. "\n")
if cb ~= nil then
cb()
end
end)
Async.parallelLimit(asyncTasks, 8, function(results)
RconPrint('[SAVED] All players' .. "\n")
if cb ~= nil then
cb()
end
end)
end
ESX.StartDBSync = function()
function saveData()
ESX.SavePlayers()
SetTimeout(10 * 60 * 1000, saveData)
end
function saveData()
ESX.SavePlayers()
SetTimeout(10 * 60 * 1000, saveData)
end
SetTimeout(10 * 60 * 1000, saveData)
SetTimeout(10 * 60 * 1000, saveData)
end
ESX.GetPlayers = function()
local sources = {}
local sources = {}
for k,v in pairs(ESX.Players) do
table.insert(sources, k)
end
for k,v in pairs(ESX.Players) do
table.insert(sources, k)
end
return sources
return sources
end
ESX.GetPlayerFromId = function(source)
return ESX.Players[tonumber(source)]
return ESX.Players[tonumber(source)]
end
ESX.GetPlayerFromIdentifier = function(identifier)
for k,v in pairs(ESX.Players) do
if v.identifier == identifier then
return v
end
end
for k,v in pairs(ESX.Players) do
if v.identifier == identifier then
return v
end
end
end
ESX.RegisterUsableItem = function(item, cb)
ESX.UsableItemsCallbacks[item] = cb
ESX.UsableItemsCallbacks[item] = cb
end
ESX.UseItem = function(source, item)
ESX.UsableItemsCallbacks[item](source)
ESX.UsableItemsCallbacks[item](source)
end
ESX.GetItemLabel = function(item)
@@ -230,34 +175,29 @@ ESX.GetItemLabel = function(item)
end
ESX.GetWeaponList = function()
return Config.Weapons
return Config.Weapons
end
ESX.GetWeaponLabel = function(name)
name = string.upper(name)
local weapons = ESX.GetWeaponList()
name = string.upper(name)
local weapons = ESX.GetWeaponList()
for i=1, #weapons, 1 do
if weapons[i].name == name then
return weapons[i].label
end
end
for i=1, #weapons, 1 do
if weapons[i].name == name then
return weapons[i].label
end
end
end
ESX.CreatePickup = function(type, name, count, label, player)
local pickupId = (ESX.PickupId == 65635 and 0 or ESX.PickupId + 1)
local pickupId = (ESX.PickupId == 65635 and 0 or ESX.PickupId + 1)
ESX.Pickups[pickupId] = {
type = type,
name = name,
count = count
}
ESX.Pickups[pickupId] = {
type = type,
name = name,
count = count
}
TriggerClientEvent('esx:pickup', -1, pickupId, label, player)
ESX.PickupId = pickupId
end
TriggerClientEvent('esx:pickup', -1, pickupId, label, player)
ESX.PickupId = pickupId
end
+401 -469
View File
@@ -1,298 +1,252 @@
AddEventHandler('es:playerLoaded', function(source, _player)
local _source = source
local tasks = {}
local userData = {
accounts = {},
inventory = {},
job = {},
loadout = {},
playerName = GetPlayerName(_source),
lastPosition = nil
}
TriggerEvent('es:getPlayerFromId', _source, function(player)
-- Update user name in DB
table.insert(tasks, function(cb)
MySQL.Async.execute('UPDATE `users` SET `name` = @name WHERE `identifier` = @identifier',
{
['@identifier'] = player.getIdentifier(),
['@name'] = userData.playerName
}, function(rowsChanged)
cb()
end)
end)
-- Get accounts
table.insert(tasks, function(cb)
MySQL.Async.fetchAll('SELECT * FROM `user_accounts` WHERE `identifier` = @identifier', {
['@identifier'] = player.getIdentifier()
}, function(accounts)
for i=1, #Config.Accounts, 1 do
for j=1, #accounts, 1 do
if accounts[j].name == Config.Accounts[i] then
table.insert(userData.accounts, {
name = accounts[j].name,
money = accounts[j].money,
label = Config.AccountLabels[accounts[j].name]
})
end
end
end
cb()
end)
end)
-- Get inventory
table.insert(tasks, function(cb)
MySQL.Async.fetchAll('SELECT * FROM `user_inventory` WHERE `identifier` = @identifier', {
['@identifier'] = player.getIdentifier()
}, function(inventory)
local tasks2 = {}
for i=1, #inventory, 1 do
table.insert(userData.inventory, {
name = inventory[i].item,
count = inventory[i].count,
label = ESX.Items[inventory[i].item].label,
limit = ESX.Items[inventory[i].item].limit,
usable = ESX.UsableItemsCallbacks[inventory[i].item] ~= nil,
rare = ESX.Items[inventory[i].item].rare,
canRemove = ESX.Items[inventory[i].item].canRemove
})
end
for k,v in pairs(ESX.Items) do
local found = false
for j=1, #userData.inventory, 1 do
if userData.inventory[j].name == k then
found = true
break
end
end
if not found then
table.insert(userData.inventory, {
name = k,
count = 0,
label = ESX.Items[k].label,
limit = ESX.Items[k].limit,
usable = ESX.UsableItemsCallbacks[k] ~= nil,
rare = ESX.Items[k].rare,
canRemove = ESX.Items[k].canRemove
})
local scope = function(item, identifier)
table.insert(tasks2, function(cb2)
MySQL.Async.execute('INSERT INTO user_inventory (identifier, item, count) VALUES (@identifier, @item, @count)',
{
['@identifier'] = identifier,
['@item'] = item,
['@count'] = 0
}, function(rowsChanged)
cb2()
end)
end)
end
scope(k, player.getIdentifier())
end
end
Async.parallelLimit(tasks2, 5, function(results) end)
table.sort(userData.inventory, function(a,b)
return a.label < b.label
end)
cb()
end)
end)
-- Get job and loadout
table.insert(tasks, function(cb)
local tasks2 = {}
-- Get job name, grade and last position
table.insert(tasks2, function(cb2)
local _source = source
local tasks = {}
local userData = {
accounts = {},
inventory = {},
job = {},
loadout = {},
playerName = GetPlayerName(_source),
lastPosition = nil
}
TriggerEvent('es:getPlayerFromId', _source, function(player)
-- Update user name in DB
table.insert(tasks, function(cb)
MySQL.Async.execute(
'UPDATE `users` SET `name` = @name WHERE `identifier` = @identifier',
{
['@identifier'] = player.getIdentifier(),
['@name'] = userData.playerName
},
function(rowsChanged)
cb()
end
)
end)
-- Get accounts
table.insert(tasks, function(cb)
MySQL.Async.fetchAll(
'SELECT * FROM `user_accounts` WHERE `identifier` = @identifier',
{
['@identifier'] = player.getIdentifier()
},
function(accounts)
for i=1, #Config.Accounts, 1 do
for j=1, #accounts, 1 do
if accounts[j].name == Config.Accounts[i] then
table.insert(userData.accounts, {
name = accounts[j].name,
money = accounts[j].money,
label = Config.AccountLabels[accounts[j].name]
})
end
end
end
cb()
end
)
end)
-- Get Inventory
table.insert(tasks, function(cb)
MySQL.Async.fetchAll(
'SELECT * FROM `user_inventory` WHERE `identifier` = @identifier',
{
['@identifier'] = player.getIdentifier()
},
function(inventory)
local tasks2 = {}
for i=1, #inventory, 1 do
table.insert(userData.inventory, {
name = inventory[i].item,
count = inventory[i].count,
label = ESX.Items[inventory[i].item].label,
limit = ESX.Items[inventory[i].item].limit,
usable = ESX.UsableItemsCallbacks[inventory[i].item] ~= nil,
rare = ESX.Items[inventory[i].item].rare,
canRemove = ESX.Items[inventory[i].item].canRemove,
})
end
for k,v in pairs(ESX.Items) do
local found = false
for j=1, #userData.inventory, 1 do
if userData.inventory[j].name == k then
found = true
break
end
end
MySQL.Async.fetchAll('SELECT * FROM `users` WHERE `identifier` = @identifier', {
['@identifier'] = player.getIdentifier()
}, function(result)
userData.job['name'] = result[1].job
userData.job['grade'] = result[1].job_grade
if not found then
if result[1].loadout ~= nil then
userData.loadout = json.decode(result[1].loadout)
end
table.insert(userData.inventory, {
name = k,
count = 0,
label = ESX.Items[k].label,
limit = ESX.Items[k].limit,
usable = ESX.UsableItemsCallbacks[k] ~= nil,
rare = ESX.Items[k].rare,
canRemove = ESX.Items[k].canRemove,
})
local scope = function(item, identifier)
if result[1].position ~= nil then
userData.lastPosition = json.decode(result[1].position)
end
table.insert(tasks2, function(cb2)
cb2()
end)
MySQL.Async.execute(
'INSERT INTO user_inventory (identifier, item, count) VALUES (@identifier, @item, @count)',
{
['@identifier'] = identifier,
['@item'] = item,
['@count'] = 0
},
function(rowsChanged)
cb2()
end
)
end)
end)
-- Get job label
table.insert(tasks2, function(cb2)
MySQL.Async.fetchAll('SELECT * FROM `jobs` WHERE `name` = @name', {
['@name'] = userData.job.name
}, function(result)
userData.job['label'] = result[1].label
cb2()
end)
end)
end
-- Get job grade data
table.insert(tasks2, function(cb2)
scope(k, player.getIdentifier())
MySQL.Async.fetchAll('SELECT * FROM `job_grades` WHERE `job_name` = @job_name AND `grade` = @grade',
{
['@job_name'] = userData.job.name,
['@grade'] = userData.job.grade
}, function(result)
end
userData.job['grade_name'] = result[1].name
userData.job['grade_label'] = result[1].label
userData.job['grade_salary'] = result[1].salary
end
userData.job['skin_male'] = {}
userData.job['skin_female'] = {}
Async.parallelLimit(tasks2, 5, function(results) end)
if result[1].skin_male ~= nil then
userData.job['skin_male'] = json.decode(result[1].skin_male)
end
table.sort(userData.inventory, function(a,b)
return a.label < b.label
end)
if result[1].skin_female ~= nil then
userData.job['skin_female'] = json.decode(result[1].skin_female)
end
cb()
end
)
cb2()
end)
end)
end)
-- Get job and loadout
table.insert(tasks, function(cb)
Async.series(tasks2, cb)
local tasks2 = {}
end)
-- Get job name, grade and last position
table.insert(tasks2, function(cb2)
-- Run Tasks
Async.parallel(tasks, function(results)
MySQL.Async.fetchAll(
'SELECT * FROM `users` WHERE `identifier` = @identifier',
{
['@identifier'] = player.getIdentifier()
},
function(result)
local xPlayer = CreateExtendedPlayer(player, userData.accounts, userData.inventory, userData.job, userData.loadout, userData.playerName, userData.lastPosition)
userData.job['name'] = result[1].job
userData.job['grade'] = result[1].job_grade
xPlayer.getMissingAccounts(function(missingAccounts)
if result[1].loadout ~= nil then
userData.loadout = json.decode(result[1].loadout)
end
if #missingAccounts > 0 then
if result[1].position ~= nil then
userData.lastPosition = json.decode(result[1].position)
end
for i=1, #missingAccounts, 1 do
table.insert(xPlayer.accounts, {
name = missingAccounts[i],
money = 0,
label = Config.AccountLabels[missingAccounts[i]]
})
end
cb2()
xPlayer.createAccounts(missingAccounts)
end
end
)
ESX.Players[_source] = xPlayer
end)
TriggerEvent('esx:playerLoaded', _source)
-- Get job label
table.insert(tasks2, function(cb2)
TriggerClientEvent('esx:playerLoaded', _source, {
identifier = xPlayer.identifier,
accounts = xPlayer.getAccounts(),
inventory = xPlayer.getInventory(),
job = xPlayer.getJob(),
loadout = xPlayer.getLoadout(),
lastPosition = xPlayer.getLastPosition(),
money = xPlayer.get('money')
})
MySQL.Async.fetchAll(
'SELECT * FROM `jobs` WHERE `name` = @name',
{
['@name'] = userData.job.name
},
function(result)
xPlayer.player.displayMoney(xPlayer.get('money'))
userData.job['label'] = result[1].label
end)
cb2()
end)
end
)
end)
-- Get job grade data
table.insert(tasks2, function(cb2)
MySQL.Async.fetchAll(
'SELECT * FROM `job_grades` WHERE `job_name` = @job_name AND `grade` = @grade',
{
['@job_name'] = userData.job.name,
['@grade'] = userData.job.grade
},
function(result)
userData.job['grade_name'] = result[1].name
userData.job['grade_label'] = result[1].label
userData.job['grade_salary'] = result[1].salary
userData.job['skin_male'] = {}
userData.job['skin_female'] = {}
if result[1].skin_male ~= nil then
userData.job['skin_male'] = json.decode(result[1].skin_male)
end
if result[1].skin_female ~= nil then
userData.job['skin_female'] = json.decode(result[1].skin_female)
end
cb2()
end
)
end)
Async.series(tasks2, cb)
end)
-- Run Tasks
Async.parallel(tasks, function(results)
local xPlayer = CreateExtendedPlayer(player, userData.accounts, userData.inventory, userData.job, userData.loadout, userData.playerName, userData.lastPosition)
xPlayer.getMissingAccounts(function(missingAccounts)
if #missingAccounts > 0 then
for i=1, #missingAccounts, 1 do
table.insert(xPlayer.accounts, {
name = missingAccounts[i],
money = 0,
label = Config.AccountLabels[missingAccounts[i]]
})
end
xPlayer.createAccounts(missingAccounts)
end
ESX.Players[_source] = xPlayer
TriggerEvent('esx:playerLoaded', _source)
TriggerClientEvent('esx:playerLoaded', _source, {
identifier = xPlayer.identifier,
accounts = xPlayer.getAccounts(),
inventory = xPlayer.getInventory(),
job = xPlayer.getJob(),
loadout = xPlayer.getLoadout(),
lastPosition = xPlayer.getLastPosition(),
money = xPlayer.get('money')
})
xPlayer.player.displayMoney(xPlayer.get('money'))
end)
end)
end)
end)
end)
AddEventHandler('playerDropped', function(reason)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
if xPlayer ~= nil then
TriggerEvent('esx:playerDropped', _source, reason)
ESX.SavePlayer(xPlayer, function()
ESX.Players[_source] = nil
ESX.LastPlayerData[_source] = nil
end)
end
if xPlayer ~= nil then
TriggerEvent('esx:playerDropped', _source, reason)
ESX.SavePlayer(xPlayer, function()
ESX.Players[_source] = nil
ESX.LastPlayerData[_source] = nil
end)
end
end)
RegisterServerEvent('esx:updateLoadout')
@@ -310,293 +264,271 @@ end)
RegisterServerEvent('esx:giveInventoryItem')
AddEventHandler('esx:giveInventoryItem', function(target, type, itemName, itemCount)
local _source = source
local _source = source
local sourceXPlayer = ESX.GetPlayerFromId(_source)
local targetXPlayer = ESX.GetPlayerFromId(target)
local sourceXPlayer = ESX.GetPlayerFromId(_source)
local targetXPlayer = ESX.GetPlayerFromId(target)
if type == 'item_standard' then
if type == 'item_standard' then
local sourceItem = sourceXPlayer.getInventoryItem(itemName)
local targetItem = targetXPlayer.getInventoryItem(itemName)
local sourceItem = sourceXPlayer.getInventoryItem(itemName)
local targetItem = targetXPlayer.getInventoryItem(itemName)
if itemCount > 0 and sourceItem.count >= itemCount then
if itemCount > 0 and sourceItem.count >= itemCount then
if targetItem.limit ~= -1 and (targetItem.count + itemCount) > targetItem.limit then
TriggerClientEvent('esx:showNotification', _source, _U('ex_inv_lim', targetXPlayer.name))
else
sourceXPlayer.removeInventoryItem(itemName, itemCount)
targetXPlayer.addInventoryItem (itemName, itemCount)
TriggerClientEvent('esx:showNotification', _source, _U('gave_item', itemCount, ESX.Items[itemName].label, targetXPlayer.name))
TriggerClientEvent('esx:showNotification', target, _U('received_item', itemCount, ESX.Items[itemName].label, sourceXPlayer.name))
end
if targetItem.limit ~= -1 and (targetItem.count + itemCount) > targetItem.limit then
TriggerClientEvent('esx:showNotification', _source, _U('ex_inv_lim', targetXPlayer.name))
else
sourceXPlayer.removeInventoryItem(itemName, itemCount)
targetXPlayer.addInventoryItem (itemName, itemCount)
TriggerClientEvent('esx:showNotification', _source, _U('gave_item', itemCount, ESX.Items[itemName].label, targetXPlayer.name))
TriggerClientEvent('esx:showNotification', target, _U('received_item', itemCount, ESX.Items[itemName].label, sourceXPlayer.name))
end
else
TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_quantity'))
end
else
TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_quantity'))
end
elseif type == 'item_money' then
elseif type == 'item_money' then
if itemCount > 0 and sourceXPlayer.player.get('money') >= itemCount then
if itemCount > 0 and sourceXPlayer.player.get('money') >= itemCount then
sourceXPlayer.removeMoney(itemCount)
targetXPlayer.addMoney (itemCount)
sourceXPlayer.removeMoney(itemCount)
targetXPlayer.addMoney (itemCount)
TriggerClientEvent('esx:showNotification', _source, _U('gave_money', itemCount, targetXPlayer.name))
TriggerClientEvent('esx:showNotification', target, _U('received_money', itemCount, sourceXPlayer.name))
TriggerClientEvent('esx:showNotification', _source, _U('gave_money', itemCount, targetXPlayer.name))
TriggerClientEvent('esx:showNotification', target, _U('received_money', itemCount, sourceXPlayer.name))
else
TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_amount'))
end
else
TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_amount'))
end
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)
targetXPlayer.addAccountMoney (itemName, itemCount)
sourceXPlayer.removeAccountMoney(itemName, itemCount)
targetXPlayer.addAccountMoney (itemName, itemCount)
TriggerClientEvent('esx:showNotification', _source, _U('gave_account_money', itemCount, Config.AccountLabels[itemName], targetXPlayer.name))
TriggerClientEvent('esx:showNotification', target, _U('received_account_money', itemCount, Config.AccountLabels[itemName], sourceXPlayer.name))
TriggerClientEvent('esx:showNotification', _source, _U('gave_account_money', itemCount, Config.AccountLabels[itemName], targetXPlayer.name))
TriggerClientEvent('esx:showNotification', target, _U('received_account_money', itemCount, Config.AccountLabels[itemName], sourceXPlayer.name))
else
TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_amount'))
end
else
TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_amount'))
end
elseif type == 'item_weapon' then
sourceXPlayer.removeWeapon(itemName)
targetXPlayer.addWeapon(itemName, itemCount)
local weaponLabel = ESX.GetWeaponLabel(itemName)
TriggerClientEvent('esx:showNotification', _source, _U('gave_weapon', weaponLabel, itemCount, targetXPlayer.name))
TriggerClientEvent('esx:showNotification', target, _U('received_weapon', weaponLabel, itemCount, sourceXPlayer.name))
end
elseif type == 'item_weapon' then
sourceXPlayer.removeWeapon(itemName)
targetXPlayer.addWeapon(itemName, itemCount)
local weaponLabel = ESX.GetWeaponLabel(itemName)
TriggerClientEvent('esx:showNotification', _source, _U('gave_weapon', weaponLabel, itemCount, targetXPlayer.name))
TriggerClientEvent('esx:showNotification', target, _U('received_weapon', weaponLabel, itemCount, sourceXPlayer.name))
end
end)
RegisterServerEvent('esx:removeInventoryItem')
AddEventHandler('esx:removeInventoryItem', function(type, itemName, itemCount)
local _source = source
local _source = source
if type == 'item_standard' then
if type == 'item_standard' then
if itemCount == nil or itemCount <= 0 then
TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_quantity'))
else
if itemCount == nil or itemCount <= 0 then
TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_quantity'))
else
local xPlayer = ESX.GetPlayerFromId(source)
local foundItem = nil
local xPlayer = ESX.GetPlayerFromId(source)
local foundItem = nil
for i=1, #xPlayer.inventory, 1 do
if xPlayer.inventory[i].name == itemName then
foundItem = xPlayer.inventory[i]
end
end
for i=1, #xPlayer.inventory, 1 do
if xPlayer.inventory[i].name == itemName then
foundItem = xPlayer.inventory[i]
end
end
if itemCount > foundItem.count then
TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_quantity'))
else
if itemCount > foundItem.count then
TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_quantity'))
else
TriggerClientEvent('esx:showNotification', _source, _U('delete_five_min'))
TriggerClientEvent('esx:showNotification', _source, _U('delete_five_min'))
SetTimeout(Config.RemoveInventoryItemDelay, function()
local remainingCount = xPlayer.getInventoryItem(itemName).count
local total = itemCount
SetTimeout(Config.RemoveInventoryItemDelay, function()
if remainingCount < itemCount then
total = remainingCount
end
local remainingCount = xPlayer.getInventoryItem(itemName).count
local total = itemCount
if total > 0 then
xPlayer.removeInventoryItem(itemName, total)
ESX.CreatePickup('item_standard', itemName, total, foundItem.label .. ' [' .. itemCount .. ']', _source)
TriggerClientEvent('esx:showNotification', _source, _U('threw') .. ' ' .. foundItem.label .. ' x' .. total)
end
end)
end
if remainingCount < itemCount then
total = remainingCount
end
end
if total > 0 then
xPlayer.removeInventoryItem(itemName, total)
ESX.CreatePickup('item_standard', itemName, total, foundItem.label .. ' [' .. itemCount .. ']', _source)
TriggerClientEvent('esx:showNotification', _source, _U('threw') .. ' ' .. foundItem.label .. ' x' .. total)
end
elseif type == 'item_money' then
end)
if itemCount == nil or itemCount <= 0 then
TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_amount'))
else
end
local xPlayer = ESX.GetPlayerFromId(source)
end
if itemCount > xPlayer.player.get('money') then
TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_amount'))
else
elseif type == 'item_money' then
TriggerClientEvent('esx:showNotification', _source, _U('delete_five_min'))
if itemCount == nil or itemCount <= 0 then
TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_amount'))
else
SetTimeout(Config.RemoveInventoryItemDelay, function()
local remainingCount = xPlayer.player.get('money')
local total = itemCount
local xPlayer = ESX.GetPlayerFromId(source)
if remainingCount < itemCount then
total = remainingCount
end
if itemCount > xPlayer.player.get('money') then
TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_amount'))
else
if total > 0 then
xPlayer.removeMoney(total)
ESX.CreatePickup('item_money', 'money', total, 'Cash' .. ' [' .. itemCount .. ']', _source)
TriggerClientEvent('esx:showNotification', _source, _U('threw') .. ' [Cash] $' .. total)
end
end)
end
TriggerClientEvent('esx:showNotification', _source, _U('delete_five_min'))
end
SetTimeout(Config.RemoveInventoryItemDelay, function()
elseif type == 'item_account' then
local remainingCount = xPlayer.player.get('money')
local total = itemCount
if itemCount == nil or itemCount <= 0 then
TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_amount'))
else
if remainingCount < itemCount then
total = remainingCount
end
local xPlayer = ESX.GetPlayerFromId(source)
if total > 0 then
xPlayer.removeMoney(total)
ESX.CreatePickup('item_money', 'money', total, 'Cash' .. ' [' .. itemCount .. ']', _source)
TriggerClientEvent('esx:showNotification', _source, _U('threw') .. ' [Cash] $' .. total)
end
if itemCount > xPlayer.getAccount(itemName).money then
TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_amount'))
else
end)
TriggerClientEvent('esx:showNotification', _source, _U('delete_five_min'))
end
SetTimeout(Config.RemoveInventoryItemDelay, function()
local remainingCount = xPlayer.getAccount(itemName).money
local total = itemCount
end
if remainingCount < itemCount then
total = remainingCount
end
elseif type == 'item_account' then
if total > 0 then
xPlayer.removeAccountMoney(itemName, total)
ESX.CreatePickup('item_account', itemName, total, Config.AccountLabels[itemName] .. ' [' .. itemCount .. ']', _source)
TriggerClientEvent('esx:showNotification', _source, _U('threw') .. ' [Cash] $' .. total)
end
end)
end
if itemCount == nil or itemCount <= 0 then
TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_amount'))
else
end
local xPlayer = ESX.GetPlayerFromId(source)
elseif type == 'item_weapon' then
if itemCount > xPlayer.getAccount(itemName).money then
TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_amount'))
else
local xPlayer = ESX.GetPlayerFromId(source)
local weaponName = itemName
local weaponLabel = ESX.GetWeaponLabel(weaponName)
local weaponPickup = 'PICKUP_' .. weaponName
TriggerClientEvent('esx:showNotification', _source, _U('delete_five_min'))
SetTimeout(Config.RemoveInventoryItemDelay, function()
xPlayer.removeWeapon(itemName)
if Config.EnableWeaponPickup then
TriggerClientEvent('esx:pickupWeapon', _source, weaponPickup, weaponName, itemCount)
end
TriggerClientEvent('esx:showNotification', _source, _U('delete_five_min'))
SetTimeout(Config.RemoveInventoryItemDelay, function()
local remainingCount = xPlayer.getAccount(itemName).money
local total = itemCount
if remainingCount < itemCount then
total = remainingCount
end
if total > 0 then
xPlayer.removeAccountMoney(itemName, total)
ESX.CreatePickup('item_account', itemName, total, Config.AccountLabels[itemName] .. ' [' .. itemCount .. ']', _source)
TriggerClientEvent('esx:showNotification', _source, _U('threw') .. ' [Cash] $' .. total)
end
end)
end
end
elseif type == 'item_weapon' then
local xPlayer = ESX.GetPlayerFromId(source)
local weaponName = itemName
local weaponLabel = ESX.GetWeaponLabel(weaponName)
local weaponPickup = 'PICKUP_' .. weaponName
TriggerClientEvent('esx:showNotification', _source, _U('delete_five_min'))
SetTimeout(Config.RemoveInventoryItemDelay, function()
xPlayer.removeWeapon(itemName)
if Config.EnableWeaponPickup then
TriggerClientEvent('esx:pickupWeapon', _source, weaponPickup, weaponName, itemCount)
end
TriggerClientEvent('esx:showNotification', _source, _U('threw_weapon', weaponLabel, itemCount))
end)
end
TriggerClientEvent('esx:showNotification', _source, _U('threw_weapon', weaponLabel, itemCount))
end)
end
end)
RegisterServerEvent('esx:useItem')
AddEventHandler('esx:useItem', function(itemName)
local xPlayer = ESX.GetPlayerFromId(source)
local count = xPlayer.getInventoryItem(itemName).count
local xPlayer = ESX.GetPlayerFromId(source)
local count = xPlayer.getInventoryItem(itemName).count
if count > 0 then
ESX.UseItem(source, itemName)
else
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('act_imp'))
end
if count > 0 then
ESX.UseItem(source, itemName)
else
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('act_imp'))
end
end)
RegisterServerEvent('esx:onPickup')
AddEventHandler('esx:onPickup', function(id)
local _source = source
local pickup = ESX.Pickups[id]
local xPlayer = ESX.GetPlayerFromId(_source)
local _source = source
local pickup = ESX.Pickups[id]
local xPlayer = ESX.GetPlayerFromId(_source)
if pickup.type == 'item_standard' then
if pickup.type == 'item_standard' then
local item = xPlayer.getInventoryItem(pickup.name)
local canTake = ((item.limit == -1) and (pickup.count)) or ((item.limit - item.count > 0) and (item.limit - item.count)) or 0
local total = pickup.count < canTake and pickup.count or canTake
local remaining = pickup.count - total
local item = xPlayer.getInventoryItem(pickup.name)
local canTake = ((item.limit == -1) and (pickup.count)) or ((item.limit - item.count > 0) and (item.limit - item.count)) or 0
local total = pickup.count < canTake and pickup.count or canTake
local remaining = pickup.count - total
TriggerClientEvent('esx:removePickup', -1, id)
TriggerClientEvent('esx:removePickup', -1, id)
if total > 0 then
xPlayer.addInventoryItem(pickup.name, total)
end
if total > 0 then
xPlayer.addInventoryItem(pickup.name, total)
end
if remaining > 0 then
TriggerClientEvent('esx:showNotification', _source, _U('cannot_pickup_room', item.label))
ESX.CreatePickup('item_standard', pickup.name, remaining, item.label .. ' [' .. remaining .. ']', _source)
end
elseif pickup.type == 'item_money' then
TriggerClientEvent('esx:removePickup', -1, id)
xPlayer.addMoney(pickup.count)
elseif pickup.type == 'item_account' then
TriggerClientEvent('esx:removePickup', -1, id)
xPlayer.addAccountMoney(pickup.name, pickup.count)
end
if remaining > 0 then
TriggerClientEvent('esx:showNotification', _source, _U('cannot_pickup_room', item.label))
ESX.CreatePickup('item_standard', pickup.name, remaining, item.label .. ' [' .. remaining .. ']', _source)
end
elseif pickup.type == 'item_money' then
TriggerClientEvent('esx:removePickup', -1, id)
xPlayer.addMoney(pickup.count)
elseif pickup.type == 'item_account' then
TriggerClientEvent('esx:removePickup', -1, id)
xPlayer.addAccountMoney(pickup.name, pickup.count)
end
end)
ESX.RegisterServerCallback('esx:getPlayerData', function(source, cb)
local xPlayer = ESX.GetPlayerFromId(source)
local xPlayer = ESX.GetPlayerFromId(source)
cb({
identifier = xPlayer.identifier,
accounts = xPlayer.getAccounts(),
inventory = xPlayer.getInventory(),
job = xPlayer.getJob(),
loadout = xPlayer.getLoadout(),
lastPosition = xPlayer.getLastPosition(),
money = xPlayer.get('money')
})
cb({
identifier = xPlayer.identifier,
accounts = xPlayer.getAccounts(),
inventory = xPlayer.getInventory(),
job = xPlayer.getJob(),
loadout = xPlayer.getLoadout(),
lastPosition = xPlayer.getLastPosition(),
money = xPlayer.get('money')
})
end)
ESX.RegisterServerCallback('esx:getOtherPlayerData', function(source, cb, target)
local xPlayer = ESX.GetPlayerFromId(target)
local xPlayer = ESX.GetPlayerFromId(target)
cb({
identifier = xPlayer.identifier,
accounts = xPlayer.getAccounts(),
inventory = xPlayer.getInventory(),
job = xPlayer.getJob(),
loadout = xPlayer.getLoadout(),
lastPosition = xPlayer.getLastPosition(),
money = xPlayer.get('money')
})
cb({
identifier = xPlayer.identifier,
accounts = xPlayer.getAccounts(),
inventory = xPlayer.getInventory(),
job = xPlayer.getJob(),
loadout = xPlayer.getLoadout(),
lastPosition = xPlayer.getLastPosition(),
money = xPlayer.get('money')
})
end)
TriggerEvent("es:addGroup", "jobmaster", "user", function(group) end)