build(submodules): Remove submodules + move everything at root

This commit is contained in:
Jérémie N'gadi
2017-09-15 14:26:56 +02:00
parent 9ee7a5f61e
commit 97adf4f97c
34 changed files with 0 additions and 16 deletions
+426
View File
@@ -0,0 +1,426 @@
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)
self.player.setMoney(m)
end
self.getMoney = function()
return self.player.get('money')
end
self.setBankBalance = function(m)
self.player.setBankBalance(m)
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)
self.player.addMoney(m)
end
self.removeMoney = function(m)
self.player.removeMoney(m)
end
self.addBank = function(m)
self.player.addBank(m)
end
self.removeBank = function(m)
self.player.removeBank(m)
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
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)
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)
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)
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 = ammon,
label = weaponLabel
})
end
TriggerClientEvent('esx:addWeapon', self.source, weaponName, ammo)
TriggerClientEvent("esx:addInventoryItem", self.source, {label = weaponLabel}, 1)
end
self.removeWeapon = function(weaponName)
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)
TriggerClientEvent("esx:removeInventoryItem", self.source, {label = weaponLabel}, 1)
end
return self
end
+136
View File
@@ -0,0 +1,136 @@
TriggerEvent('es:addGroupCommand', 'tp', 'admin', function(source, args, user)
TriggerClientEvent("esx:teleport", source, {
x = tonumber(args[2]),
y = tonumber(args[3]),
z = tonumber(args[4])
})
end, function(source, args, user)
TriggerClientEvent('chatMessage', source, "SYSTEM", {255, 0, 0}, "Insufficient Permissions.")
end)
TriggerEvent('es:addGroupCommand', 'setjob', 'jobmaster', function(source, args, user)
local xPlayer = ESX.GetPlayerFromId(args[2])
xPlayer.setJob(args[3], tonumber(args[4]))
end, function(source, args, user)
TriggerClientEvent('chatMessage', source, "SYSTEM", {255, 0, 0}, "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[2])
end, function(source, args, user)
TriggerClientEvent('chatMessage', source, "SYSTEM", {255, 0, 0}, "Insufficient Permissions.")
end, {help = _U('load_ipl')})
TriggerEvent('es:addGroupCommand', 'unloadipl', 'admin', function(source, args, user)
TriggerClientEvent('esx:unloadIPL', -1, args[2])
end, function(source, args, user)
TriggerClientEvent('chatMessage', source, "SYSTEM", {255, 0, 0}, "Insufficient Permissions.")
end, {help = _U('unload_ipl')})
TriggerEvent('es:addGroupCommand', 'playanim', 'admin', function(source, args, user)
TriggerClientEvent('esx:playAnim', -1, args[2], args[3])
end, function(source, args, user)
TriggerClientEvent('chatMessage', source, "SYSTEM", {255, 0, 0}, "Insufficient Permissions.")
end, {help = _U('play_anim')})
TriggerEvent('es:addGroupCommand', 'playemote', 'admin', function(source, args, user)
TriggerClientEvent('esx:playEmote', -1, args[2])
end, function(source, args, user)
TriggerClientEvent('chatMessage', source, "SYSTEM", {255, 0, 0}, "Insufficient Permissions.")
end, {help = _U('play_emote')})
TriggerEvent('es:addGroupCommand', 'car', 'admin', function(source, args, user)
TriggerClientEvent('esx:spawnVehicle', source, args[2])
end, function(source, args, user)
TriggerClientEvent('chatMessage', source, "SYSTEM", {255, 0, 0}, "Insufficient Permissions.")
end, {help = _U('spawn_car'), params = {{name = "car", help = _U('spawn_car_param')}}})
TriggerEvent('es:addGroupCommand', 'dv', 'admin', function(source, args, user)
TriggerClientEvent('esx:deleteVehicle', source)
end, function(source, args, user)
TriggerClientEvent('chatMessage', source, "SYSTEM", {255, 0, 0}, "Insufficient Permissions.")
end, {help = _U('delete_vehicle'), params = {{name = "car", help = _U('delete_veh_param')}}})
TriggerEvent('es:addGroupCommand', 'spawnped', 'admin', function(source, args, user)
TriggerClientEvent('esx:spawnPed', source, args[2])
end, function(source, args, user)
TriggerClientEvent('chatMessage', source, "SYSTEM", {255, 0, 0}, "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[2])
end, function(source, args, user)
TriggerClientEvent('chatMessage', source, "SYSTEM", {255, 0, 0}, "Insufficient Permissions.")
end, {help = _U('spawn_object'), params = {{name = "name"}}})
TriggerEvent('es:addGroupCommand', 'givemoney', 'admin', function(source, args, user)
local _source = source
local xPlayer = ESX.GetPlayerFromId(args[2])
local amount = tonumber(args[3])
if amount ~= nil then
xPlayer.addMoney(amount)
else
TriggerClientEvent('esx:showNotification', _source, _U('amount_invalid'))
end
end, function(source, args, user)
TriggerClientEvent('chatMessage', source, "SYSTEM", {255, 0, 0}, "Insufficient Permissions.")
end, {help = _U('givemoney'), params = {{name = "id", help = _U('id_param')}, {name = "amount", help = _U('money_amount')}}})
TriggerEvent('es:addGroupCommand', 'giveaccountmoney', 'admin', function(source, args, user)
local _source = source
local xPlayer = ESX.GetPlayerFromId(args[2])
local account = args[3]
local amount = tonumber(args[4])
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('chatMessage', source, "SYSTEM", {255, 0, 0}, "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[2])
local item = args[3]
local count = (args[4] == nil and 1 or tonumber(args[4]))
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('chatMessage', source, "SYSTEM", {255, 0, 0}, "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[2])
local weaponName = string.upper(args[3])
xPlayer.addWeapon(weaponName, 1000)
end, function(source, args, user)
TriggerClientEvent('chatMessage', source, "SYSTEM", {255, 0, 0}, "Insufficient Permissions.")
end, {help = _U('giveweapon'), params = {{name = "id", help = _U('id_param')}, {name = "weapon", help = _U('weapon')}}})
+101
View File
@@ -0,0 +1,101 @@
ESX = {}
ESX.Players = {}
ESX.UsableItemsCallbacks = {}
ESX.Items = {}
ESX.ServerCallbacks = {}
ESX.TimeoutCallbacks = {}
ESX.LastPlayerData = {}
ESX.Pickups = {}
ESX.PickupId = 0
AddEventHandler('esx:getSharedObject', function(cb)
cb(ESX)
end)
function getSharedObject()
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
)
end)
AddEventHandler('esx:playerLoaded', function(source)
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, #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")
end)
RegisterServerEvent('esx:triggerServerCallback')
AddEventHandler('esx:triggerServerCallback', function(name, requestId, ...)
local _source = source
ESX.TriggerServerCallback(name, requestID, _source, function(...)
TriggerClientEvent('esx:serverCallback', _source, requestId, ...)
end, ...)
end)
-- SetTimeout
CreateThread(function()
while true do
Wait(0)
local currTime = os.clock() * 1000
for i=1, #ESX.TimeoutCallbacks, 1 do
if ESX.TimeoutCallbacks[i] ~= nil then
if currTime >= ESX.TimeoutCallbacks[i].time then
ESX.TimeoutCallbacks[i].cb()
ESX.TimeoutCallbacks[i] = nil
end
end
end
end
end)
+246
View File
@@ -0,0 +1,246 @@
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
end
ESX.SetTimeout = function(msec, cb)
table.insert(ESX.TimeoutCallbacks, {
time = os.clock() * 1000 + msec,
cb = cb
})
return #ESX.TimeoutCallbacks
end
ESX.ClearTimeout = function(i)
ESX.TimeoutCallbacks[i] = nil
end
ESX.RegisterServerCallback = function(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 exists')
end
end
ESX.SavePlayer = function(xPlayer, cb)
local asyncTasks = {}
xPlayer.lastPosition = xPlayer.get('coords')
-- User accounts
for i=1, #xPlayer.accounts, 1 do
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)
ESX.LastPlayerData[xPlayer.source].accounts[xPlayer.accounts[i].name] = xPlayer.accounts[i].money
end
end
-- Inventory items
for i=1, #xPlayer.inventory, 1 do
if ESX.LastPlayerData[xPlayer.source].items[xPlayer.inventory[i].name] ~= xPlayer.inventory[i].count then
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)
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)
end
ESX.SavePlayers = function(cb)
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
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
SetTimeout(10 * 60 * 1000, saveData)
end
ESX.GetPlayers = function()
local sources = {}
for k,v in pairs(ESX.Players) do
table.insert(sources, k)
end
return sources
end
ESX.GetPlayerFromId = function(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
end
ESX.RegisterUsableItem = function(item, cb)
ESX.UsableItemsCallbacks[item] = cb
end
ESX.UseItem = function(source, item)
ESX.UsableItemsCallbacks[item](source)
end
ESX.GetWeaponList = function()
return Config.Weapons
end
ESX.GetWeaponLabel = function(name)
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
end
ESX.CreatePickup = function(type, name, count, label, player)
local pickupId = (ESX.PickupId == 65635 and 0 or ESX.PickupId + 1)
ESX.Pickups[pickupId] = {
type = type,
name = name,
count = count
}
TriggerClientEvent('esx:pickup', -1, pickupId, label, player)
ESX.PickupId = pickupId
end
+587
View File
@@ -0,0 +1,587 @@
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)
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,
})
MySQL.Async.execute(
'INSERT INTO user_inventory (identifier, item, count) VALUES (@identifier, @item, @count)',
{
['@identifier'] = player.getIdentifier(),
['@item'] = k,
['@count'] = 0
}
)
end
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)
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 result[1].loadout ~= nil then
userData.loadout = json.decode(result[1].loadout)
end
if result[1].position ~= nil then
userData.lastPosition = json.decode(result[1].position)
end
cb2()
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)
-- 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)
AddEventHandler('playerDropped', function()
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
if xPlayer ~= nil then
TriggerEvent('esx:playerDropped', _source)
ESX.SavePlayer(xPlayer, function()
ESX.Players[_source] = nil
ESX.LastPlayerData[_source] = nil
end)
end
end)
RegisterServerEvent('esx:updateLoadout')
AddEventHandler('esx:updateLoadout', function(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
end)
RegisterServerEvent('esx:giveInventoryItem')
AddEventHandler('esx:giveInventoryItem', function(target, type, itemName, itemCount)
local _source = source
local sourceXPlayer = ESX.GetPlayerFromId(_source)
local targetXPlayer = ESX.GetPlayerFromId(target)
if type == 'item_standard' then
local sourceItem = sourceXPlayer.getInventoryItem(itemName)
local targetItem = targetXPlayer.getInventoryItem(itemName)
if itemCount > 0 and sourceItem.count >= itemCount then
if targetItem.limit ~= -1 and (targetItem.count + itemCount) > targetItem.limit then
TriggerClientEvent('esx:showNotification', target, _U('ex_inv_lim') .. targetXPlayer.name)
else
sourceXPlayer.removeInventoryItem(itemName, itemCount)
targetXPlayer.addInventoryItem (itemName, itemCount)
TriggerClientEvent('esx:showNotification', _source, _U('yougave') .. ' ~g~x' .. itemCount .. ' ' .. ESX.Items[itemName].label .. _U('to') .. targetXPlayer.name)
TriggerClientEvent('esx:showNotification', target, _U('youreceived') .. ' ~g~x' .. itemCount .. ' ' .. ESX.Items[itemName].label .. _U('by') .. sourceXPlayer.name)
end
else
TriggerClientEvent('esx:showNotification', target, _U('imp_invalid_quantity'))
end
elseif type == 'item_money' then
if itemCount > 0 and sourceXPlayer.player.get('money') >= itemCount then
sourceXPlayer.removeMoney(itemCount)
targetXPlayer.addMoney(itemCount)
TriggerClientEvent('esx:showNotification', _source, _U('yougave') .. ' ~g~$' .. itemCount .. _U('to') .. targetXPlayer.name)
TriggerClientEvent('esx:showNotification', target, _U('youreceived') .. ' ~g~$' .. itemCount .. _U('by') .. sourceXPlayer.name)
else
TriggerClientEvent('esx:showNotification', target, _U('imp_invalid_amount'))
end
elseif type == 'item_account' then
if itemCount > 0 and sourceXPlayer.getAccount(itemName).money >= itemCount then
sourceXPlayer.removeAccountMoney(itemName, itemCount)
targetXPlayer.addAccountMoney(itemName, itemCount)
TriggerClientEvent('esx:showNotification', _source, _U('yougave') .. ' [' .. Config.AccountLabels[itemName] .. '] ~g~$' .. itemCount .. _U('to') .. targetXPlayer.name)
TriggerClientEvent('esx:showNotification', target, _U('youreceived') .. ' [' .. Config.AccountLabels[itemName] .. '] ~g~$' .. itemCount .. _U('by') .. sourceXPlayer.name)
else
TriggerClientEvent('esx:showNotification', target, _U('imp_invalid_amount'))
end
elseif type == 'item_weapon' then
sourceXPlayer.removeWeapon(itemName)
targetXPlayer.addWeapon(itemName, itemCount)
local weaponLabel = itemName
for i=1, #Config.Weapons, 1 do
if Config.Weapons[i].name == itemName then
weaponLabel = Config.Weapons[i].label
break
end
end
TriggerClientEvent('esx:showNotification', _source, _U('yougave') .. ' x1 ~g~' .. weaponLabel .. _U('to') .. targetXPlayer.name)
TriggerClientEvent('esx:showNotification', target, _U('youreceived') .. ' x1 ~g~' .. weaponLabel .. _U('by') .. sourceXPlayer.name)
end
end)
RegisterServerEvent('esx:removeInventoryItem')
AddEventHandler('esx:removeInventoryItem', function(type, itemName, itemCount)
local _source = source
if type == 'item_standard' then
if itemCount == nil or itemCount <= 0 then
TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_quantity'))
else
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
if itemCount > foundItem.count then
TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_quantity'))
else
TriggerClientEvent('esx:showNotification', _source, _U('delete_five_min'))
SetTimeout(Config.RemoveInventoryItemDelay, function()
local remainingCount = xPlayer.getInventoryItem(itemName).count
local total = itemCount
if remainingCount < itemCount then
total = remainingCount
end
if total > 0 then
xPlayer.removeInventoryItem(itemName, total)
ESX.CreatePickup('item_standard', itemName, total, foundItem.label, _source)
TriggerClientEvent('esx:showNotification', _source, _U('threw') .. ' ' .. foundItem.label .. ' x' .. total)
end
end)
end
end
elseif type == 'item_money' then
if itemCount == nil or itemCount <= 0 then
TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_amount'))
else
local xPlayer = ESX.GetPlayerFromId(source)
if itemCount > xPlayer.player.get('money') then
TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_amount'))
else
TriggerClientEvent('esx:showNotification', _source, _U('delete_five_min'))
SetTimeout(Config.RemoveInventoryItemDelay, function()
local remainingCount = xPlayer.player.get('money')
local total = itemCount
if remainingCount < itemCount then
total = remainingCount
end
if total > 0 then
xPlayer.removeMoney(total)
ESX.CreatePickup('item_money', 'money', total, 'Cash', _source)
TriggerClientEvent('esx:showNotification', _source, _U('threw') .. ' [Cash] $' .. total)
end
end)
end
end
elseif type == 'item_account' then
if itemCount == nil or itemCount <= 0 then
TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_amount'))
else
local xPlayer = ESX.GetPlayerFromId(source)
if itemCount > xPlayer.getAccount(itemName).money then
TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_amount'))
else
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, 'Cash', _source)
TriggerClientEvent('esx:showNotification', _source, _U('threw') .. ' [Cash] $' .. total)
end
end)
end
end
elseif type == 'item_weapon' then
local xPlayer = ESX.GetPlayerFromId(source)
local weaponLabel = itemName
local weaponName = nil
local weaponPickup = nil
for i=1, #Config.Weapons, 1 do
if Config.Weapons[i].name == itemName then
weaponLabel = Config.Weapons[i].label
weaponName = Config.Weapons[i].name
weaponPickup = 'PICKUP_'..weaponName
break
end
end
SetTimeout(Config.RemoveInventoryItemDelay, function()
xPlayer.removeWeapon(itemName)
if Config.EnableWeaponPickup then
TriggerClientEvent('esx:pickupWeapon', _source, weaponPickup, weaponName)
end
TriggerClientEvent('esx:showNotification', _source, _U('threw') .. ' x1 ~g~' .. weaponLabel)
end)
end
end)
RegisterServerEvent('esx:useItem')
AddEventHandler('esx:useItem', function(itemName)
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
end)
RegisterServerEvent('esx:onPickup')
AddEventHandler('esx:onPickup', function(id)
local pickup = ESX.Pickups[id]
local xPlayer = ESX.GetPlayerFromId(source)
if pickup.type == 'item_standard' then
xPlayer.addInventoryItem(pickup.name, pickup.count)
elseif pickup.type == 'item_money' then
xPlayer.addMoney(pickup.count)
elseif pickup.type == 'item_account' then
xPlayer.addAccountMoney(pickup.name, pickup.count)
end
TriggerClientEvent('esx:removePickup', -1, id)
end)
ESX.RegisterServerCallback('esx:getPlayerData', function(source, cb)
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')
})
end)
ESX.RegisterServerCallback('esx:getOtherPlayerData', function(source, cb, 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')
})
end)
TriggerEvent("es:addGroup", "jobmaster", "user", function(group) end)
ESX.StartDBSync()
ESX.StartPayCheck()
+24
View File
@@ -0,0 +1,24 @@
ESX.StartPayCheck = function()
function payCheck()
local xPlayers = ESX.GetPlayers()
for i=1, #xPlayers, 1 do
local xPlayer = ESX.GetPlayerFromId(xPlayers[i])
if xPlayer.job.grade_salary > 0 then
xPlayer.addMoney(xPlayer.job.grade_salary)
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('rec_salary') .. '~g~$' .. xPlayer.job.grade_salary)
end
end
SetTimeout(Config.PaycheckInterval, payCheck)
end
SetTimeout(Config.PaycheckInterval, payCheck)
end