From b9712a0fe5a23e877bfc0c27352d78fc864132dc Mon Sep 17 00:00:00 2001 From: Mitroxs <59477429+Mitroxs@users.noreply.github.com> Date: Fri, 3 Dec 2021 17:35:32 +0100 Subject: [PATCH 1/5] Introduction to Routingbuckets --- server/events.lua | 1 + server/functions.lua | 69 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/server/events.lua b/server/events.lua index d4b15d4..f85fbc4 100644 --- a/server/events.lua +++ b/server/events.lua @@ -6,6 +6,7 @@ AddEventHandler('playerDropped', function() local Player = QBCore.Players[src] TriggerEvent('qb-log:server:CreateLog', 'joinleave', 'Dropped', 'red', '**' .. GetPlayerName(src) .. '** (' .. Player.PlayerData.license .. ') left..') Player.Functions.Save() + _G.QBCore.Player_Buckets[Player.PlayerData.license] = nil QBCore.Players[src] = nil end end) diff --git a/server/functions.lua b/server/functions.lua index 1fd1504..b284192 100644 --- a/server/functions.lua +++ b/server/functions.lua @@ -107,6 +107,75 @@ function QBCore.Functions.GetDutyCount(job) return count end +--- Routingbucket stuff (Only touch if you know what you are doing) +_G.QBCore.Player_Buckets = {} -- Bucket array containing all players that have been set to a different bucket +_G.QBCore.Entity_Buckets = {} -- Bucket array containing all entities that have been set to a different bucket + +--- Will set the provided player id / source into the provided bucket id +function QBCore.Functions.SetPlayerBucket(player_source --[[int]],bucket --[[int]]) + if player_source and bucket then + local plicense = QBCore.Functions.GetIdentifier(player, 'license') + SetPlayerRoutingBucket(player_source, bucket) + _G.QBCore.Player_Buckets[plicense] = {player_id = player_source, player_bucket = bucket} + return true + else + return false + end +end + +--- Will set any entity into the provided bucket, for example peds / vehicles / props / etc... +function QBCore.Functions.SetEntityBucket(entity --[[int]],bucket --[[int]]) + if entity and bucket then + SetEntityRoutingBucket(entity, bucket) + _G.QBCore.Entity_Buckets[entity] = {entity_id = entity, entity_bucket = bucket} + return true + else + return false + end +end + + +-- Will return an array of all the player ids inside the current bucket +function QBCore.Functions.GetPlayersInBucket(bucket --[[int]]) + local curr_bucket_pool = {} + if _G.QBCore.Player_Buckets ~= nil then + for k, v in pairs(_G.QBCore.Player_Buckets) do + if k['player_bucket'] == bucket then + curr_bucket_pool[#curr_bucket_pool + 1] = k['player_id'] + end + end + return curr_bucket_pool + else + return false + end +end + + +--- Will return an array of all the entities inside the current bucket (Not player entities , use GetPlayersInBucket for that) +function QBCore.Functions.GetEntitiesInBucket(bucket --[[int]]) + local curr_bucket_pool = {} + if _G.QBCore.Entity_Buckets ~= nil then + for k, v in pairs(_G.QBCore.Entity_Buckets) do + if k['entity_bucket'] == bucket then + curr_bucket_pool[#curr_bucket_pool + 1] = k['entity_id'] + end + end + return curr_bucket_pool + else + return false + end +end + +--- Will return true / false wheter the mentioned player id is present in the bucket provided +function QBCore.Functions.IsPlayerInBucket(player_source --[[int]] ,bucket --[[int]]) + local curr_player_bucket = GetPlayerRoutingBucket(player_source) + if curr_player_bucket == bucket then + return true + else + return false + end +end + -- Paychecks (standalone - don't touch) function PaycheckLoop() From 0c55486312e61fb717429ecf029c95cec7d0081c Mon Sep 17 00:00:00 2001 From: Mitroxs <59477429+Mitroxs@users.noreply.github.com> Date: Fri, 3 Dec 2021 18:18:14 +0100 Subject: [PATCH 2/5] Update server/functions.lua Co-authored-by: Taso --- server/functions.lua | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/server/functions.lua b/server/functions.lua index b284192..60f5c18 100644 --- a/server/functions.lua +++ b/server/functions.lua @@ -169,11 +169,7 @@ end --- Will return true / false wheter the mentioned player id is present in the bucket provided function QBCore.Functions.IsPlayerInBucket(player_source --[[int]] ,bucket --[[int]]) local curr_player_bucket = GetPlayerRoutingBucket(player_source) - if curr_player_bucket == bucket then - return true - else - return false - end + return curr_player_bucket == bucket end -- Paychecks (standalone - don't touch) From 315f70600d12b80091c1bd248cad10e36aa9c277 Mon Sep 17 00:00:00 2001 From: Mitroxs <59477429+Mitroxs@users.noreply.github.com> Date: Fri, 3 Dec 2021 18:25:00 +0100 Subject: [PATCH 3/5] Deattach from QBcore object --- server/functions.lua | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/server/functions.lua b/server/functions.lua index b284192..61f3fb4 100644 --- a/server/functions.lua +++ b/server/functions.lua @@ -108,15 +108,15 @@ function QBCore.Functions.GetDutyCount(job) end --- Routingbucket stuff (Only touch if you know what you are doing) -_G.QBCore.Player_Buckets = {} -- Bucket array containing all players that have been set to a different bucket -_G.QBCore.Entity_Buckets = {} -- Bucket array containing all entities that have been set to a different bucket +_G.Player_Buckets = {} -- Bucket array containing all players that have been set to a different bucket +_G.Entity_Buckets = {} -- Bucket array containing all entities that have been set to a different bucket --- Will set the provided player id / source into the provided bucket id function QBCore.Functions.SetPlayerBucket(player_source --[[int]],bucket --[[int]]) if player_source and bucket then local plicense = QBCore.Functions.GetIdentifier(player, 'license') SetPlayerRoutingBucket(player_source, bucket) - _G.QBCore.Player_Buckets[plicense] = {player_id = player_source, player_bucket = bucket} + _G.Player_Buckets[plicense] = {player_id = player_source, player_bucket = bucket} return true else return false @@ -127,7 +127,7 @@ end function QBCore.Functions.SetEntityBucket(entity --[[int]],bucket --[[int]]) if entity and bucket then SetEntityRoutingBucket(entity, bucket) - _G.QBCore.Entity_Buckets[entity] = {entity_id = entity, entity_bucket = bucket} + _G.Entity_Buckets[entity] = {entity_id = entity, entity_bucket = bucket} return true else return false @@ -138,8 +138,8 @@ end -- Will return an array of all the player ids inside the current bucket function QBCore.Functions.GetPlayersInBucket(bucket --[[int]]) local curr_bucket_pool = {} - if _G.QBCore.Player_Buckets ~= nil then - for k, v in pairs(_G.QBCore.Player_Buckets) do + if _G.Player_Buckets ~= nil then + for k, v in pairs(_G.Player_Buckets) do if k['player_bucket'] == bucket then curr_bucket_pool[#curr_bucket_pool + 1] = k['player_id'] end @@ -154,8 +154,8 @@ end --- Will return an array of all the entities inside the current bucket (Not player entities , use GetPlayersInBucket for that) function QBCore.Functions.GetEntitiesInBucket(bucket --[[int]]) local curr_bucket_pool = {} - if _G.QBCore.Entity_Buckets ~= nil then - for k, v in pairs(_G.QBCore.Entity_Buckets) do + if _G.Entity_Buckets ~= nil then + for k, v in pairs(_G.Entity_Buckets) do if k['entity_bucket'] == bucket then curr_bucket_pool[#curr_bucket_pool + 1] = k['entity_id'] end From a3a763c86a5d84504486ab478b663e4df404109b Mon Sep 17 00:00:00 2001 From: Mitroxs <59477429+Mitroxs@users.noreply.github.com> Date: Fri, 3 Dec 2021 19:06:40 +0100 Subject: [PATCH 4/5] Get function for the bucket objects --- server/functions.lua | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/server/functions.lua b/server/functions.lua index 2c86364..b5796de 100644 --- a/server/functions.lua +++ b/server/functions.lua @@ -111,6 +111,13 @@ end _G.Player_Buckets = {} -- Bucket array containing all players that have been set to a different bucket _G.Entity_Buckets = {} -- Bucket array containing all entities that have been set to a different bucket + +--- Returns the objects related to buckets, first returned value is the player buckets , second one is entity buckets +function QBCore.Functions.GetBucketObjects() + return _G.Player_Buckets, _G.Entity_Buckets +end + + --- Will set the provided player id / source into the provided bucket id function QBCore.Functions.SetPlayerBucket(player_source --[[int]],bucket --[[int]]) if player_source and bucket then From 88820c80f1dae2ab45e29449c1d228d4da63cedf Mon Sep 17 00:00:00 2001 From: Mitroxs <59477429+Mitroxs@users.noreply.github.com> Date: Fri, 3 Dec 2021 22:09:28 +0100 Subject: [PATCH 5/5] typo :interrobang: --- server/functions.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/functions.lua b/server/functions.lua index b5796de..1334c99 100644 --- a/server/functions.lua +++ b/server/functions.lua @@ -121,7 +121,7 @@ end --- Will set the provided player id / source into the provided bucket id function QBCore.Functions.SetPlayerBucket(player_source --[[int]],bucket --[[int]]) if player_source and bucket then - local plicense = QBCore.Functions.GetIdentifier(player, 'license') + local plicense = QBCore.Functions.GetIdentifier(player_source, 'license') SetPlayerRoutingBucket(player_source, bucket) _G.Player_Buckets[plicense] = {player_id = player_source, player_bucket = bucket} return true