Skip to content

Commit

Permalink
Merge pull request #921 from bitpredator/dev
Browse files Browse the repository at this point in the history
fix(esx_policejob): remove not working job blip system
  • Loading branch information
bitpredator authored Dec 15, 2024
2 parents a1f02ff + d13b6d4 commit bfd1901
Show file tree
Hide file tree
Showing 6 changed files with 532 additions and 755 deletions.
179 changes: 7 additions & 172 deletions server-data/resources/[bpt_addons]/bpt_policejob/client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ function OpenCloakroomMenu()
TriggerServerEvent("esx_service:notifyAllInService", notification, "police")

TriggerServerEvent("esx_service:disableService", "police")
TriggerEvent("bpt_policejob:updateBlip")
ESX.ShowNotification(TranslateCap("service_out"))
end
end, "police")
Expand Down Expand Up @@ -110,7 +109,6 @@ function OpenCloakroomMenu()
}

TriggerServerEvent("esx_service:notifyAllInService", notification, "police")
TriggerEvent("bpt_policejob:updateBlip")
ESX.ShowNotification(TranslateCap("service_in"))
end
end, "police")
Expand All @@ -126,7 +124,6 @@ function OpenCloakroomMenu()
}

TriggerServerEvent("esx_service:notifyAllInService", notification, "police")
TriggerEvent("bpt_policejob:updateBlip")
ESX.ShowNotification(TranslateCap("service_in"))
end
else
Expand Down Expand Up @@ -197,8 +194,6 @@ function OpenArmoryMenu(station)
OpenGetWeaponMenu()
elseif data.current.value == "put_weapon" then
OpenPutWeaponMenu()
elseif data.current.value == "buy_weapons" then
OpenBuyWeaponsMenu()
elseif data.current.value == "put_stock" then
OpenPutStocksMenu()
elseif data.current.value == "get_stock" then
Expand Down Expand Up @@ -469,7 +464,7 @@ function OpenBodySearchMenu(player)
end

ESX.OpenContext("right", elements, function(_, element)
local data = { current = element }
data = { current = element }
if data.current.value then
TriggerServerEvent("bpt_policejob:confiscatePlayerItem", GetPlayerServerId(player), data.current.itemType, data.current.value, data.current.amount)
OpenBodySearchMenu(player)
Expand Down Expand Up @@ -515,7 +510,7 @@ function OpenFineCategoryMenu(player, category)
{ unselectable = true, icon = "fas fa-scroll", title = TranslateCap("fine") },
}

for k, fine in ipairs(fineList[category]) do
for _, fine in ipairs(fineList[category]) do
elements[#elements + 1] = {
icon = "fas fa-scroll",
title = ('%s <span style="color:green;">%s</span>'):format(fine.label, TranslateCap("armory_item", ESX.Math.GroupDigits(fine.amount))),
Expand Down Expand Up @@ -585,7 +580,7 @@ function LookupVehicle(elementF)
ESX.ShowNotification(TranslateCap("search_database_error_invalid"))
else
ESX.TriggerServerCallback("bpt_policejob:getVehicleInfos", function(retrivedInfo)
local elements = {
elements = {
{ unselectable = true, icon = "fas fa-car", title = element.title },
{ unselectable = true, icon = "fas fa-car", title = TranslateCap("plate", retrivedInfo.plate) },
}
Expand All @@ -596,7 +591,7 @@ function LookupVehicle(elementF)
elements[#elements + 1] = { unselectable = true, icon = "fas fa-user", title = TranslateCap("owner", retrivedInfo.owner) }
end

ESX.OpenContext("right", elements, nil, function(menu)
ESX.OpenContext("right", elements, nil, function()
OpenPoliceActionsMenu()
end)
end, data.value)
Expand Down Expand Up @@ -726,116 +721,6 @@ function OpenPutWeaponMenu()
end)
end

function OpenBuyWeaponsMenu()
local elements = {
{ unselectable = true, icon = "fas fa-gun", title = TranslateCap("armory_weapontitle") },
}
local playerPed = PlayerPedId()

for k, v in ipairs(Config.AuthorizedWeapons[ESX.PlayerData.job.grade_name]) do
local weaponNum, weapon = ESX.GetWeapon(v.weapon)
local components, label = {}, nil
local hasWeapon = HasPedGotWeapon(playerPed, joaat(v.weapon), false)

if v.components then
for i = 1, #v.components do
if v.components[i] then
local component = weapon.components[i]
local hasComponent = HasPedGotWeaponComponent(playerPed, joaat(v.weapon), component.hash)

if hasComponent then
label = ('%s: <span style="color:green;">%s</span>'):format(component.label, TranslateCap("armory_owned"))
else
if v.components[i] > 0 then
label = ('%s: <span style="color:green;">%s</span>'):format(component.label, TranslateCap("armory_item", ESX.Math.GroupDigits(v.components[i])))
else
label = ('%s: <span style="color:green;">%s</span>'):format(component.label, TranslateCap("armory_free"))
end
end

components[#components + 1] = {
icon = "fas fa-gun",
title = label,
componentLabel = component.label,
hash = component.hash,
name = component.name,
price = v.components[i],
hasComponent = hasComponent,
componentNum = i,
}
end
end
end

if hasWeapon and v.components then
label = ('%s: <span style="color:green;">></span>'):format(weapon.label)
elseif hasWeapon and not v.components then
label = ('%s: <span style="color:green;">%s</span>'):format(weapon.label, TranslateCap("armory_owned"))
else
if v.price > 0 then
label = ('%s: <span style="color:green;">%s</span>'):format(weapon.label, TranslateCap("armory_item", ESX.Math.GroupDigits(v.price)))
else
label = ('%s: <span style="color:green;">%s</span>'):format(weapon.label, TranslateCap("armory_free"))
end
end

elements[#elements + 1] = {
icon = "fas fa-gun",
title = label,
weaponLabel = weapon.label,
name = weapon.name,
components = components,
price = v.price,
hasWeapon = hasWeapon,
}
end

ESX.OpenContext("right", elements, function(menu, element)
local data = { current = element }
if data.current.hasWeapon then
if #data.current.components > 0 then
OpenWeaponComponentShop(data.current.components, data.current.name, menu)
end
else
ESX.TriggerServerCallback("bpt_policejob:buyWeapon", function(bought)
if bought then
if data.current.price > 0 then
ESX.ShowNotification(TranslateCap("armory_bought", data.current.weaponLabel, ESX.Math.GroupDigits(data.current.price)))
end

ESX.CloseContext()
OpenBuyWeaponsMenu()
else
ESX.ShowNotification(TranslateCap("armory_money"))
end
end, data.current.name, 1)
end
end)
end

function OpenWeaponComponentShop(components, weaponName, parentShop)
ESX.OpenContext("right", components, function(menu, element)
local data = { current = element }
if data.current.hasComponent then
ESX.ShowNotification(TranslateCap("armory_hascomponent"))
else
ESX.TriggerServerCallback("bpt_policejob:buyWeapon", function(bought)
if bought then
if data.current.price > 0 then
ESX.ShowNotification(TranslateCap("armory_bought", data.current.componentLabel, ESX.Math.GroupDigits(data.current.price)))
end

ESX.CloseContext()
parentShop.close()
OpenBuyWeaponsMenu()
else
ESX.ShowNotification(TranslateCap("armory_money"))
end
end, weaponName, 2, data.current.componentNum)
end
end)
end

function OpenGetStocksMenu()
ESX.TriggerServerCallback("bpt_policejob:getStockItems", function(items)
local elements = {
Expand Down Expand Up @@ -939,16 +824,6 @@ function OpenPutStocksMenu()
end)
end

function OnPlayerData(k, v)
if k ~= "job" then
return
end
if v.name == "police" then
Wait(1000)
TriggerServerEvent("bpt_policejob:forceBlip")
end
end

AddEventHandler("bpt_policejob:hasEnteredMarker", function(station, part, partNum)
if part == "Cloakroom" then
CurrentAction = "menu_cloakroom"
Expand Down Expand Up @@ -991,8 +866,8 @@ AddEventHandler("bpt_policejob:hasEnteredEntityZone", function(entity)
end

if GetEntityModel(entity) == `p_ld_stinger_s` then
local playerPed = PlayerPedId()
local coords = GetEntityCoords(playerPed)
playerPed = PlayerPedId()
local _ = GetEntityCoords(playerPed)

if IsPedInAnyVehicle(playerPed, false) then
local vehicle = GetVehiclePedIsIn(playerPed)
Expand Down Expand Up @@ -1210,7 +1085,7 @@ end)

-- Create blips
CreateThread(function()
for k, v in pairs(Config.PoliceStations) do
for _, v in pairs(Config.PoliceStations) do
local blip = AddBlipForCoord(v.Blip.Coords)

SetBlipSprite(blip, v.Blip.Sprite)
Expand Down Expand Up @@ -1475,40 +1350,6 @@ function CreateBlip(id)
end
end

RegisterNetEvent("bpt_policejob:updateBlip")
AddEventHandler("bpt_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("bpt_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)
end
end)

AddEventHandler("esx:onPlayerSpawn", function(spawn)
isDead = false
TriggerEvent("bpt_policejob:unrestrain")
Expand Down Expand Up @@ -1561,9 +1402,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("bpt_policejob:forceBlip")
end)
end
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
---@diagnostic disable: undefined-global

local spawnedVehicles = {}

function OpenVehicleSpawnerMenu(type, station, part, partNum)
Expand Down
Loading

0 comments on commit bfd1901

Please sign in to comment.