diff --git a/server/main.lua b/server/main.lua index 080333da..dd5d9cfb 100644 --- a/server/main.lua +++ b/server/main.lua @@ -3,7 +3,7 @@ ESX = nil TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) if Config.MaxInService ~= -1 then - TriggerEvent('esx_service:activateService', 'police', Config.MaxInService) + TriggerEvent('esx_service:activateService', 'police', Config.MaxInService) end TriggerEvent('esx_phone:registerNumber', 'police', _U('alert_police'), true, true) @@ -11,8 +11,8 @@ TriggerEvent('esx_society:registerSociety', 'police', 'Police', 'society_police' RegisterServerEvent('esx_policejob:giveWeapon') AddEventHandler('esx_policejob:giveWeapon', function(weapon, ammo) - local xPlayer = ESX.GetPlayerFromId(source) - xPlayer.addWeapon(weapon, ammo) + local xPlayer = ESX.GetPlayerFromId(source) + xPlayer.addWeapon(weapon, ammo) end) RegisterServerEvent('esx_policejob:confiscatePlayerItem') @@ -60,23 +60,34 @@ end) RegisterServerEvent('esx_policejob:handcuff') AddEventHandler('esx_policejob:handcuff', function(target) - TriggerClientEvent('esx_policejob:handcuff', target) + local xPlayer = ESX.GetPlayerFromId(source) + + if xPlayer.job.name == 'police' then + TriggerClientEvent('esx_policejob:handcuff', target) + else + print(('esx_policejob: %s attempted to handcuff a player (not cop)!'):format(xPlayer.identifier)) + end end) RegisterServerEvent('esx_policejob:drag') AddEventHandler('esx_policejob:drag', function(target) - local _source = source - TriggerClientEvent('esx_policejob:drag', target, _source) + TriggerClientEvent('esx_policejob:drag', target, source) end) RegisterServerEvent('esx_policejob:putInVehicle') AddEventHandler('esx_policejob:putInVehicle', function(target) - TriggerClientEvent('esx_policejob:putInVehicle', target) + TriggerClientEvent('esx_policejob:putInVehicle', target) end) RegisterServerEvent('esx_policejob:OutVehicle') AddEventHandler('esx_policejob:OutVehicle', function(target) - TriggerClientEvent('esx_policejob:OutVehicle', target) + local xPlayer = ESX.GetPlayerFromId(source) + + if xPlayer.job.name == 'police' then + TriggerClientEvent('esx_policejob:OutVehicle', target) + else + print(('esx_policejob: %s attempted to drag out from vehicle (not cop)!'):format(xPlayer.identifier)) + end end) RegisterServerEvent('esx_policejob:getStockItem') @@ -131,97 +142,84 @@ end) ESX.RegisterServerCallback('esx_policejob:getOtherPlayerData', function(source, cb, target) - if Config.EnableESXIdentity then + if Config.EnableESXIdentity then - local xPlayer = ESX.GetPlayerFromId(target) + local xPlayer = ESX.GetPlayerFromId(target) - local identifier = GetPlayerIdentifiers(target)[1] + local identifier = GetPlayerIdentifiers(target)[1] - local result = MySQL.Sync.fetchAll("SELECT * FROM users WHERE identifier = @identifier", { - ['@identifier'] = identifier - }) + local result = MySQL.Sync.fetchAll("SELECT * FROM users WHERE identifier = @identifier", { + ['@identifier'] = identifier + }) - local user = result[1] - local firstname = user['firstname'] - local lastname = user['lastname'] - local sex = user['sex'] - local dob = user['dateofbirth'] - local height = user['height'] .. " Inches" + 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 - 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 - } + 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 + } - TriggerEvent('esx_status:getStatus', target, 'drunk', function(status) + TriggerEvent('esx_status:getStatus', target, 'drunk', function(status) + if status ~= nil then + data.drunk = math.floor(status.percent) + end + end) - if status ~= nil then - data.drunk = math.floor(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) + else - if Config.EnableLicenses then + local xPlayer = ESX.GetPlayerFromId(target) - TriggerEvent('esx_license:getLicenses', target, function(licenses) - data.licenses = licenses - cb(data) - end) + local data = { + name = GetPlayerName(target), + job = xPlayer.job, + inventory = xPlayer.inventory, + accounts = xPlayer.accounts, + weapons = xPlayer.loadout + } - else - cb(data) - end + TriggerEvent('esx_status:getStatus', target, 'drunk', function(status) + if status ~= nil then + data.drunk = math.floor(status.percent) + end + end) - else + TriggerEvent('esx_license:getLicenses', target, function(licenses) + data.licenses = licenses + end) - local xPlayer = ESX.GetPlayerFromId(target) + cb(data) - 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 ~= nil then - data.drunk = math.floor(status.percent) - end - - end) - - TriggerEvent('esx_license:getLicenses', target, function(licenses) - data.licenses = licenses - end) - - cb(data) - - end + end 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 - ) - + 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) @@ -255,159 +253,145 @@ ESX.RegisterServerCallback('esx_policejob:getVehicleInfos', function(source, cb, end) ESX.RegisterServerCallback('esx_policejob:getVehicleFromPlate', function(source, cb, plate) - MySQL.Async.fetchAll( - 'SELECT * FROM owned_vehicles WHERE plate = @plate', - { - ['@plate'] = plate - }, - function(result) - if result[1] ~= nil then + MySQL.Async.fetchAll('SELECT * FROM owned_vehicles WHERE plate = @plate', { + ['@plate'] = plate + }, function(result) + if result[1] ~= nil then - MySQL.Async.fetchAll('SELECT * FROM users WHERE identifier = @identifier', { - ['@identifier'] = result[1].owner - }, function(result2) - - if Config.EnableESXIdentity then - cb(result2[1].firstname .. ' ' .. result2[1].lastname, true) - else - cb(result2[1].name, true) - end + MySQL.Async.fetchAll('SELECT * FROM users WHERE identifier = @identifier', { + ['@identifier'] = result[1].owner + }, function(result2) - end) - else - cb(_U('unknown'), false) - end + if Config.EnableESXIdentity then + cb(result2[1].firstname .. ' ' .. result2[1].lastname, true) + else + cb(result2[1].name, true) + end + + end) + else + cb(_U('unknown'), false) end - ) + end) end) ESX.RegisterServerCallback('esx_policejob:getArmoryWeapons', function(source, cb) - TriggerEvent('esx_datastore:getSharedDataStore', 'society_police', function(store) + TriggerEvent('esx_datastore:getSharedDataStore', 'society_police', function(store) - local weapons = store.get('weapons') + local weapons = store.get('weapons') - if weapons == nil then - weapons = {} - end + if weapons == nil then + weapons = {} + end - cb(weapons) + cb(weapons) - end) + end) end) ESX.RegisterServerCallback('esx_policejob:addArmoryWeapon', function(source, cb, weaponName, removeWeapon) - local xPlayer = ESX.GetPlayerFromId(source) + local xPlayer = ESX.GetPlayerFromId(source) - if removeWeapon then - xPlayer.removeWeapon(weaponName) - end + if removeWeapon then + xPlayer.removeWeapon(weaponName) + end - TriggerEvent('esx_datastore:getSharedDataStore', 'society_police', function(store) + TriggerEvent('esx_datastore:getSharedDataStore', 'society_police', function(store) - local weapons = store.get('weapons') + local weapons = store.get('weapons') - if weapons == nil then - weapons = {} - end + if weapons == nil then + weapons = {} + end - local foundWeapon = false + 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 + for i=1, #weapons, 1 do + if weapons[i].name == weaponName then + weapons[i].count = weapons[i].count + 1 + foundWeapon = true + break + end + end - if not foundWeapon then - table.insert(weapons, { - name = weaponName, - count = 1 - }) - end + if not foundWeapon then + table.insert(weapons, { + name = weaponName, + count = 1 + }) + end - store.set('weapons', weapons) - - cb() - - end) + store.set('weapons', weapons) + cb() + end) end) ESX.RegisterServerCallback('esx_policejob:removeArmoryWeapon', function(source, cb, weaponName) - local xPlayer = ESX.GetPlayerFromId(source) + local xPlayer = ESX.GetPlayerFromId(source) - xPlayer.addWeapon(weaponName, 1000) + xPlayer.addWeapon(weaponName, 500) - TriggerEvent('esx_datastore:getSharedDataStore', 'society_police', function(store) + TriggerEvent('esx_datastore:getSharedDataStore', 'society_police', function(store) - local weapons = store.get('weapons') + local weapons = store.get('weapons') - if weapons == nil then - weapons = {} - end + if weapons == nil then + weapons = {} + end - local foundWeapon = false + 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 + 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 + break + end + end - if not foundWeapon then - table.insert(weapons, { - name = weaponName, - count = 0 - }) - end + if not foundWeapon then + table.insert(weapons, { + name = weaponName, + count = 0 + }) + end - store.set('weapons', weapons) - - cb() - - 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) + TriggerEvent('esx_addonaccount:getSharedAccount', 'society_police', function(account) + if account.money >= amount then + account.removeMoney(amount) + cb(true) + else + cb(false) + end + end) end) ESX.RegisterServerCallback('esx_policejob:getStockItems', function(source, cb) - - TriggerEvent('esx_addoninventory:getSharedInventory', 'society_police', function(inventory) - cb(inventory.items) - end) - + TriggerEvent('esx_addoninventory:getSharedInventory', 'society_police', function(inventory) + cb(inventory.items) + end) end) ESX.RegisterServerCallback('esx_policejob:getPlayerInventory', function(source, cb) + local xPlayer = ESX.GetPlayerFromId(source) + local items = xPlayer.inventory - local xPlayer = ESX.GetPlayerFromId(source) - local items = xPlayer.inventory - - cb({ - items = items - }) - + cb( { items = items } ) end) AddEventHandler('playerDropped', function()