mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-09-04 08:13:21 +00:00
Add files
This commit is contained in:
+263
@@ -0,0 +1,263 @@
|
||||
ESX = nil
|
||||
|
||||
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
|
||||
|
||||
if Config.MaxInService ~= -1 then
|
||||
TriggerEvent('esx_service:activateService', 'police', Config.MaxInService)
|
||||
end
|
||||
|
||||
RegisterServerEvent('esx_policejob:giveWeapon')
|
||||
AddEventHandler('esx_policejob:giveWeapon', function(weapon, ammo)
|
||||
local xPlayer = ESX.GetPlayerFromId(source)
|
||||
xPlayer.addWeapon(weapon, ammo)
|
||||
end)
|
||||
|
||||
RegisterServerEvent('esx_policejob:confiscatePlayerItem')
|
||||
AddEventHandler('esx_policejob:confiscatePlayerItem', function(target, itemType, itemName, amount)
|
||||
|
||||
local sourceXPlayer = ESX.GetPlayerFromId(source)
|
||||
local targetXPlayer = ESX.GetPlayerFromId(target)
|
||||
|
||||
if itemType == 'item_standard' then
|
||||
|
||||
local label = sourceXPlayer.getInventoryItem(itemName).label
|
||||
|
||||
targetXPlayer.removeInventoryItem(itemName, amount)
|
||||
sourceXPlayer.addInventoryItem(itemName, amount)
|
||||
|
||||
TriggerClientEvent('esx:showNotification', sourceXPlayer.source, 'Vous avez confisqué ~y~x' .. amount .. ' ' .. label .. '~s~ à ~b~' .. targetXPlayer.name)
|
||||
TriggerClientEvent('esx:showNotification', targetXPlayer.source, '~b~' .. targetXPlayer.name .. '~s~ vous a confisqué ~y~x' .. amount .. ' ' .. label )
|
||||
|
||||
end
|
||||
|
||||
if itemType == 'item_account' then
|
||||
|
||||
targetXPlayer.removeAccountMoney(itemName, amount)
|
||||
sourceXPlayer.addAccountMoney(itemName, amount)
|
||||
|
||||
TriggerClientEvent('esx:showNotification', sourceXPlayer.source, 'Vous avez confisqué ~y~$' .. amount .. '~s~ à ~b~' .. targetXPlayer.name)
|
||||
TriggerClientEvent('esx:showNotification', targetXPlayer.source, '~b~' .. targetXPlayer.name .. '~s~ vous a confisqué ~y~$' .. amount)
|
||||
|
||||
end
|
||||
|
||||
if itemType == 'item_weapon' then
|
||||
|
||||
targetXPlayer.removeWeapon(itemName)
|
||||
sourceXPlayer.addWeapon(itemName, amount)
|
||||
|
||||
TriggerClientEvent('esx:showNotification', sourceXPlayer.source, 'Vous avez confisqué ~y~x1 ' .. ESX.GetWeaponLabel(itemName) .. '~s~ à ~b~' .. targetXPlayer.name)
|
||||
TriggerClientEvent('esx:showNotification', targetXPlayer.source, '~b~' .. targetXPlayer.name .. '~s~ vous a confisqué ~y~x1 ' .. ESX.GetWeaponLabel(itemName))
|
||||
|
||||
end
|
||||
|
||||
end)
|
||||
|
||||
RegisterServerEvent('esx_policejob:handcuff')
|
||||
AddEventHandler('esx_policejob:handcuff', function(target)
|
||||
TriggerClientEvent('esx_policejob:handcuff', target)
|
||||
end)
|
||||
|
||||
RegisterServerEvent('esx_policejob:putInVehicle')
|
||||
AddEventHandler('esx_policejob:putInVehicle', function(target)
|
||||
TriggerClientEvent('esx_policejob:putInVehicle', target)
|
||||
end)
|
||||
|
||||
ESX.RegisterServerCallback('esx_policejob:getOtherPlayerData', function(source, cb, target)
|
||||
|
||||
local xPlayer = ESX.GetPlayerFromId(target)
|
||||
|
||||
local data = {
|
||||
name = GetPlayerName(source),
|
||||
job = xPlayer.job,
|
||||
inventory = xPlayer.inventory,
|
||||
accounts = xPlayer.accounts,
|
||||
weapons = xPlayer.loadout
|
||||
}
|
||||
|
||||
TriggerEvent('esx_status:getStatus', _source, 'drunk', function(status)
|
||||
data.drunk = status:getPercent()
|
||||
end)
|
||||
|
||||
TriggerEvent('esx_license:getLicenses', _source, function(licenses)
|
||||
data.licenses = licenses
|
||||
end)
|
||||
|
||||
cb(data)
|
||||
|
||||
end)
|
||||
|
||||
ESX.RegisterServerCallback('esx_policejob:getFineList', function(source, cb, category)
|
||||
|
||||
MySQL.Async.fetchAll(
|
||||
'SELECT * FROM fine_types WHERE category = @category',
|
||||
{
|
||||
['@category'] = category
|
||||
},
|
||||
function(fines)
|
||||
cb(fines)
|
||||
end
|
||||
)
|
||||
|
||||
end)
|
||||
|
||||
ESX.RegisterServerCallback('esx_policejob:getVehicleInfos', function(source, cb, plate)
|
||||
|
||||
MySQL.Async.fetchAll(
|
||||
'SELECT * FROM owned_vehicles',
|
||||
{},
|
||||
function(result)
|
||||
|
||||
local foundIdentifier = nil
|
||||
|
||||
for i=1, #result, 1 do
|
||||
|
||||
local vehicleData = json.decode(result[i].vehicle)
|
||||
|
||||
if vehicleData.plate == plate then
|
||||
foundIdentifier = result[i].owner
|
||||
break
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if foundIdentifier ~= nil then
|
||||
|
||||
MySQL.Async.fetchAll(
|
||||
'SELECT * FROM users WHERE identifier = @identifier',
|
||||
{
|
||||
['@identifier'] = foundIdentifier
|
||||
},
|
||||
function(result)
|
||||
|
||||
local infos = {
|
||||
plate = plate,
|
||||
owner = result[1].name
|
||||
}
|
||||
|
||||
cb(infos)
|
||||
|
||||
end
|
||||
)
|
||||
|
||||
else
|
||||
|
||||
local infos = {
|
||||
plate = plate
|
||||
}
|
||||
|
||||
cb(infos)
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
)
|
||||
|
||||
end)
|
||||
|
||||
ESX.RegisterServerCallback('esx_policejob:getArmoryWeapons', function(source, cb)
|
||||
|
||||
TriggerEvent('esx_datastore:getSharedDataStore', 'society_police', function(store)
|
||||
|
||||
local weapons = store.get('weapons')
|
||||
|
||||
if weapons == nil then
|
||||
weapons = {}
|
||||
end
|
||||
|
||||
cb(weapons)
|
||||
|
||||
end)
|
||||
|
||||
end)
|
||||
|
||||
ESX.RegisterServerCallback('esx_policejob:addArmoryWeapon', function(source, cb, weaponName)
|
||||
|
||||
local xPlayer = ESX.GetPlayerFromId(source)
|
||||
|
||||
xPlayer.removeWeapon(weaponName)
|
||||
|
||||
TriggerEvent('esx_datastore:getSharedDataStore', 'society_police', function(store)
|
||||
|
||||
local weapons = store.get('weapons')
|
||||
|
||||
if weapons == nil then
|
||||
weapons = {}
|
||||
end
|
||||
|
||||
local foundWeapon = false
|
||||
|
||||
for i=1, #weapons, 1 do
|
||||
if weapons[i].name == weaponName then
|
||||
weapons[i].count = weapons[i].count + 1
|
||||
foundWeapon = true
|
||||
end
|
||||
end
|
||||
|
||||
if not foundWeapon then
|
||||
table.insert(weapons, {
|
||||
name = weaponName,
|
||||
count = 1
|
||||
})
|
||||
end
|
||||
|
||||
store.set('weapons', weapons)
|
||||
|
||||
cb()
|
||||
|
||||
end)
|
||||
|
||||
end)
|
||||
|
||||
ESX.RegisterServerCallback('esx_policejob:removeArmoryWeapon', function(source, cb, weaponName)
|
||||
|
||||
local xPlayer = ESX.GetPlayerFromId(source)
|
||||
|
||||
xPlayer.addWeapon(weaponName, 1000)
|
||||
|
||||
TriggerEvent('esx_datastore:getSharedDataStore', 'society_police', function(store)
|
||||
|
||||
local weapons = store.get('weapons')
|
||||
|
||||
if weapons == nil then
|
||||
weapons = {}
|
||||
end
|
||||
|
||||
local foundWeapon = false
|
||||
|
||||
for i=1, #weapons, 1 do
|
||||
if weapons[i].name == weaponName then
|
||||
weapons[i].count = (weapons[i].count > 0 and weapons[i].count - 1 or 0)
|
||||
foundWeapon = true
|
||||
end
|
||||
end
|
||||
|
||||
if not foundWeapon then
|
||||
table.insert(weapons, {
|
||||
name = weaponName,
|
||||
count = 0
|
||||
})
|
||||
end
|
||||
|
||||
store.set('weapons', weapons)
|
||||
|
||||
cb()
|
||||
|
||||
end)
|
||||
|
||||
end)
|
||||
|
||||
|
||||
ESX.RegisterServerCallback('esx_policejob:buy', function(source, cb, amount)
|
||||
|
||||
TriggerEvent('esx_addonaccount:getSharedAccount', 'society_police', function(account)
|
||||
|
||||
if account.money >= amount then
|
||||
account.removeMoney(amount)
|
||||
cb(true)
|
||||
else
|
||||
cb(false)
|
||||
end
|
||||
|
||||
end)
|
||||
|
||||
end)
|
||||
Reference in New Issue
Block a user