Last active
February 20, 2024 07:57
-
-
Save PichotM/44542ebdd5eba659055fbe1e09ae6b21 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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