From 04b4fb56d0aee2a307385b398068a323afc19476 Mon Sep 17 00:00:00 2001 From: Samael <33399712+bleonheart@users.noreply.github.com> Date: Wed, 9 Oct 2024 21:41:45 +0100 Subject: [PATCH] Adds ix.util.GetUserByCharacterID --- gamemode/core/sh_util.lua | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) 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