mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-31 02:08:55 +00:00
Minor code cleanup, use latest esx_identity code
This commit is contained in:
+69
-106
@@ -9,7 +9,7 @@ end
|
||||
TriggerEvent('esx_phone:registerNumber', 'police', _U('alert_police'), true, true)
|
||||
TriggerEvent('esx_society:registerSociety', 'police', 'Police', 'society_police', 'society_police', 'society_police', {type = 'public'})
|
||||
|
||||
RegisterServerEvent('esx_policejob:confiscatePlayerItem')
|
||||
RegisterNetEvent('esx_policejob:confiscatePlayerItem')
|
||||
AddEventHandler('esx_policejob:confiscatePlayerItem', function(target, itemType, itemName, amount)
|
||||
local _source = source
|
||||
local sourceXPlayer = ESX.GetPlayerFromId(_source)
|
||||
@@ -57,7 +57,7 @@ AddEventHandler('esx_policejob:confiscatePlayerItem', function(target, itemType,
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterServerEvent('esx_policejob:handcuff')
|
||||
RegisterNetEvent('esx_policejob:handcuff')
|
||||
AddEventHandler('esx_policejob:handcuff', function(target)
|
||||
local xPlayer = ESX.GetPlayerFromId(source)
|
||||
|
||||
@@ -68,7 +68,7 @@ AddEventHandler('esx_policejob:handcuff', function(target)
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterServerEvent('esx_policejob:drag')
|
||||
RegisterNetEvent('esx_policejob:drag')
|
||||
AddEventHandler('esx_policejob:drag', function(target)
|
||||
local xPlayer = ESX.GetPlayerFromId(source)
|
||||
|
||||
@@ -79,7 +79,7 @@ AddEventHandler('esx_policejob:drag', function(target)
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterServerEvent('esx_policejob:putInVehicle')
|
||||
RegisterNetEvent('esx_policejob:putInVehicle')
|
||||
AddEventHandler('esx_policejob:putInVehicle', function(target)
|
||||
local xPlayer = ESX.GetPlayerFromId(source)
|
||||
|
||||
@@ -90,7 +90,7 @@ AddEventHandler('esx_policejob:putInVehicle', function(target)
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterServerEvent('esx_policejob:OutVehicle')
|
||||
RegisterNetEvent('esx_policejob:OutVehicle')
|
||||
AddEventHandler('esx_policejob:OutVehicle', function(target)
|
||||
local xPlayer = ESX.GetPlayerFromId(source)
|
||||
|
||||
@@ -101,7 +101,7 @@ AddEventHandler('esx_policejob:OutVehicle', function(target)
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterServerEvent('esx_policejob:getStockItem')
|
||||
RegisterNetEvent('esx_policejob:getStockItem')
|
||||
AddEventHandler('esx_policejob:getStockItem', function(itemName, count)
|
||||
local _source = source
|
||||
local xPlayer = ESX.GetPlayerFromId(_source)
|
||||
@@ -126,7 +126,7 @@ AddEventHandler('esx_policejob:getStockItem', function(itemName, count)
|
||||
end)
|
||||
end)
|
||||
|
||||
RegisterServerEvent('esx_policejob:putStockItems')
|
||||
RegisterNetEvent('esx_policejob:putStockItems')
|
||||
AddEventHandler('esx_policejob:putStockItems', function(itemName, count)
|
||||
local xPlayer = ESX.GetPlayerFromId(source)
|
||||
local sourceItem = xPlayer.getInventoryItem(itemName)
|
||||
@@ -145,68 +145,44 @@ AddEventHandler('esx_policejob:putStockItems', function(itemName, count)
|
||||
end)
|
||||
end)
|
||||
|
||||
ESX.RegisterServerCallback('esx_policejob:getOtherPlayerData', function(source, cb, target)
|
||||
if Config.EnableESXIdentity then
|
||||
local xPlayer = ESX.GetPlayerFromId(target)
|
||||
local result = MySQL.Sync.fetchAll('SELECT firstname, lastname, sex, dateofbirth, height FROM users WHERE identifier = @identifier', {
|
||||
['@identifier'] = xPlayer.identifier
|
||||
})
|
||||
ESX.RegisterServerCallback('esx_policejob:getOtherPlayerData', function(source, cb, target, notify)
|
||||
local xPlayer = ESX.GetPlayerFromId(target)
|
||||
|
||||
local firstname = result[1].firstname
|
||||
local lastname = result[1].lastname
|
||||
local sex = result[1].sex
|
||||
local dob = result[1].dateofbirth
|
||||
local height = result[1].height
|
||||
if notify then
|
||||
xPlayer.showNotification(_U('being_searched'))
|
||||
end
|
||||
|
||||
if xPlayer then
|
||||
local data = {
|
||||
name = GetPlayerName(target),
|
||||
job = xPlayer.job,
|
||||
inventory = xPlayer.inventory,
|
||||
accounts = xPlayer.accounts,
|
||||
weapons = xPlayer.loadout,
|
||||
firstname = firstname,
|
||||
lastname = lastname,
|
||||
sex = sex,
|
||||
dob = dob,
|
||||
height = height
|
||||
name = xPlayer.getName(),
|
||||
job = xPlayer.job.label,
|
||||
grade = xPlayer.job.grade_label,
|
||||
inventory = xPlayer.getInventory(),
|
||||
accounts = xPlayer.getAccounts(),
|
||||
weapons = xPlayer.getLoadout()
|
||||
}
|
||||
|
||||
TriggerEvent('esx_status:getStatus', target, 'drunk', function(status)
|
||||
if status ~= nil then
|
||||
data.drunk = math.floor(status.percent)
|
||||
end
|
||||
end)
|
||||
if Config.EnableESXIdentity then
|
||||
data.dob = xPlayer.get('dateofbirth')
|
||||
data.height = xPlayer.get('height')
|
||||
|
||||
if Config.EnableLicenses then
|
||||
TriggerEvent('esx_license:getLicenses', target, function(licenses)
|
||||
data.licenses = licenses
|
||||
cb(data)
|
||||
end)
|
||||
else
|
||||
cb(data)
|
||||
if xPlayer.get('sex') == 'm' then data.sex = 'male' else data.sex = 'female' end
|
||||
end
|
||||
else
|
||||
local xPlayer = ESX.GetPlayerFromId(target)
|
||||
|
||||
local data = {
|
||||
name = GetPlayerName(target),
|
||||
job = xPlayer.job,
|
||||
inventory = xPlayer.inventory,
|
||||
accounts = xPlayer.accounts,
|
||||
weapons = xPlayer.loadout
|
||||
}
|
||||
|
||||
TriggerEvent('esx_status:getStatus', target, 'drunk', function(status)
|
||||
if status then
|
||||
data.drunk = math.floor(status.percent)
|
||||
data.drunk = ESX.Math.Round(status.percent)
|
||||
end
|
||||
|
||||
if Config.EnableLicenses then
|
||||
TriggerEvent('esx_license:getLicenses', target, function(licenses)
|
||||
data.licenses = licenses
|
||||
cb(data)
|
||||
end)
|
||||
else
|
||||
cb(data)
|
||||
end
|
||||
end)
|
||||
|
||||
TriggerEvent('esx_license:getLicenses', target, function(licenses)
|
||||
data.licenses = licenses
|
||||
end)
|
||||
|
||||
cb(data)
|
||||
end
|
||||
end)
|
||||
|
||||
@@ -219,28 +195,35 @@ ESX.RegisterServerCallback('esx_policejob:getFineList', function(source, cb, cat
|
||||
end)
|
||||
|
||||
ESX.RegisterServerCallback('esx_policejob:getVehicleInfos', function(source, cb, plate)
|
||||
|
||||
MySQL.Async.fetchAll('SELECT owner FROM owned_vehicles WHERE plate = @plate', {
|
||||
['@plate'] = plate
|
||||
}, function(result)
|
||||
|
||||
local retrivedInfo = {
|
||||
plate = plate
|
||||
}
|
||||
local retrivedInfo = {plate = plate}
|
||||
|
||||
if result[1] then
|
||||
MySQL.Async.fetchAll('SELECT name, firstname, lastname FROM users WHERE identifier = @identifier', {
|
||||
['@identifier'] = result[1].owner
|
||||
}, function(result2)
|
||||
|
||||
if Config.EnableESXIdentity then
|
||||
retrivedInfo.owner = result2[1].firstname .. ' ' .. result2[1].lastname
|
||||
else
|
||||
retrivedInfo.owner = result2[1].name
|
||||
end
|
||||
local xPlayer = ESX.GetPlayerFromIdentifier(result[1].owner)
|
||||
|
||||
-- is the owner online?
|
||||
if xPlayer then
|
||||
retrivedInfo.owner = xPlayer.getName()
|
||||
cb(retrivedInfo)
|
||||
end)
|
||||
else
|
||||
MySQL.Async.fetchAll('SELECT name, firstname, lastname FROM users WHERE identifier = @identifier', {
|
||||
['@identifier'] = result[1].owner
|
||||
}, function(result2)
|
||||
if result2[1] then
|
||||
if Config.EnableESXIdentity then
|
||||
retrivedInfo.owner = ('%s %s'):format(result2[1].firstname, result2[1].lastname)
|
||||
else
|
||||
retrivedInfo.owner = result2[1].name
|
||||
end
|
||||
|
||||
cb(retrivedInfo)
|
||||
else
|
||||
cb(retrivedInfo)
|
||||
end
|
||||
end)
|
||||
end
|
||||
else
|
||||
cb(retrivedInfo)
|
||||
end
|
||||
@@ -251,14 +234,13 @@ ESX.RegisterServerCallback('esx_policejob:getVehicleFromPlate', function(source,
|
||||
MySQL.Async.fetchAll('SELECT owner FROM owned_vehicles WHERE plate = @plate', {
|
||||
['@plate'] = plate
|
||||
}, function(result)
|
||||
if result[1] ~= nil then
|
||||
|
||||
if result[1] then
|
||||
MySQL.Async.fetchAll('SELECT name, firstname, lastname FROM users WHERE identifier = @identifier', {
|
||||
['@identifier'] = result[1].owner
|
||||
}, function(result2)
|
||||
|
||||
if Config.EnableESXIdentity then
|
||||
cb(result2[1].firstname .. ' ' .. result2[1].lastname, true)
|
||||
cb(('%s %s'):format(result2[1].firstname, result2[1].lastname), true)
|
||||
else
|
||||
cb(result2[1].name, true)
|
||||
end
|
||||
@@ -290,12 +272,7 @@ ESX.RegisterServerCallback('esx_policejob:addArmoryWeapon', function(source, cb,
|
||||
end
|
||||
|
||||
TriggerEvent('esx_datastore:getSharedDataStore', 'society_police', function(store)
|
||||
local weapons = store.get('weapons')
|
||||
|
||||
if weapons == nil then
|
||||
weapons = {}
|
||||
end
|
||||
|
||||
local weapons = store.get('weapons') or {}
|
||||
local foundWeapon = false
|
||||
|
||||
for i=1, #weapons, 1 do
|
||||
@@ -323,12 +300,7 @@ ESX.RegisterServerCallback('esx_policejob:removeArmoryWeapon', function(source,
|
||||
xPlayer.addWeapon(weaponName, 500)
|
||||
|
||||
TriggerEvent('esx_datastore:getSharedDataStore', 'society_police', function(store)
|
||||
|
||||
local weapons = store.get('weapons')
|
||||
|
||||
if weapons == nil then
|
||||
weapons = {}
|
||||
end
|
||||
local weapons = store.get('weapons') or {}
|
||||
|
||||
local foundWeapon = false
|
||||
|
||||
@@ -342,7 +314,7 @@ ESX.RegisterServerCallback('esx_policejob:removeArmoryWeapon', function(source,
|
||||
|
||||
if not foundWeapon then
|
||||
table.insert(weapons, {
|
||||
name = weaponName,
|
||||
name = weaponName,
|
||||
count = 0
|
||||
})
|
||||
end
|
||||
@@ -382,7 +354,6 @@ ESX.RegisterServerCallback('esx_policejob:buyWeapon', function(source, cb, weapo
|
||||
elseif type == 2 then
|
||||
local price = selectedWeapon.components[componentNum]
|
||||
local weaponNum, weapon = ESX.GetWeapon(weaponName)
|
||||
|
||||
local component = weapon.components[componentNum]
|
||||
|
||||
if component then
|
||||
@@ -402,7 +373,6 @@ ESX.RegisterServerCallback('esx_policejob:buyWeapon', function(source, cb, weapo
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
ESX.RegisterServerCallback('esx_policejob:buyJobVehicle', function(source, cb, vehicleProps, type)
|
||||
local xPlayer = ESX.GetPlayerFromId(source)
|
||||
local price = getPriceFromHash(vehicleProps.model, xPlayer.job.grade_name, type)
|
||||
@@ -464,7 +434,6 @@ ESX.RegisterServerCallback('esx_policejob:storeNearbyVehicle', function(source,
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
end)
|
||||
|
||||
function getPriceFromHash(hashKey, jobGrade, type)
|
||||
@@ -506,37 +475,36 @@ ESX.RegisterServerCallback('esx_policejob:getPlayerInventory', function(source,
|
||||
local xPlayer = ESX.GetPlayerFromId(source)
|
||||
local items = xPlayer.inventory
|
||||
|
||||
cb( { items = items } )
|
||||
cb({items = items})
|
||||
end)
|
||||
|
||||
AddEventHandler('playerDropped', function()
|
||||
-- Save the source in case we lose it (which happens a lot)
|
||||
local _source = source
|
||||
local playerId = source
|
||||
|
||||
-- Did the player ever join?
|
||||
if _source ~= nil then
|
||||
local xPlayer = ESX.GetPlayerFromId(_source)
|
||||
if playerId then
|
||||
local xPlayer = ESX.GetPlayerFromId(playerId)
|
||||
|
||||
-- Is it worth telling all clients to refresh?
|
||||
if xPlayer ~= nil and xPlayer.job ~= nil and xPlayer.job.name == 'police' then
|
||||
if xPlayer and xPlayer.job.name == 'police' then
|
||||
Citizen.Wait(5000)
|
||||
TriggerClientEvent('esx_policejob:updateBlip', -1)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterServerEvent('esx_policejob:spawned')
|
||||
RegisterNetEvent('esx_policejob:spawned')
|
||||
AddEventHandler('esx_policejob:spawned', function()
|
||||
local _source = source
|
||||
local xPlayer = ESX.GetPlayerFromId(_source)
|
||||
local xPlayer = ESX.GetPlayerFromId(playerId)
|
||||
|
||||
if xPlayer ~= nil and xPlayer.job ~= nil and xPlayer.job.name == 'police' then
|
||||
if xPlayer and xPlayer.job.name == 'police' then
|
||||
Citizen.Wait(5000)
|
||||
TriggerClientEvent('esx_policejob:updateBlip', -1)
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterServerEvent('esx_policejob:forceBlip')
|
||||
RegisterNetEvent('esx_policejob:forceBlip')
|
||||
AddEventHandler('esx_policejob:forceBlip', function()
|
||||
TriggerClientEvent('esx_policejob:updateBlip', -1)
|
||||
end)
|
||||
@@ -553,8 +521,3 @@ AddEventHandler('onResourceStop', function(resource)
|
||||
TriggerEvent('esx_phone:removeNumber', 'police')
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterServerEvent('esx_policejob:message')
|
||||
AddEventHandler('esx_policejob:message', function(target, msg)
|
||||
TriggerClientEvent('esx:showNotification', target, msg)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user