Skip to content

Commit

Permalink
refactor: (bpt_menu) await callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
bitpredator committed Mar 26, 2024
1 parent a4d4937 commit c6e9dd5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 45 deletions.
4 changes: 2 additions & 2 deletions server-data/resources/[bpt_addons]/bpt_menu/client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,14 @@ for i = 1, #Config.Animations do
end

if Config.Framework == "esx" then
AddEventHandler("esx:onPlayerDeath", function()
RegisterNetEvent("esx:onPlayerDeath", function()
PlayerVars.isDead = true
RageUI.CloseAll()
ESX.UI.Menu.CloseAll()
end)
end

AddEventHandler("playerSpawned", function()
RegisterNetEvent("playerSpawned", function()
PlayerVars.isDead = false
end)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function ResetOtherAnimsVals()
end

if Config.Framework == "esx" then
AddEventHandler("esx:onPlayerDeath", ResetOtherAnimsVals)
RegisterNetEvent("esx:onPlayerDeath", ResetOtherAnimsVals)
end

RegisterCommand("+handsup", function()
Expand Down
58 changes: 16 additions & 42 deletions server-data/resources/[bpt_addons]/bpt_menu/server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ do
local oldEventName = ("bpt-PersonalMenu:%s"):format(eventName:sub(endIdx + 1))

origRegisterServerEvent(oldEventName)
AddEventHandler(oldEventName, function()
RegisterNetEvent(oldEventName, function()
DropPlayer(
source,
(
Expand Down Expand Up @@ -103,20 +103,17 @@ end

-- Admin Menu --
RegisterServerEvent("bpt_personalmenu:Admin_BringS")
AddEventHandler(
"bpt_personalmenu:Admin_BringS",
makeTargetedEventFunction(function(playerId, target)
local xPlayer = ESX.GetPlayerFromId(source)
local plyGroup = xPlayer.getGroup()

if isAuthorized(getAdminCommand("bring"), plyGroup) or isAuthorized(getAdminCommand("goto"), plyGroup) then
TriggerClientEvent("bpt_personalmenu:Admin_BringC", playerId, GetEntityCoords(GetPlayerPed(target)))
end
end)
end
)

RegisterServerEvent("bpt_personalmenu:Admin_giveCash")
AddEventHandler("bpt_personalmenu:Admin_giveCash", function(amount)
RegisterServerEvent("bpt_personalmenu:Admin_giveCash", function(amount)
local xPlayer = ESX.GetPlayerFromId(source)
local plyGroup = xPlayer.getGroup()

Expand All @@ -126,8 +123,7 @@ AddEventHandler("bpt_personalmenu:Admin_giveCash", function(amount)
end
end)

RegisterServerEvent("bpt_personalmenu:Admin_giveBank")
AddEventHandler("bpt_personalmenu:Admin_giveBank", function(amount)
RegisterServerEvent("bpt_personalmenu:Admin_giveBank", function(amount)
local xPlayer = ESX.GetPlayerFromId(source)
local plyGroup = xPlayer.getGroup()

Expand All @@ -137,8 +133,7 @@ AddEventHandler("bpt_personalmenu:Admin_giveBank", function(amount)
end
end)

RegisterServerEvent("bpt_personalmenu:Admin_giveDirtyMoney")
AddEventHandler("bpt_personalmenu:Admin_giveDirtyMoney", function(amount)
RegisterServerEvent("bpt_personalmenu:Admin_giveDirtyMoney", function(amount)
local xPlayer = ESX.GetPlayerFromId(source)
local plyGroup = xPlayer.getGroup()

Expand All @@ -150,8 +145,6 @@ end)

-- Grade Menu --
RegisterServerEvent("bpt_personalmenu:Boss_promoteplayer")
AddEventHandler(
"bpt_personalmenu:Boss_promoteplayer",
makeTargetedEventFunction(function(target)
local sourceXPlayer = ESX.GetPlayerFromId(source)
local sourceJob = sourceXPlayer.getJob()
Expand All @@ -165,8 +158,7 @@ AddEventHandler(

if newGrade ~= getMaximumGrade(targetJob.name) then
targetXPlayer.setJob(targetJob.name, newGrade)
TriggerClientEvent(
"esx:showNotification",
TriggerClientEvent("esx:showNotification",
sourceXPlayer.source,
TranslateCap("promoted"):format(targetXPlayer.name)
)
Expand All @@ -180,12 +172,10 @@ AddEventHandler(
else
TriggerClientEvent("esx:showNotification", sourceXPlayer.source, TranslateCap("not_permission"))
end
end)
end
)

RegisterServerEvent("bpt_personalmenu:Boss_dismissplayer")
AddEventHandler(
"bpt_personalmenu:Boss_dismissplayer",
makeTargetedEventFunction(function(target)
local sourceXPlayer = ESX.GetPlayerFromId(source)
local sourceJob = sourceXPlayer.getJob()
Expand Down Expand Up @@ -214,12 +204,10 @@ AddEventHandler(
else
TriggerClientEvent("esx:showNotification", sourceXPlayer.source, TranslateCap("not_permission"))
end
end)
end
)

RegisterServerEvent("bpt_personalmenu:Boss_recruitplayer")
AddEventHandler(
"bpt_personalmenu:Boss_recruitplayer",
makeTargetedEventFunction(function(target)
local sourceXPlayer = ESX.GetPlayerFromId(source)
local sourceJob = sourceXPlayer.getJob()
Expand All @@ -231,12 +219,10 @@ AddEventHandler(
TriggerClientEvent("esx:showNotification", sourceXPlayer.source, TranslateCap("you_hired"):format(targetXPlayer.name))
TriggerClientEvent("esx:showNotification", target, TranslateCap("you_hired_by"):format(sourceXPlayer.name))
end
end)
end
)

RegisterServerEvent("bpt_personalmenu:Boss_fireplayer")
AddEventHandler(
"bpt_personalmenu:Boss_fireplayer",
makeTargetedEventFunction(function(target)
local sourceXPlayer = ESX.GetPlayerFromId(source)
local sourceJob = sourceXPlayer.getJob()
Expand All @@ -247,9 +233,7 @@ AddEventHandler(

if sourceJob.name == targetJob.name then
targetXPlayer.setJob("unemployed", 0)
TriggerClientEvent(
"esx:showNotification",
sourceXPlayer.source,
TriggerClientEvent("esx:showNotification", sourceXPlayer.source,
TranslateCap("you_fired"):format(targetXPlayer.name)
)
TriggerClientEvent("esx:showNotification", target, TranslateCap("you_were_fired"):format(sourceXPlayer.name))
Expand All @@ -259,12 +243,10 @@ AddEventHandler(
else
TriggerClientEvent("esx:showNotification", sourceXPlayer.source, TranslateCap("not_permission"))
end
end)
end
)

RegisterServerEvent("bpt_personalmenu:Boss_promoteplayer2")
AddEventHandler(
"bpt_personalmenu:Boss_promoteplayer2",
makeTargetedEventFunction(function(target)
local sourceXPlayer = ESX.GetPlayerFromId(source)
local sourceJob2 = sourceXPlayer.getJob2()
Expand Down Expand Up @@ -293,12 +275,10 @@ AddEventHandler(
else
TriggerClientEvent("esx:showNotification", sourceXPlayer.source, TranslateCap("not_permission"))
end
end)
end
)

RegisterServerEvent("bpt_personalmenu:Boss_dismissplayer2")
AddEventHandler(
"bpt_personalmenu:Boss_dismissplayer2",
makeTargetedEventFunction(function(target)
local sourceXPlayer = ESX.GetPlayerFromId(source)
local sourceJob2 = sourceXPlayer.getJob2()
Expand Down Expand Up @@ -327,12 +307,10 @@ AddEventHandler(
else
TriggerClientEvent("esx:showNotification", sourceXPlayer.source, TranslateCap("not_permission"))
end
end)
end
)

RegisterServerEvent("bpt_personalmenu:Boss_recruitplayer2")
AddEventHandler(
"bpt_personalmenu:Boss_recruitplayer2",
makeTargetedEventFunction(function(target)
local sourceXPlayer = ESX.GetPlayerFromId(source)
local sourceJob2 = sourceXPlayer.getJob2()
Expand All @@ -344,12 +322,10 @@ AddEventHandler(
TriggerClientEvent("esx:showNotification", sourceXPlayer.source, TranslateCap("you_hired"):format(targetXPlayer.name))
TriggerClientEvent("esx:showNotification", target, TranslateCap("you_hired_by"):format(sourceXPlayer.name))
end
end)
end
)

RegisterServerEvent("bpt_personalmenu:Boss_fireplayer2")
AddEventHandler(
"bpt_personalmenu:Boss_fireplayer2",
makeTargetedEventFunction(function(target)
local sourceXPlayer = ESX.GetPlayerFromId(source)
local sourceJob2 = sourceXPlayer.getJob2()
Expand All @@ -360,9 +336,7 @@ AddEventHandler(

if sourceJob2.name == targetJob2.name then
targetXPlayer.setJob2("unemployed2", 0)
TriggerClientEvent(
"esx:showNotification",
sourceXPlayer.source,
TriggerClientEvent("esx:showNotification", sourceXPlayer.source,
TranslateCap("you_fired"):format(targetXPlayer.name)
)
TriggerClientEvent("esx:showNotification", target, TranslateCap("you_were_fired"):format(sourceXPlayer.name))
Expand All @@ -372,5 +346,5 @@ AddEventHandler(
else
TriggerClientEvent("esx:showNotification", sourceXPlayer.source, TranslateCap("not_permission"))
end
end)
end
)

0 comments on commit c6e9dd5

Please sign in to comment.