From cbb79f6cd404627e5895600e66c4762f8ad802e5 Mon Sep 17 00:00:00 2001 From: bitpredator <67551273+bitpredator@users.noreply.github.com> Date: Tue, 26 Mar 2024 01:22:55 +0100 Subject: [PATCH] refactor: (bpt_streetfight) await callbacks --- .../bpt_streetfight/client/client.lua | 18 ++++++------------ .../bpt_streetfight/server/server.lua | 18 ++++++------------ 2 files changed, 12 insertions(+), 24 deletions(-) diff --git a/server-data/resources/[bpt_addons]/bpt_streetfight/client/client.lua b/server-data/resources/[bpt_addons]/bpt_streetfight/client/client.lua index fe0aec30a..fe12db33f 100644 --- a/server-data/resources/[bpt_addons]/bpt_streetfight/client/client.lua +++ b/server-data/resources/[bpt_addons]/bpt_streetfight/client/client.lua @@ -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 @@ -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 @@ -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) @@ -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) @@ -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 @@ -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) diff --git a/server-data/resources/[bpt_addons]/bpt_streetfight/server/server.lua b/server-data/resources/[bpt_addons]/bpt_streetfight/server/server.lua index 9a7e67364..f5cee2319 100644 --- a/server-data/resources/[bpt_addons]/bpt_streetfight/server/server.lua +++ b/server-data/resources/[bpt_addons]/bpt_streetfight/server/server.lua @@ -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) @@ -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 @@ -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)