diff --git a/docs/hooks/plugin.lua b/docs/hooks/plugin.lua index 276543314..610e96e6b 100644 --- a/docs/hooks/plugin.lua +++ b/docs/hooks/plugin.lua @@ -657,7 +657,16 @@ end function MessageReceived(client, info) end ---- @realm client +--- Called when a player leaves an area. +-- @number oldID The ID of the area the player is leaving. +-- @realm client +function OnLeaveArea(oldID) +end + +--- Called when a player enters a new area. +-- @number oldID The ID of the area the player is leaving. +-- @number newID The ID of the area the player is entering. +-- @realm client function OnAreaChanged(oldID, newID) end diff --git a/gamemode/core/sh_util.lua b/gamemode/core/sh_util.lua index af0b3dc9c..a8b118292 100644 --- a/gamemode/core/sh_util.lua +++ b/gamemode/core/sh_util.lua @@ -388,7 +388,25 @@ do return iterator, player.GetAll() end end - +--- Retrieves the client associated with a character by their character ID. +-- @realm shared +-- @tparam number ID The ID of the character to find the associated client +-- @treturn player|nil The client associated with the character, or `nil` if no client is found +-- @usage +-- local client = ix.util.GetUserByCharacterID(123) +-- if IsValid(client) then +-- print(client:Nick() .. " is the player associated with the character ID.") +-- else +-- print("No client found for that character ID.") +-- end +function ix.util.GetUserByCharacterID(ID) + ID = tonumber(ID) + for client, character in ix.util.GetCharacters() do + if not character then continue end + if character:GetID() == ID then return client end + end + return nil +end if (CLIENT) then local blur = ix.util.GetMaterial("pp/blurscreen") local surface = surface diff --git a/plugins/area/cl_hooks.lua b/plugins/area/cl_hooks.lua index 662f0fcc4..2b67def1f 100644 --- a/plugins/area/cl_hooks.lua +++ b/plugins/area/cl_hooks.lua @@ -185,23 +185,17 @@ end function PLUGIN:OnAreaChanged(oldID, newID) local client = LocalPlayer() client.ixArea = newID - local area = ix.area.stored[newID] - - if (!area) then + if not area then client.ixInArea = false + hook.Run("OnLeaveArea", oldID) return end client.ixInArea = true - - if (hook.Run("ShouldDisplayArea", newID) == false or !area.properties.display) then - return - end - + if hook.Run("ShouldDisplayArea", newID) == false or not area.properties.display then return end local format = newID .. (ix.option.Get("24hourTime", false) and ", %H:%M." or ", %I:%M %p.") format = ix.date.GetFormatted(format) - self.panel:AddEntry(format, area.properties.color) end