Minor code cleanup, use latest esx_identity code

This commit is contained in:
ElPumpo
2020-01-19 16:30:30 +01:00
parent 99f9a30cd8
commit d733fe5428
12 changed files with 88 additions and 186 deletions
+1 -2
View File
@@ -41,7 +41,7 @@ git clone https://github.com/ESX-Org/esx_policejob [esx]/esx_policejob
## Installation
- Import `esx_policejob.sql` in your database
- Add this in your server.cfg :
- Add this to your server.cfg:
```
start esx_policejob
@@ -52,7 +52,6 @@ start esx_policejob
* If you want license management you have to set `Config.EnableLicenses` to `true` in `config.lua`
* If you want service management you have to set `Config.MaxInService` to a higher value than `-1` in `config.lua`
# Legal
### License
esx_policejob - police script for ESX
+16 -67
View File
@@ -610,7 +610,7 @@ function OpenPoliceActionsMenu()
if data.current.value == 'citizen_interaction' then
local elements = {
{label = _U('id_card'), value = 'identity_card'},
{label = _U('search'), value = 'body_search'},
{label = _U('search'), value = 'search'},
{label = _U('handcuff'), value = 'handcuff'},
{label = _U('drag'), value = 'drag'},
{label = _U('put_in_vehicle'), value = 'put_in_vehicle'},
@@ -634,8 +634,7 @@ function OpenPoliceActionsMenu()
if action == 'identity_card' then
OpenIdentityCardMenu(closestPlayer)
elseif action == 'body_search' then
TriggerServerEvent('esx_policejob:message', GetPlayerServerId(closestPlayer), _U('being_searched'))
elseif action == 'search' then
OpenBodySearchMenu(closestPlayer)
elseif action == 'handcuff' then
TriggerServerEvent('esx_policejob:handcuff', GetPlayerServerId(closestPlayer))
@@ -765,58 +764,15 @@ end
function OpenIdentityCardMenu(player)
ESX.TriggerServerCallback('esx_policejob:getOtherPlayerData', function(data)
local elements = {}
local nameLabel = _U('name', data.name)
local jobLabel, sexLabel, dobLabel, heightLabel, idLabel
if data.job.grade_label and data.job.grade_label ~= '' then
jobLabel = _U('job', data.job.label .. ' - ' .. data.job.grade_label)
else
jobLabel = _U('job', data.job.label)
end
if Config.EnableESXIdentity then
nameLabel = _U('name', data.firstname .. ' ' .. data.lastname)
if data.sex then
if string.lower(data.sex) == 'm' then
sexLabel = _U('sex', _U('male'))
else
sexLabel = _U('sex', _U('female'))
end
else
sexLabel = _U('sex', _U('unknown'))
end
if data.dob then
dobLabel = _U('dob', data.dob)
else
dobLabel = _U('dob', _U('unknown'))
end
if data.height then
heightLabel = _U('height', data.height)
else
heightLabel = _U('height', _U('unknown'))
end
if data.name then
idLabel = _U('id', data.name)
else
idLabel = _U('id', _U('unknown'))
end
end
local elements = {
{label = nameLabel},
{label = jobLabel}
{label = _U('name', data.name)},
{label = _U('job', ('%s - %s'):format(data.job.label, data.job.grade_label))}
}
if Config.EnableESXIdentity then
table.insert(elements, {label = sexLabel})
table.insert(elements, {label = dobLabel})
table.insert(elements, {label = heightLabel})
table.insert(elements, {label = idLabel})
table.insert(elements, {label = _U('sex', _U(data.sex))})
table.insert(elements, {label = _U('dob', data.dob)})
table.insert(elements, {label = _U('height', data.height)})
end
if data.drunk then
@@ -949,8 +905,7 @@ function OpenFineCategoryMenu(player, category)
end
function LookupVehicle()
ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), 'lookup_vehicle',
{
ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), 'lookup_vehicle', {
title = _U('search_database_title'),
}, function(data, menu)
local length = string.len(data.value)
@@ -972,32 +927,26 @@ function LookupVehicle()
end
function ShowPlayerLicense(player)
local elements, targetName = {}
local elements = {}
ESX.TriggerServerCallback('esx_policejob:getOtherPlayerData', function(data)
if data.licenses then
for i=1, #data.licenses, 1 do
if data.licenses[i].label and data.licenses[i].type then
ESX.TriggerServerCallback('esx_policejob:getOtherPlayerData', function(playerData)
if playerData.licenses then
for i=1, #playerData.licenses, 1 do
if playerData.licenses[i].label and playerData.licenses[i].type then
table.insert(elements, {
label = data.licenses[i].label,
type = data.licenses[i].type
label = playerData.licenses[i].label,
type = playerData.licenses[i].type
})
end
end
end
if Config.EnableESXIdentity then
targetName = data.firstname .. ' ' .. data.lastname
else
targetName = data.name
end
ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'manage_license', {
title = _U('license_revoke'),
align = 'top-left',
elements = elements,
}, function(data, menu)
ESX.ShowNotification(_U('licence_you_revoked', data.current.label, targetName))
ESX.ShowNotification(_U('licence_you_revoked', data.current.label, playerData.name))
TriggerServerEvent('esx_policejob:message', GetPlayerServerId(player), _U('license_revoked', data.current.label))
TriggerServerEvent('esx_license:removeLicense', GetPlayerServerId(player), data.current.type)
-1
View File
@@ -108,7 +108,6 @@ Locales['br'] = {
['sex'] = 'sex: %s',
['dob'] = 'DOB: %s',
['height'] = 'height: %s',
['id'] = 'ID: %s',
['bac'] = 'BAC: %s',
['unknown'] = 'unknown',
['male'] = 'male',
-1
View File
@@ -108,7 +108,6 @@ Locales['de'] = {
['sex'] = 'sex: %s',
['dob'] = 'DOB: %s',
['height'] = 'height: %s',
['id'] = 'ID: %s',
['bac'] = 'BAC: %s',
['unknown'] = 'unknown',
['male'] = 'male',
+1 -2
View File
@@ -108,7 +108,6 @@ Locales['en'] = {
['sex'] = 'sex: %s',
['dob'] = 'DOB: %s',
['height'] = 'height: %s',
['id'] = 'ID: %s',
['bac'] = 'BAC: %s',
['unknown'] = 'unknown',
['male'] = 'male',
@@ -117,7 +116,7 @@ Locales['en'] = {
['guns_label'] = '--- Guns ---',
['inventory_label'] = '--- Inventory ---',
['license_label'] = ' --- Licenses ---',
['confiscate'] = 'confiscate %s',
['confiscate'] = 'sieze illegal items',
['confiscate_weapon'] = 'confiscate %s with %s bullets',
['confiscate_inv'] = 'confiscate %sx %s',
['confiscate_dirty'] = 'confiscate dirty money: <span style="color:red;">$%s</span>',
-1
View File
@@ -108,7 +108,6 @@ Locales['es'] = {
['sex'] = 'sex: %s',
['dob'] = 'DOB: %s',
['height'] = 'height: %s',
['id'] = 'ID: %s',
['bac'] = 'BAC: %s',
['unknown'] = 'unknown',
['male'] = 'male',
-1
View File
@@ -108,7 +108,6 @@ Locales['fi'] = {
['sex'] = 'sukupuoli: %s',
['dob'] = 'syntymäaika: %s',
['height'] = 'pituus: %s',
['id'] = 'ID: %s',
['bac'] = 'alkometri: %s',
['unknown'] = 'tuntematon',
['male'] = 'mies',
-1
View File
@@ -108,7 +108,6 @@ Locales['fr'] = {
['sex'] = 'sexe: %s',
['dob'] = 'DOB: %s',
['height'] = 'taille: %s',
['id'] = 'ID: %s',
['bac'] = 'BAC: %s',
['unknown'] = 'inconnu',
['male'] = 'homme',
-1
View File
@@ -108,7 +108,6 @@ Locales['ko'] = {
['sex'] = '성별: %s',
['dob'] = '생일: %s',
['height'] = '키: %s',
['id'] = 'ID: %s',
['bac'] = '혈중 알코올 농도: %s',
['unknown'] = '알 수 없는',
['male'] = '남자',
+1 -2
View File
@@ -108,8 +108,7 @@ Locales['pl'] = {
['sex'] = 'płeć: %s',
['dob'] = 'data urodzenia: %s',
['height'] = 'wzrost: %s',
['id'] = 'iD: %s',
['bac'] = 'bAC: %s',
['bac'] = 'BAC: %s',
['unknown'] = 'nieznany',
['male'] = 'mężczyzna',
['female'] = 'kobieta',
-1
View File
@@ -108,7 +108,6 @@ Locales['sv'] = {
['sex'] = 'kön: %s',
['dob'] = 'födelsedatum: %s',
['height'] = 'längd: %s',
['id'] = 'ID: %s',
['bac'] = 'alkohol i blodet: %s',
['unknown'] = 'okänt',
['male'] = 'man',
+69 -106
View File
@@ -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)