Skip to content

Instantly share code, notes, and snippets.

@PichotM
Last active February 20, 2024 07:57
Show Gist options
  • Save PichotM/44542ebdd5eba659055fbe1e09ae6b21 to your computer and use it in GitHub Desktop.
Save PichotM/44542ebdd5eba659055fbe1e09ae6b21 to your computer and use it in GitHub Desktop.
local scopes = {}
AddEventHandler("playerEnteredScope", function(data)
local playerEntering, player = data["player"], data["for"]
if not scopes[player] then
scopes[player] = {}
end
scopes[player][playerEntering] = true
end)
AddEventHandler("playerLeftScope", function(data)
local playerLeaving, player = data["player"], data["for"]
if not scopes[player] then return end
scopes[player][playerLeaving] = nil
end)
AddEventHandler("playerDropped", function()
local intSource = source
if not intSource then return end
scopes[intSource] = nil
for owner, tbl in pairs(scopes) do
if tbl[intSource] then
tbl[intSource] = nil
end
end
end)
function GetPlayerScope(intSource)
return scopes[tostring(intSource)]
end
function TriggerScopeEvent(eventName, scopeOwner, ...)
local targets = scopes[tostring(scopeOwner)]
if targets then
for target, _ in pairs(targets) do
TriggerClientEvent(eventName, target, ...)
end
end
TriggerClientEvent(eventName, scopeOwner, ...)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment