Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds ix.util.GetUserByCharacterID #453

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion docs/hooks/plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 19 additions & 1 deletion gamemode/core/sh_util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 3 additions & 9 deletions plugins/area/cl_hooks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please try to stick to the same code style as the rest of the framework.

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

Expand Down
Loading