Skip to content

Commit

Permalink
Merge pull request #2 from mri-Qbox-Brasil/dev
Browse files Browse the repository at this point in the history
Feat: Colocar o player no bucket ao revogar whitelist
  • Loading branch information
ggfto authored Dec 23, 2024
2 parents 63a2b52 + c7db0d6 commit 0ac5e78
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 16 deletions.
8 changes: 4 additions & 4 deletions client/creator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ end

local function OnExit()
lib.callback(
"mri_Qwhitelist:saveConfig",
"mri_Qwhitelist:Server:SaveConfig",
false,
function(result)
return true
Expand Down Expand Up @@ -543,7 +543,7 @@ local function AddWhitelist(args)
if tonumber(identifier) then
identifier = tonumber(identifier)
end
if lib.callback.await("mri_Qwhitelist:addCitizenship", false, identifier) then
if lib.callback.await("mri_Qwhitelist:Server:AddCitizenship", false, identifier) then
lib.notify({description = "Whitelist adicionada com sucesso!", type = "success"})
end
args.callback()
Expand All @@ -558,7 +558,7 @@ local function RemoveWhitelist(args)
if tonumber(identifier) then
identifier = tonumber(identifier)
end
if lib.callback.await("mri_Qwhitelist:removeCitizenship", false, identifier) then
if lib.callback.await("mri_Qwhitelist:Server:RemoveCitizenship", false, identifier) then
lib.notify({description = "Whitelist revogada com sucesso!", type = "success"})
end
args.callback()
Expand Down Expand Up @@ -625,7 +625,7 @@ if GetResourceState("mri_Qbox") == "started" then
)
else
lib.callback.register(
"mri_Qwhitelist:manageWhitelistMenu",
"mri_Qwhitelist:Client:ManageWhitelistMenu",
function()
manageCitizenship()
return true
Expand Down
27 changes: 20 additions & 7 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,7 @@ local function beginExam()
local anwserPercentage = ((100 * correctAnswers) / #Config.Questions)
if anwserPercentage >= Config.Percent then
showAlertDialog(Config.SuccessHeader, Config.SuccessContent, false, "Jogar")
lib.callback.await("mri_Qwhitelist:addCitizenship", false)
examCompleted = true
Zone:Remove()
teleportPlayer(ped, Config.CompletionCoords)
lib.callback.await("mri_Qwhitelist:Server:addCitizenship", false)
else
showAlertDialog(Config.FailedHeader, Config.FailedContent, false, "Entendi")
end
Expand Down Expand Up @@ -117,14 +114,30 @@ function loadCitizenship()
end

local function OnPlayerLoaded()
Config = lib.callback.await("mri_Qwhitelist:getConfig", false)
if not lib.callback.await("mri_Qwhitelist:checkCitizenship", false) then
Config = lib.callback.await("mri_Qwhitelist:Server:GetConfig", false)
if not lib.callback.await("mri_Qwhitelist:Server:CheckCitizenship", false) then
if Config.Enabled then
loadCitizenship()
OnPlayerLoaded()
end
end
end

lib.callback.register(
"mri_Qwhitelist:Client:AddCitizenship",
function()
examCompleted = true
Zone:Remove()
teleportPlayer(cache.ped, Config.CompletionCoords)
end
)

lib.callback.register(
"mri_Qwhitelist:Client:RemoveCitizenship",
function()
loadCitizenship()
end
)

AddEventHandler(
"onResourceStart",
function(resourceName)
Expand Down
17 changes: 12 additions & 5 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ local function SetConfig(data)
end

local function SetPlayerBucket(target, bucket)
local actualBucket = GetPlayerRoutingBucket(target)
if actualBucket == bucket then
return
end
exports.qbx_core:SetPlayerBucket(target, bucket)
end

Expand Down Expand Up @@ -88,14 +92,14 @@ AddEventHandler('onResourceStart', function(resource)
end)

lib.callback.register(
"mri_Qwhitelist:getConfig",
"mri_Qwhitelist:Server:GetConfig",
function(source)
return Config
end
)

lib.callback.register(
"mri_Qwhitelist:saveConfig",
"mri_Qwhitelist:Server:SaveConfig",
function(source, data)
SetConfig(json.encode(data))
Config = data
Expand All @@ -105,7 +109,7 @@ lib.callback.register(
)

lib.callback.register(
"mri_Qwhitelist:checkCitizenship",
"mri_Qwhitelist:Server:CheckCitizenship",
function(source)
local playerBucket = 1000 + source
exports.qbx_core:SetPlayerBucket(source, playerBucket)
Expand All @@ -121,7 +125,7 @@ lib.callback.register(
)

lib.callback.register(
"mri_Qwhitelist:addCitizenship",
"mri_Qwhitelist:Server:AddCitizenship",
function(source, identifier)

local player = GetPlayer(identifier or source, identifier and source or nil)
Expand All @@ -138,12 +142,13 @@ lib.callback.register(
end

SetPlayerBucket(player.PlayerData.source, 0)
lib.callback.await("mri_Qwhitelist:Client:AddCitizenship", player.PlayerData.source, false)
return status
end
)

lib.callback.register(
"mri_Qwhitelist:removeCitizenship",
"mri_Qwhitelist:Server:RemoveCitizenship",
function(source, identifier)

local player = GetPlayer(identifier)
Expand All @@ -157,6 +162,8 @@ lib.callback.register(
lib.notify(source, {description = "Erro ao revogar whitelist, verifique o console para mais informações.", type = "error", duration = 5000})
end

SetPlayerBucket(player.PlayerData.source, 1000 + player.PlayerData.source)
lib.callback.await("mri_Qwhitelist:Client:RemoveCitizenship", player.PlayerData.source, false)
return status
end
)

0 comments on commit 0ac5e78

Please sign in to comment.