Skip to content

Commit

Permalink
refactor: (bpt_streetfight) await callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
bitpredator committed Mar 26, 2024
1 parent c6e9dd5 commit cbb79f6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ CreateThread(function()
RunThread()
end)

RegisterNetEvent("bpt_streetfight:playerJoined")
AddEventHandler("bpt_streetfight:playerJoined", function(side, id)
RegisterNetEvent("bpt_streetfight:playerJoined", function(side, id)
if side == 1 then
blueJoined = true
else
Expand All @@ -36,8 +35,7 @@ AddEventHandler("bpt_streetfight:playerJoined", function(side, id)
fightStatus = STATUS_JOINED
end)

RegisterNetEvent("bpt_streetfight:startFight")
AddEventHandler("bpt_streetfight:startFight", function(fightData)
RegisterNetEvent("bpt_streetfight:startFight", function(fightData)
for _, value in ipairs(fightData) do
if value.id ~= GetPlayerServerId(PlayerId()) then
rival = value.id
Expand All @@ -51,8 +49,7 @@ AddEventHandler("bpt_streetfight:startFight", function(fightData)
countdown()
end)

RegisterNetEvent("bpt_streetfight:playerLeaveFight")
AddEventHandler("bpt_streetfight:playerLeaveFight", function(id)
RegisterNetEvent("bpt_streetfight:playerLeaveFight", function(id)
if id == GetPlayerServerId(PlayerId()) then
ESX.ShowNotification(_U("you_toofar"))
SetPedMaxHealth(PlayerPedId(), 200)
Expand All @@ -68,8 +65,7 @@ AddEventHandler("bpt_streetfight:playerLeaveFight", function(id)
reset()
end)

RegisterNetEvent("bpt_streetfight:fightFinished")
AddEventHandler("bpt_streetfight:fightFinished", function(looser)
RegisterNetEvent("bpt_streetfight:fightFinished", function(looser)
if participating == true then
if looser ~= GetPlayerServerId(PlayerId()) and looser ~= -2 then
TriggerServerEvent("bpt_streetfight:pay", betAmount)
Expand Down Expand Up @@ -97,8 +93,7 @@ AddEventHandler("bpt_streetfight:fightFinished", function(looser)
reset()
end)

RegisterNetEvent("bpt_streetfight:raiseActualBet")
AddEventHandler("bpt_streetfight:raiseActualBet", function()
RegisterNetEvent("bpt_streetfight:raiseActualBet", function()
betAmount = betAmount * 2
if betAmount == 0 then
betAmount = 2000
Expand All @@ -107,8 +102,7 @@ AddEventHandler("bpt_streetfight:raiseActualBet", function()
end
end)

RegisterNetEvent("bpt_streetfight:winnerText")
AddEventHandler("bpt_streetfight:winnerText", function(id)
RegisterNetEvent("bpt_streetfight:winnerText", function(id)
showWinner = true
winner = id
Wait(5000)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ local fight = {}

ESX = exports["es_extended"]:getSharedObject()

RegisterServerEvent("bpt_streetfight:join")
AddEventHandler("bpt_streetfight:join", function(betAmount, side)
RegisterServerEvent("bpt_streetfight:join", function(betAmount, side)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)

Expand Down Expand Up @@ -55,16 +54,14 @@ function countdown(copyFight)
end
end

RegisterServerEvent("bpt_streetfight:finishFight")
AddEventHandler("bpt_streetfight:finishFight", function(looser)
RegisterServerEvent("bpt_streetfight:finishFight", function(looser)
TriggerClientEvent("bpt_streetfight:fightFinished", -1, looser)
fight = {}
bluePlayerReady = false
redPlayerReady = false
end)

RegisterServerEvent("bpt_streetfight:leaveFight")
AddEventHandler("bpt_streetfight:leaveFight", function(id)
RegisterServerEvent("bpt_streetfight:leaveFight", function(id)
if bluePlayerReady or redPlayerReady then
bluePlayerReady = false
redPlayerReady = false
Expand All @@ -73,19 +70,16 @@ AddEventHandler("bpt_streetfight:leaveFight", function(id)
end
end)

RegisterServerEvent("bpt_streetfight:pay")
AddEventHandler("bpt_streetfight:pay", function(amount)
RegisterServerEvent("bpt_streetfight:pay", function(amount)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
xPlayer.addAccountMoney("money", amount * 2)
end)

RegisterServerEvent("bpt_streetfight:raiseBet")
AddEventHandler("bpt_streetfight:raiseBet", function()
RegisterServerEvent("bpt_streetfight:raiseBet", function()
TriggerClientEvent("bpt_streetfight:raiseActualBet", -1)
end)

RegisterServerEvent("bpt_streetfight:showWinner")
AddEventHandler("bpt_streetfight:showWinner", function(id)
RegisterServerEvent("bpt_streetfight:showWinner", function(id)
TriggerClientEvent("bpt_streetfight:winnerText", -1, id)
end)

0 comments on commit cbb79f6

Please sign in to comment.