diff --git a/client/main.lua b/client/main.lua
index 16aa6c8..8c9ffa3 100644
--- a/client/main.lua
+++ b/client/main.lua
@@ -1,4 +1,4 @@
-local CurrentActionData, handcuffTimer, dragStatus, blipsCops, currentTask = {}, {}, {}, {}, {}
+local CurrentActionData, handcuffTimer, dragStatus, currentTask = {}, {}, {}, {}
local HasAlreadyEnteredMarker, isDead, isHandcuffed, hasAlreadyJoined, playerInService = false, false, false, false, false
local LastStation, LastPart, LastPartNum, LastEntity, CurrentAction, CurrentActionMsg
dragStatus.isDragged, isInShopMenu = false, false
@@ -103,7 +103,6 @@ function OpenCloakroomMenu()
TriggerServerEvent('esx_service:notifyAllInService', notification, 'police')
TriggerServerEvent('esx_service:disableService', 'police')
- TriggerEvent('esx_policejob:updateBlip')
ESX.ShowNotification(TranslateCap('service_out'))
end
end, 'police')
@@ -132,7 +131,6 @@ function OpenCloakroomMenu()
}
TriggerServerEvent('esx_service:notifyAllInService', notification, 'police')
- TriggerEvent('esx_policejob:updateBlip')
ESX.ShowNotification(TranslateCap('service_in'))
end
end, 'police')
@@ -148,7 +146,6 @@ function OpenCloakroomMenu()
}
TriggerServerEvent('esx_service:notifyAllInService', notification, 'police')
- TriggerEvent('esx_policejob:updateBlip')
ESX.ShowNotification(TranslateCap('service_in'))
end
@@ -946,14 +943,6 @@ function OpenPutStocksMenu()
end)
end
-function OnPlayerData(k, v)
- if k ~= 'job' then return end
- if v.name == 'police' then
- Wait(1000)
- TriggerServerEvent('esx_policejob:forceBlip')
- end
-end
-
RegisterNetEvent('esx_phone:loaded')
AddEventHandler('esx_phone:loaded', function(phoneNumber, contacts)
local specialContact = {
@@ -1036,35 +1025,11 @@ AddEventHandler('esx_policejob:hasExitedEntityZone', function(entity)
end
end)
-RegisterNetEvent('esx_policejob:handcuff')
-AddEventHandler('esx_policejob:handcuff', function()
+RegisterNetEvent('esx_policejob:handcuff', function()
isHandcuffed = not isHandcuffed
local playerPed = PlayerPedId()
- if isHandcuffed then
- RequestAnimDict('mp_arresting')
- while not HasAnimDictLoaded('mp_arresting') do
- Wait(100)
- end
-
- TaskPlayAnim(playerPed, 'mp_arresting', 'idle', 8.0, -8, -1, 49, 0, 0, 0, 0)
- RemoveAnimDict('mp_arresting')
-
- SetEnableHandcuffs(playerPed, true)
- DisablePlayerFiring(playerPed, true)
- SetCurrentPedWeapon(playerPed, `WEAPON_UNARMED`, true) -- unarm player
- SetPedCanPlayGestureAnims(playerPed, false)
- FreezeEntityPosition(playerPed, true)
- DisplayRadar(false)
-
- if Config.EnableHandcuffTimer then
- if handcuffTimer.active then
- ESX.ClearTimeout(handcuffTimer.task)
- end
-
- StartHandcuffTimer()
- end
- else
+ if not isHandcuffed then
if Config.EnableHandcuffTimer and handcuffTimer.active then
ESX.ClearTimeout(handcuffTimer.task)
end
@@ -1075,37 +1040,57 @@ AddEventHandler('esx_policejob:handcuff', function()
SetPedCanPlayGestureAnims(playerPed, true)
FreezeEntityPosition(playerPed, false)
DisplayRadar(true)
+ return
+ end
+
+ RequestAnimDict('mp_arresting')
+ while not HasAnimDictLoaded('mp_arresting') do
+ Wait(100)
end
-end)
-RegisterNetEvent('esx_policejob:unrestrain')
-AddEventHandler('esx_policejob:unrestrain', function()
- if isHandcuffed then
- local playerPed = PlayerPedId()
- isHandcuffed = false
+ TaskPlayAnim(playerPed, 'mp_arresting', 'idle', 8.0, -8, -1, 49, 0, 0, 0, 0)
+ RemoveAnimDict('mp_arresting')
- ClearPedSecondaryTask(playerPed)
- SetEnableHandcuffs(playerPed, false)
- DisablePlayerFiring(playerPed, false)
- SetPedCanPlayGestureAnims(playerPed, true)
- FreezeEntityPosition(playerPed, false)
- DisplayRadar(true)
+ SetEnableHandcuffs(playerPed, true)
+ DisablePlayerFiring(playerPed, true)
+ SetCurrentPedWeapon(playerPed, `WEAPON_UNARMED`, true) -- unarm player
+ SetPedCanPlayGestureAnims(playerPed, false)
+ FreezeEntityPosition(playerPed, true)
+ DisplayRadar(false)
- -- end timer
- if Config.EnableHandcuffTimer and handcuffTimer.active then
+ if Config.EnableHandcuffTimer then
+ if handcuffTimer.active then
ESX.ClearTimeout(handcuffTimer.task)
end
+
+ StartHandcuffTimer()
end
end)
-RegisterNetEvent('esx_policejob:drag')
-AddEventHandler('esx_policejob:drag', function(copId)
- if isHandcuffed then
- dragStatus.isDragged = not dragStatus.isDragged
- dragStatus.CopId = copId
+RegisterNetEvent('esx_policejob:unrestrain', function()
+ if not isHandcuffed then return end
+ local playerPed = PlayerPedId()
+ isHandcuffed = false
+
+ ClearPedSecondaryTask(playerPed)
+ SetEnableHandcuffs(playerPed, false)
+ DisablePlayerFiring(playerPed, false)
+ SetPedCanPlayGestureAnims(playerPed, true)
+ FreezeEntityPosition(playerPed, false)
+ DisplayRadar(true)
+
+ -- end timer
+ if Config.EnableHandcuffTimer and handcuffTimer.active then
+ ESX.ClearTimeout(handcuffTimer.task)
end
end)
+RegisterNetEvent('esx_policejob:drag', function(copId)
+ if not isHandcuffed then return end
+ dragStatus.isDragged = not dragStatus.isDragged
+ dragStatus.CopId = copId
+end)
+
CreateThread(function()
local wasDragged
@@ -1136,39 +1121,36 @@ CreateThread(function()
end
end)
-RegisterNetEvent('esx_policejob:putInVehicle')
-AddEventHandler('esx_policejob:putInVehicle', function()
- if isHandcuffed then
- local playerPed = PlayerPedId()
- local vehicle, distance = ESX.Game.GetClosestVehicle()
+RegisterNetEvent('esx_policejob:putInVehicle', function()
+ if not isHandcuffed then return end
+ local playerPed = PlayerPedId()
+ local vehicle, distance = ESX.Game.GetClosestVehicle()
- if vehicle and distance < 5 then
- local maxSeats, freeSeat = GetVehicleMaxNumberOfPassengers(vehicle)
+ if vehicle and distance < 5 then
+ local maxSeats, freeSeat = GetVehicleMaxNumberOfPassengers(vehicle)
- for i=maxSeats - 1, 0, -1 do
- if IsVehicleSeatFree(vehicle, i) then
- freeSeat = i
- break
- end
+ for i=maxSeats - 1, 0, -1 do
+ if IsVehicleSeatFree(vehicle, i) then
+ freeSeat = i
+ break
end
+ end
- if freeSeat then
- TaskWarpPedIntoVehicle(playerPed, vehicle, freeSeat)
- dragStatus.isDragged = false
- end
+ if freeSeat then
+ TaskWarpPedIntoVehicle(playerPed, vehicle, freeSeat)
+ dragStatus.isDragged = false
end
end
end)
-RegisterNetEvent('esx_policejob:OutVehicle')
-AddEventHandler('esx_policejob:OutVehicle', function()
+RegisterNetEvent('esx_policejob:OutVehicle', function()
local GetVehiclePedIsIn = GetVehiclePedIsIn
local IsPedSittingInAnyVehicle = IsPedSittingInAnyVehicle
local TaskLeaveVehicle = TaskLeaveVehicle
- if IsPedSittingInAnyVehicle(ESX.PlayerData.ped) then
- local vehicle = GetVehiclePedIsIn(ESX.PlayerData.ped, false)
- TaskLeaveVehicle(ESX.PlayerData.ped, vehicle, 64)
- end
+ if not IsPedSittingInAnyVehicle(ESX.PlayerData.ped) then return end
+
+ local vehicle = GetVehiclePedIsIn(ESX.PlayerData.ped, false)
+ TaskLeaveVehicle(ESX.PlayerData.ped, vehicle, 64)
end)
-- Handcuff
@@ -1482,62 +1464,8 @@ CreateThread(function()
Sleep = 0
ESX.ShowHelpNotification(CurrentActionMsg)
end
- Wait(Sleep)
- end
-end)
-
--- Create blip for colleagues
-function createBlip(id)
- local ped = GetPlayerPed(id)
- local blip = GetBlipFromEntity(ped)
-
- if not DoesBlipExist(blip) then -- Add blip and create head display on player
- blip = AddBlipForEntity(ped)
- SetBlipSprite(blip, 1)
- ShowHeadingIndicatorOnBlip(blip, true) -- Player Blip indicator
- SetBlipRotation(blip, math.ceil(GetEntityHeading(ped))) -- update rotation
- SetBlipNameToPlayerName(blip, id) -- update blip name
- SetBlipScale(blip, 0.85) -- set scale
- SetBlipAsShortRange(blip, true)
-
- table.insert(blipsCops, blip) -- add blip to array so we can remove it later
- end
-end
-
-RegisterNetEvent('esx_policejob:updateBlip')
-AddEventHandler('esx_policejob:updateBlip', function()
-
- -- Refresh all blips
- for k, existingBlip in pairs(blipsCops) do
- RemoveBlip(existingBlip)
- end
-
- -- Clean the blip table
- blipsCops = {}
-
- -- Enable blip?
- if Config.EnableESXService and not playerInService then
- return
- end
-
- if not Config.EnableJobBlip then
- return
- end
-
- -- Is the player a cop? In that case show all the blips for other cops
- if ESX.PlayerData.job and ESX.PlayerData.job.name == 'police' then
- ESX.TriggerServerCallback('esx_society:getOnlinePlayers', function(players)
- for i=1, #players, 1 do
- if players[i].job.name == 'police' then
- local id = GetPlayerFromServerId(players[i].source)
- if NetworkIsPlayerActive(id) and GetPlayerPed(id) ~= PlayerPedId() then
- createBlip(id)
- end
- end
- end
- end)
+ Wait(Sleep)
end
-
end)
AddEventHandler('esx:onPlayerSpawn', function(spawn)
@@ -1593,9 +1521,3 @@ function ImpoundVehicle(vehicle)
ESX.ShowNotification(TranslateCap('impound_successful'))
currentTask.busy = false
end
-
-if ESX.PlayerLoaded and ESX.PlayerData.job == 'police' then
- SetTimeout(1000, function()
- TriggerServerEvent('esx_policejob:forceBlip')
- end)
-end
diff --git a/client/vehicle.lua b/client/vehicle.lua
index 9ac134a..4aeddd5 100644
--- a/client/vehicle.lua
+++ b/client/vehicle.lua
@@ -16,95 +16,84 @@ function OpenVehicleSpawnerMenu(type, station, part, partNum)
local shopCoords = Config.PoliceStations[station][part][partNum].InsideShop
local authorizedVehicles = Config.AuthorizedVehicles[type][ESX.PlayerData.job.grade_name]
- if authorizedVehicles then
- if #authorizedVehicles > 0 then
- for k,vehicle in ipairs(authorizedVehicles) do
- if IsModelInCdimage(vehicle.model) then
- local vehicleLabel = GetLabelText(GetDisplayNameFromVehicleModel(vehicle.model))
-
- shopElements[#shopElements+1] = {
- icon = 'fas fa-car',
- title = ('%s - %s'):format(vehicleLabel, TranslateCap('shop_item', ESX.Math.GroupDigits(vehicle.price))),
- name = vehicleLabel,
- model = vehicle.model,
- price = vehicle.price,
- props = vehicle.props,
- type = type
- }
- end
- end
-
- if #shopElements > 0 then
- OpenShopMenu(shopElements, playerCoords, shopCoords)
- else
- ESX.ShowNotification(TranslateCap('garage_notauthorized'))
- end
- else
- ESX.ShowNotification(TranslateCap('garage_notauthorized'))
+ if not authorizedVehicles or #authorizedVehicles < 1 then
+ return ESX.ShowNotification(TranslateCap('garage_notauthorized'))
+ end
+
+ for k, vehicle in ipairs(authorizedVehicles) do
+ if IsModelInCdimage(vehicle.model) then
+ local vehicleLabel = GetLabelText(GetDisplayNameFromVehicleModel(vehicle.model))
+
+ shopElements[#shopElements+1] = {
+ icon = 'fas fa-car',
+ title = ('%s - %s'):format(vehicleLabel, TranslateCap('shop_item', ESX.Math.GroupDigits(vehicle.price))),
+ name = vehicleLabel,
+ model = vehicle.model,
+ price = vehicle.price,
+ props = vehicle.props,
+ type = type
+ }
end
- else
- ESX.ShowNotification(TranslateCap('garage_notauthorized'))
end
+
+ if #shopElements < 1 then return ESX.ShowNotification(TranslateCap('garage_notauthorized')) end
+
+ OpenShopMenu(shopElements, playerCoords, shopCoords)
elseif element.action == "garage" then
local garage = {
{unselectable = true, icon = "fas fa-car", title = "Garage"}
}
ESX.TriggerServerCallback('esx_vehicleshop:retrieveJobVehicles', function(jobVehicles)
- if #jobVehicles > 0 then
- local allVehicleProps = {}
+ if #jobVehicles < 1 then return ESX.ShowNotification(TranslateCap('garage_empty')) end
+ local allVehicleProps = {}
- for k,v in ipairs(jobVehicles) do
- local props = json.decode(v.vehicle)
+ for k,v in ipairs(jobVehicles) do
+ local props = json.decode(v.vehicle)
- if IsModelInCdimage(props.model) then
- local vehicleName = GetLabelText(GetDisplayNameFromVehicleModel(props.model))
- local label = ('%s - %s: '):format(vehicleName, props.plate)
+ if IsModelInCdimage(props.model) then
+ local vehicleName = GetLabelText(GetDisplayNameFromVehicleModel(props.model))
+ local label = ('%s - %s: '):format(vehicleName, props.plate)
- if v.stored == 1 or v.stored == true then
- label = label .. ('%s'):format(TranslateCap('garage_stored'))
- elseif v.stored == 0 or v.stored == false then
- label = label .. ('%s'):format(TranslateCap('garage_notstored'))
- end
+ if v.stored == 1 or v.stored == true then
+ label = label .. ('%s'):format(TranslateCap('garage_stored'))
+ elseif v.stored == 0 or v.stored == false then
+ label = label .. ('%s'):format(TranslateCap('garage_notstored'))
+ end
- garage[#garage+1] = {
- icon = 'fas fa-car',
- title = label,
- stored = v.stored,
- model = props.model,
- plate = props.plate
- }
+ garage[#garage+1] = {
+ icon = 'fas fa-car',
+ title = label,
+ stored = v.stored,
+ model = props.model,
+ plate = props.plate
+ }
- allVehicleProps[props.plate] = props
- end
+ allVehicleProps[props.plate] = props
end
+ end
- if #garage > 0 then
- ESX.OpenContext("right", garage, function(menuG,elementG)
- if elementG.stored == 1 or elementG.stored == true then
- local foundSpawn, spawnPoint = GetAvailableVehicleSpawnPoint(station, part, partNum)
+ if #garage < 1 then return ESX.ShowNotification(TranslateCap('garage_empty')) end
+
+ ESX.OpenContext("right", garage, function(menuG,elementG)
+ if elementG.stored == 1 or elementG.stored == true then
+ local foundSpawn, spawnPoint = GetAvailableVehicleSpawnPoint(station, part, partNum)
- if foundSpawn then
- ESX.CloseContext()
+ if foundSpawn then
+ ESX.CloseContext()
- ESX.Game.SpawnVehicle(elementG.model, spawnPoint.coords, spawnPoint.heading, function(vehicle)
- local vehicleProps = allVehicleProps[elementG.plate]
- ESX.Game.SetVehicleProperties(vehicle, vehicleProps)
+ ESX.Game.SpawnVehicle(elementG.model, spawnPoint.coords, spawnPoint.heading, function(vehicle)
+ local vehicleProps = allVehicleProps[elementG.plate]
+ ESX.Game.SetVehicleProperties(vehicle, vehicleProps)
- TriggerServerEvent('esx_vehicleshop:setJobVehicleState', elementG.plate, false)
- ESX.ShowNotification(TranslateCap('garage_released'))
- end)
- end
- else
- ESX.ShowNotification(TranslateCap('garage_notavailable'))
- end
- end)
+ TriggerServerEvent('esx_vehicleshop:setJobVehicleState', elementG.plate, false)
+ ESX.ShowNotification(TranslateCap('garage_released'))
+ end)
+ end
else
- ESX.ShowNotification(TranslateCap('garage_empty'))
+ ESX.ShowNotification(TranslateCap('garage_notavailable'))
end
- else
- ESX.ShowNotification(TranslateCap('garage_empty'))
- end
+ end)
end, type)
elseif element.action == "store_garage" then
StoreNearbyVehicle(playerCoords)
@@ -115,68 +104,61 @@ end
function StoreNearbyVehicle(playerCoords)
local vehicles, plates, index = ESX.Game.GetVehiclesInArea(playerCoords, 30.0), {}, {}
- if next(vehicles) then
- for i = 1, #vehicles do
- local vehicle = vehicles[i]
+ if not next(vehicles) then return ESX.ShowNotification(TranslateCap('garage_store_nearby')) end
+ for i = 1, #vehicles do
+ local vehicle = vehicles[i]
- -- Make sure the vehicle we're saving is empty, or else it won't be deleted
- if GetVehicleNumberOfPassengers(vehicle) == 0 and IsVehicleSeatFree(vehicle, -1) then
- local plate = ESX.Math.Trim(GetVehicleNumberPlateText(vehicle))
- plates[#plates + 1] = plate
- index[plate] = vehicle
- end
+ -- Make sure the vehicle we're saving is empty, or else it won't be deleted
+ if GetVehicleNumberOfPassengers(vehicle) == 0 and IsVehicleSeatFree(vehicle, -1) then
+ local plate = ESX.Math.Trim(GetVehicleNumberPlateText(vehicle))
+ plates[#plates + 1] = plate
+ index[plate] = vehicle
end
- else
- ESX.ShowNotification(TranslateCap('garage_store_nearby'))
- return
end
ESX.TriggerServerCallback('esx_policejob:storeNearbyVehicle', function(plate)
- if plate then
- local vehicleId = index[plate]
- local attempts = 0
- ESX.Game.DeleteVehicle(vehicleId)
- local isBusy = true
-
- CreateThread(function()
- BeginTextCommandBusyspinnerOn('STRING')
- AddTextComponentSubstringPlayerName(TranslateCap('garage_storing'))
- EndTextCommandBusyspinnerOn(4)
-
- while isBusy do
- Wait(100)
- end
+ if not plate then return ESX.ShowNotification(TranslateCap('garage_has_notstored')) end
+ local vehicleId = index[plate]
+ local attempts = 0
+ ESX.Game.DeleteVehicle(vehicleId)
+ local isBusy = true
+
+ CreateThread(function()
+ BeginTextCommandBusyspinnerOn('STRING')
+ AddTextComponentSubstringPlayerName(TranslateCap('garage_storing'))
+ EndTextCommandBusyspinnerOn(4)
+
+ while isBusy do
+ Wait(100)
+ end
- BusyspinnerOff()
- end)
+ BusyspinnerOff()
+ end)
- -- Workaround for vehicle not deleting when other players are near it.
- while DoesEntityExist(vehicleId) do
- Wait(500)
- attempts = attempts + 1
+ -- Workaround for vehicle not deleting when other players are near it.
+ while DoesEntityExist(vehicleId) do
+ Wait(500)
+ attempts = attempts + 1
- -- Give up
- if attempts > 30 then
- break
- end
+ -- Give up
+ if attempts > 30 then
+ break
+ end
- vehicles = ESX.Game.GetVehiclesInArea(playerCoords, 30.0)
- if #vehicles > 0 then
- for i = 1, #vehicles do
- local vehicle = vehicles[i]
- if ESX.Math.Trim(GetVehicleNumberPlateText(vehicle)) == plate then
- ESX.Game.DeleteVehicle(vehicle)
- break
- end
+ vehicles = ESX.Game.GetVehiclesInArea(playerCoords, 30.0)
+ if #vehicles > 0 then
+ for i = 1, #vehicles do
+ local vehicle = vehicles[i]
+ if ESX.Math.Trim(GetVehicleNumberPlateText(vehicle)) == plate then
+ ESX.Game.DeleteVehicle(vehicle)
+ break
end
end
end
-
- isBusy = false
- ESX.ShowNotification(TranslateCap('garage_has_stored'))
- else
- ESX.ShowNotification(TranslateCap('garage_has_notstored'))
end
+
+ isBusy = false
+ ESX.ShowNotification(TranslateCap('garage_has_stored'))
end, plates)
end
diff --git a/config.lua b/config.lua
index 377f226..f16269b 100644
--- a/config.lua
+++ b/config.lua
@@ -14,7 +14,6 @@ Config.EnableLicenses = false -- Enable if you're using esx_license.
Config.EnableHandcuffTimer = true -- Enable handcuff timer? will unrestrain player after the time ends.
Config.HandcuffTimer = 10 * 60000 -- 10 minutes.
-Config.EnableJobBlip = false -- Enable blips for cops on duty, requires esx_society.
Config.EnableCustomPeds = false -- Enable custom peds in cloak room? See Config.CustomPeds below to customize peds.
Config.EnableESXService = false -- Enable esx service?
diff --git a/server/main.lua b/server/main.lua
index 7545fc3..008c35f 100644
--- a/server/main.lua
+++ b/server/main.lua
@@ -1,158 +1,137 @@
-if Config.EnableESXService then
- if Config.MaxInService ~= -1 then
- TriggerEvent('esx_service:activateService', 'police', Config.MaxInService)
- end
+if Config.EnableESXService and Config.MaxInService ~= -1 then
+ TriggerEvent('esx_service:activateService', 'police', Config.MaxInService)
end
TriggerEvent('esx_phone:registerNumber', 'police', TranslateCap('alert_police'), true, true)
TriggerEvent('esx_society:registerSociety', 'police', TranslateCap('society_police'), 'society_police', 'society_police', 'society_police', {type = 'public'})
-RegisterNetEvent('esx_policejob:confiscatePlayerItem')
-AddEventHandler('esx_policejob:confiscatePlayerItem', function(target, itemType, itemName, amount)
+RegisterNetEvent('esx_policejob:confiscatePlayerItem', function(target, itemType, itemName, amount)
local source = source
local sourceXPlayer = ESX.GetPlayerFromId(source)
local targetXPlayer = ESX.GetPlayerFromId(target)
if sourceXPlayer.job.name ~= 'police' then
- print(('[^3WARNING^7] Player ^5%s^7 Attempted To Exploit The Confuscation System!'):format(sourceXPlayer.source))
- return
+ return print(('[^3WARNING^7] Player ^5%s^7 Attempted To Exploit The Confuscation System!'):format(sourceXPlayer.source))
end
if itemType == 'item_standard' then
local targetItem = targetXPlayer.getInventoryItem(itemName)
local sourceItem = sourceXPlayer.getInventoryItem(itemName)
+ -- can the player carry the said amount of x item?
-- does the target player have enough in their inventory?
- if targetItem.count > 0 and targetItem.count <= amount then
-
- -- can the player carry the said amount of x item?
- if sourceXPlayer.canCarryItem(itemName, sourceItem.count) then
- targetXPlayer.removeInventoryItem(itemName, amount)
- sourceXPlayer.addInventoryItem (itemName, amount)
- sourceXPlayer.showNotification(TranslateCap('you_confiscated', amount, sourceItem.label, targetXPlayer.name))
- targetXPlayer.showNotification(TranslateCap('got_confiscated', amount, sourceItem.label, sourceXPlayer.name))
- else
- sourceXPlayer.showNotification(TranslateCap('quantity_invalid'))
- end
- else
- sourceXPlayer.showNotification(TranslateCap('quantity_invalid'))
+ if (targetItem.count < 0 or targetItem.count > amount) or (not sourceXPlayer.canCarryItem(itemName, sourceItem.count)) then
+ return sourceXPlayer.showNotification(TranslateCap('quantity_invalid'))
end
+ targetXPlayer.removeInventoryItem(itemName, amount)
+ sourceXPlayer.addInventoryItem (itemName, amount)
+ sourceXPlayer.showNotification(TranslateCap('you_confiscated', amount, sourceItem.label, targetXPlayer.name))
+ targetXPlayer.showNotification(TranslateCap('got_confiscated', amount, sourceItem.label, sourceXPlayer.name))
elseif itemType == 'item_account' then
local targetAccount = targetXPlayer.getAccount(itemName)
-- does the target player have enough money?
- if targetAccount.money >= amount then
- targetXPlayer.removeAccountMoney(itemName, amount, "Confiscated")
- sourceXPlayer.addAccountMoney (itemName, amount, "Confiscated")
-
- sourceXPlayer.showNotification(TranslateCap('you_confiscated_account', amount, itemName, targetXPlayer.name))
- targetXPlayer.showNotification(TranslateCap('got_confiscated_account', amount, itemName, sourceXPlayer.name))
- else
- sourceXPlayer.showNotification(TranslateCap('quantity_invalid'))
+ if targetAccount.money < amount then
+ return sourceXPlayer.showNotification(TranslateCap('quantity_invalid'))
end
+
+ targetXPlayer.removeAccountMoney(itemName, amount, "Confiscated")
+ sourceXPlayer.addAccountMoney (itemName, amount, "Confiscated")
+ sourceXPlayer.showNotification(TranslateCap('you_confiscated_account', amount, itemName, targetXPlayer.name))
+ targetXPlayer.showNotification(TranslateCap('got_confiscated_account', amount, itemName, sourceXPlayer.name))
+
elseif itemType == 'item_weapon' then
if amount == nil then amount = 0 end
-- does the target player have weapon?
- if targetXPlayer.hasWeapon(itemName) then
- targetXPlayer.removeWeapon(itemName)
- sourceXPlayer.addWeapon (itemName, amount)
-
- sourceXPlayer.showNotification(TranslateCap('you_confiscated_weapon', ESX.GetWeaponLabel(itemName), targetXPlayer.name, amount))
- targetXPlayer.showNotification(TranslateCap('got_confiscated_weapon', ESX.GetWeaponLabel(itemName), amount, sourceXPlayer.name))
- else
- sourceXPlayer.showNotification(TranslateCap('quantity_invalid'))
+ if not targetXPlayer.hasWeapon(itemName) then
+ return sourceXPlayer.showNotification(TranslateCap('quantity_invalid'))
end
+
+ targetXPlayer.removeWeapon(itemName)
+ sourceXPlayer.addWeapon (itemName, amount)
+
+ sourceXPlayer.showNotification(TranslateCap('you_confiscated_weapon', ESX.GetWeaponLabel(itemName), targetXPlayer.name, amount))
+ targetXPlayer.showNotification(TranslateCap('got_confiscated_weapon', ESX.GetWeaponLabel(itemName), amount, sourceXPlayer.name))
end
end)
-RegisterNetEvent('esx_policejob:handcuff')
-AddEventHandler('esx_policejob:handcuff', function(target)
+RegisterNetEvent('esx_policejob:handcuff', function(target)
local xPlayer = ESX.GetPlayerFromId(source)
- if xPlayer.job.name == 'police' then
- TriggerClientEvent('esx_policejob:handcuff', target)
- else
- print(('[^3WARNING^7] Player ^5%s^7 Attempted To Exploit Handcuffs!'):format(xPlayer.source))
+ if xPlayer.job.name ~= 'police' then
+ return print(('[^3WARNING^7] Player ^5%s^7 Attempted To Exploit Handcuffs!'):format(xPlayer.source))
end
+
+ TriggerClientEvent('esx_policejob:handcuff', target)
end)
-RegisterNetEvent('esx_policejob:drag')
-AddEventHandler('esx_policejob:drag', function(target)
+RegisterNetEvent('esx_policejob:drag', function(target)
local xPlayer = ESX.GetPlayerFromId(source)
- if xPlayer.job.name == 'police' then
- TriggerClientEvent('esx_policejob:drag', target, source)
- else
- print(('[^3WARNING^7] Player ^5%s^7 Attempted To Exploit Dragging!'):format(xPlayer.source))
+ if xPlayer.job.name ~= 'police' then
+ return print(('[^3WARNING^7] Player ^5%s^7 Attempted To Exploit Dragging!'):format(xPlayer.source))
end
+
+ TriggerClientEvent('esx_policejob:drag', target, source)
end)
-RegisterNetEvent('esx_policejob:putInVehicle')
-AddEventHandler('esx_policejob:putInVehicle', function(target)
+RegisterNetEvent('esx_policejob:putInVehicle', function(target)
local xPlayer = ESX.GetPlayerFromId(source)
- if xPlayer.job.name == 'police' then
- TriggerClientEvent('esx_policejob:putInVehicle', target)
- else
- print(('[^3WARNING^7] Player ^5%s^7 Attempted To Exploit Garage!'):format(xPlayer.source))
+ if xPlayer.job.name ~= 'police' then
+ return print(('[^3WARNING^7] Player ^5%s^7 Attempted To Exploit Garage!'):format(xPlayer.source))
end
+
+ TriggerClientEvent('esx_policejob:putInVehicle', target)
end)
-RegisterNetEvent('esx_policejob:OutVehicle')
-AddEventHandler('esx_policejob:OutVehicle', function(target)
+RegisterNetEvent('esx_policejob:OutVehicle', function(target)
local xPlayer = ESX.GetPlayerFromId(source)
- if xPlayer.job.name == 'police' then
- TriggerClientEvent('esx_policejob:OutVehicle', target)
- else
- print(('[^3WARNING^7] Player ^5%s^7 Attempted To Exploit Dragging Out Of Vehicle!'):format(xPlayer.source))
- end
+ if xPlayer.job.name ~= 'police' then
+ return print(('[^3WARNING^7] Player ^5%s^7 Attempted To Exploit Dragging Out Of Vehicle!'):format(xPlayer.source))
+ end
+
+ TriggerClientEvent('esx_policejob:OutVehicle', target)
end)
-RegisterNetEvent('esx_policejob:getStockItem')
-AddEventHandler('esx_policejob:getStockItem', function(itemName, count)
+RegisterNetEvent('esx_policejob:getStockItem', function(itemName, count)
local source = source
local xPlayer = ESX.GetPlayerFromId(source)
+ if count < 0 then return xPlayer.showNotification(TranslateCap('quantity_invalid')) end
+
TriggerEvent('esx_addoninventory:getSharedInventory', 'society_police', function(inventory)
local inventoryItem = inventory.getItem(itemName)
-- is there enough in the society?
- if count > 0 and inventoryItem.count >= count then
-
- -- can the player carry the said amount of x item?
- if xPlayer.canCarryItem(itemName, count) then
- inventory.removeItem(itemName, count)
- xPlayer.addInventoryItem(itemName, count)
- xPlayer.showNotification(TranslateCap('have_withdrawn', count, inventoryItem.name))
- else
- xPlayer.showNotification(TranslateCap('quantity_invalid'))
- end
- else
- xPlayer.showNotification(TranslateCap('quantity_invalid'))
- end
+ -- can the player carry the said amount of x item?
+ if inventoryItem.count < count or (not xPlayer.canCarryItem(itemName, count)) then return xPlayer.showNotification(TranslateCap('quantity_invalid')) end
+
+ inventory.removeItem(itemName, count)
+ xPlayer.addInventoryItem(itemName, count)
+ xPlayer.showNotification(TranslateCap('have_withdrawn', count, inventoryItem.name))
end)
end)
-RegisterNetEvent('esx_policejob:putStockItems')
-AddEventHandler('esx_policejob:putStockItems', function(itemName, count)
+RegisterNetEvent('esx_policejob:putStockItems', function(itemName, count)
local xPlayer = ESX.GetPlayerFromId(source)
local sourceItem = xPlayer.getInventoryItem(itemName)
+ if count < 0 then return xPlayer.showNotification(TranslateCap('quantity_invalid')) end
+
TriggerEvent('esx_addoninventory:getSharedInventory', 'society_police', function(inventory)
local inventoryItem = inventory.getItem(itemName)
-- does the player have enough of the item?
- if sourceItem.count >= count and count > 0 then
- xPlayer.removeInventoryItem(itemName, count)
- inventory.addItem(itemName, count)
- xPlayer.showNotification(TranslateCap('have_deposited', count, inventoryItem.name))
- else
- xPlayer.showNotification(TranslateCap('quantity_invalid'))
- end
+ if sourceItem.count < count then return xPlayer.showNotification(TranslateCap('quantity_invalid')) end
+
+ xPlayer.removeInventoryItem(itemName, count)
+ inventory.addItem(itemName, count)
+ xPlayer.showNotification(TranslateCap('have_deposited', count, inventoryItem.name))
end)
end)
@@ -163,66 +142,63 @@ ESX.RegisterServerCallback('esx_policejob:getOtherPlayerData', function(source,
xPlayer.showNotification(TranslateCap('being_searched'))
end
- if xPlayer then
- local data = {
- name = xPlayer.getName(),
- job = xPlayer.job.label,
- grade = xPlayer.job.grade_label,
- inventory = xPlayer.getInventory(),
- accounts = xPlayer.getAccounts(),
- weapons = xPlayer.getLoadout()
- }
-
- if Config.EnableESXIdentity then
- data.dob = xPlayer.get('dateofbirth')
- data.height = xPlayer.get('height')
-
- if xPlayer.get('sex') == 'm' then data.sex = 'male' else data.sex = 'female' end
- end
+ if not xPlayer then return end
+ local data = {
+ 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 then
- data.drunk = ESX.Math.Round(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
+
+ TriggerEvent('esx_status:getStatus', target, 'drunk', function(status)
+ if status then
+ data.drunk = ESX.Math.Round(status.percent)
end
+ end)
+
+ if not Config.EnableLicenses then
+ return cb(data)
end
+
+ TriggerEvent('esx_license:getLicenses', target, function(licenses)
+ data.licenses = licenses
+ cb(data)
+ end)
end)
local fineList = {}
ESX.RegisterServerCallback('esx_policejob:getFineList', function(source, cb, category)
- if not fineList[category] then
- MySQL.query('SELECT * FROM fine_types WHERE category = ?', {category},
- function(fines)
- fineList[category] = fines
-
- cb(fines)
- end)
- else
- cb(fineList[category])
+ if fineList[category] then
+ return cb(fineList[category])
end
-end)
+ MySQL.query('SELECT * FROM fine_types WHERE category = ?', {category},
+ function(fines)
+ fineList[category] = fines
+ cb(fines)
+ end)
+end)
ESX.RegisterServerCallback('esx_policejob:getVehicleInfos', function(source, cb, plate)
- local retrivedInfo = {
+ local retrievedInfo = {
plate = plate
}
if Config.EnableESXIdentity then
MySQL.single('SELECT users.firstname, users.lastname FROM owned_vehicles JOIN users ON owned_vehicles.owner = users.identifier WHERE plate = ?', {plate},
function(result)
if result then
- retrivedInfo.owner = ('%s %s'):format(result.firstname, result.lastname)
+ retrievedInfo.owner = ('%s %s'):format(result.firstname, result.lastname)
end
- cb(retrivedInfo)
+ cb(retrievedInfo)
end)
else
MySQL.scalar('SELECT owner FROM owned_vehicles WHERE plate = ?', {plate},
@@ -230,10 +206,10 @@ ESX.RegisterServerCallback('esx_policejob:getVehicleInfos', function(source, cb,
if owner then
local xPlayer = ESX.GetPlayerFromIdentifier(owner)
if xPlayer then
- retrivedInfo.owner = xPlayer.getName()
+ retrievedInfo.owner = xPlayer.getName()
end
end
- cb(retrivedInfo)
+ cb(retrievedInfo)
end)
end
end)
@@ -278,7 +254,7 @@ ESX.RegisterServerCallback('esx_policejob:addArmoryWeapon', function(source, cb,
store.set('weapons', weapons)
cb()
- end)
+ end)
end)
ESX.RegisterServerCallback('esx_policejob:removeArmoryWeapon', function(source, cb, weaponName)
@@ -323,39 +299,37 @@ ESX.RegisterServerCallback('esx_policejob:buyWeapon', function(source, cb, weapo
if not selectedWeapon then
print(('[^3WARNING^7] Player ^5%s^7 Attempted To Buy Invalid Weapon - ^5%s^7!'):format(source, weaponName))
- cb(false)
- else
+ return cb(false)
+ end
-- Weapon
- if type == 1 then
- if xPlayer.getMoney() >= selectedWeapon.price then
- xPlayer.removeMoney(selectedWeapon.price, "Weapon Bought")
- xPlayer.addWeapon(weaponName, 100)
-
- cb(true)
- else
- cb(false)
- end
+ if type == 1 then
+ if xPlayer.getMoney() < selectedWeapon.price then
+ return cb(false)
+ end
- -- Weapon Component
- elseif type == 2 then
- local price = selectedWeapon.components[componentNum]
- local weaponNum, weapon = ESX.GetWeapon(weaponName)
- local component = weapon.components[componentNum]
+ xPlayer.removeMoney(selectedWeapon.price, "Weapon Bought")
+ xPlayer.addWeapon(weaponName, 100)
- if component then
- if xPlayer.getMoney() >= price then
- xPlayer.removeMoney(price, "Weapon Component Bought")
- xPlayer.addWeaponComponent(weaponName, component.name)
+ cb(true)
+ -- Weapon Component
+ elseif type == 2 then
+ local price = selectedWeapon.components[componentNum]
+ local weaponNum, weapon = ESX.GetWeapon(weaponName)
+ local component = weapon.components[componentNum]
- cb(true)
- else
- cb(false)
- end
- else
- print(('[^3WARNING^7] Player ^5%s^7 Attempted To Buy Invalid Weapon Component - ^5%s^7!'):format(source, componentNum))
- cb(false)
- end
+ if not component then
+ print(('[^3WARNING^7] Player ^5%s^7 Attempted To Buy Invalid Weapon Component - ^5%s^7!'):format(source, componentNum))
+ cb(false)
end
+
+ if xPlayer.getMoney() < price then
+ return cb(false)
+ end
+
+ xPlayer.removeMoney(price, "Weapon Component Bought")
+ xPlayer.addWeaponComponent(weaponName, component.name)
+
+ cb(true)
end
end)
@@ -366,19 +340,19 @@ ESX.RegisterServerCallback('esx_policejob:buyJobVehicle', function(source, cb, v
-- vehicle model not found
if price == 0 then
print(('[^3WARNING^7] Player ^5%s^7 Attempted To Buy Invalid Vehicle - ^5%s^7!'):format(source, vehicleProps.model))
- cb(false)
- else
- if xPlayer.getMoney() >= price then
- xPlayer.removeMoney(price, "Job Vehicle Bought")
-
- MySQL.insert('INSERT INTO owned_vehicles (owner, vehicle, plate, type, job, `stored`) VALUES (?, ?, ?, ?, ?, ?)', { xPlayer.identifier, json.encode(vehicleProps), vehicleProps.plate, type, xPlayer.job.name, true},
- function (rowsChanged)
- cb(true)
- end)
- else
- cb(false)
- end
+ return cb(false)
end
+
+ if xPlayer.getMoney < price then
+ return cb(false)
+ end
+
+ xPlayer.removeMoney(price, "Job Vehicle Bought")
+ MySQL.insert('INSERT INTO owned_vehicles (owner, vehicle, plate, type, job, `stored`) VALUES (?, ?, ?, ?, ?, ?)', { xPlayer.identifier, json.encode(vehicleProps), vehicleProps.plate, type, xPlayer.job.name, true},
+ function (rowsChanged)
+ cb(rowsChanged > 0)
+ end)
+
end)
ESX.RegisterServerCallback('esx_policejob:storeNearbyVehicle', function(source, cb, plates)
@@ -386,18 +360,11 @@ ESX.RegisterServerCallback('esx_policejob:storeNearbyVehicle', function(source,
local plate = MySQL.scalar.await('SELECT plate FROM owned_vehicles WHERE owner = ? AND plate IN (?) AND job = ?', {xPlayer.identifier, plates, xPlayer.job.name})
- if plate then
- MySQL.update('UPDATE owned_vehicles SET `stored` = true WHERE owner = ? AND plate = ? AND job = ?', {xPlayer.identifier, plate, xPlayer.job.name},
- function(rowsChanged)
- if rowsChanged == 0 then
- cb(false)
- else
- cb(plate)
- end
- end)
- else
- cb(false)
- end
+ if not plate then return cb(false) end
+ MySQL.update('UPDATE owned_vehicles SET `stored` = true WHERE owner = ? AND plate = ? AND job = ?', {xPlayer.identifier, plate, xPlayer.job.name},
+ function(rowsChanged)
+ cb(rowsChanged > 0 and plate)
+ end)
end)
function getPriceFromHash(vehicleHash, jobGrade, type)
@@ -426,47 +393,7 @@ ESX.RegisterServerCallback('esx_policejob:getPlayerInventory', function(source,
cb({items = items})
end)
-AddEventHandler('playerDropped', function()
- local playerId = source
- if playerId then
- local xPlayer = ESX.GetPlayerFromId(playerId)
-
- if xPlayer and xPlayer.job.name == 'police' then
- Wait(5000)
- TriggerClientEvent('esx_policejob:updateBlip', -1)
- end
- end
-end)
-
-RegisterNetEvent('esx_policejob:spawned')
-AddEventHandler('esx_policejob:spawned', function()
- local playerId = source
- local xPlayer = ESX.GetPlayerFromId(playerId)
-
- if xPlayer and xPlayer.job.name == 'police' then
- Wait(5000)
- TriggerClientEvent('esx_policejob:updateBlip', -1)
- end
-end)
-
-RegisterNetEvent('esx_policejob:forceBlip')
-AddEventHandler('esx_policejob:forceBlip', function()
- for _, xPlayer in pairs(ESX.GetExtendedPlayers('job', 'police')) do
- TriggerClientEvent('esx_policejob:updateBlip', xPlayer.source)
- end
-end)
-
-AddEventHandler('onResourceStart', function(resource)
- if resource == GetCurrentResourceName() then
- Wait(5000)
- for _, xPlayer in pairs(ESX.GetExtendedPlayers('job', 'police')) do
- TriggerClientEvent('esx_policejob:updateBlip', xPlayer.source)
- end
- end
-end)
-
AddEventHandler('onResourceStop', function(resource)
- if resource == GetCurrentResourceName() then
- TriggerEvent('esx_phone:removeNumber', 'police')
- end
+ if resource ~= GetCurrentResourceName() then return end
+ TriggerEvent('esx_phone:removeNumber', 'police')
end)