From cf598c513ca16286b41a3729b60e89392640a1f6 Mon Sep 17 00:00:00 2001 From: Kamil Date: Mon, 17 Oct 2022 19:37:31 +0200 Subject: [PATCH 1/4] Change client _C() to use player manager --- ScriptExtender/LuaScripts/BuiltinLibraryClient.lua | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/ScriptExtender/LuaScripts/BuiltinLibraryClient.lua b/ScriptExtender/LuaScripts/BuiltinLibraryClient.lua index 3c934232..495bb72b 100644 --- a/ScriptExtender/LuaScripts/BuiltinLibraryClient.lua +++ b/ScriptExtender/LuaScripts/BuiltinLibraryClient.lua @@ -245,12 +245,13 @@ Ext.Events.SkillGetPropertyDescription:Subscribe(function (e) end) -- Debug helper to get current player character -_C = function () - local statusConsole = Ext.UI.GetByType(117) - if statusConsole == nil then return end - local handle = statusConsole:GetPlayerHandle() - if handle == nil then return end - return Ext.Entity.GetCharacter(handle) +_C = function (playerIndex) + playerIndex = playerIndex or 1 + local playerManager = Ext.Entity.GetPlayerManager() + local player = playerManager.ClientPlayerData[playerIndex] + local charNetID = player and player.CharacterNetId + + return Ext.Entity.GetCharacter(charNetID) end -- Debug helper to get character being examined From f925cbf207c796c2fdcdbd2899b42c00887a0b02 Mon Sep 17 00:00:00 2001 From: Kamil Date: Mon, 17 Oct 2022 19:45:02 +0200 Subject: [PATCH 2/4] Implement _W() on client context --- ScriptExtender/LuaScripts/BuiltinLibraryClient.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ScriptExtender/LuaScripts/BuiltinLibraryClient.lua b/ScriptExtender/LuaScripts/BuiltinLibraryClient.lua index 495bb72b..24f25fec 100644 --- a/ScriptExtender/LuaScripts/BuiltinLibraryClient.lua +++ b/ScriptExtender/LuaScripts/BuiltinLibraryClient.lua @@ -254,6 +254,20 @@ _C = function (playerIndex) return Ext.Entity.GetCharacter(charNetID) end +-- Debug helper to get the current player character's weapon +_W = function () + local char = _C() + local item + + if char then + local itemGUID = char:GetItemBySlot("Weapon") + + item = itemGUID and Ext.Entity.GetItem(itemGUID) + end + + return item +end + -- Debug helper to get character being examined _E = function () local examine = Ext.UI.GetByType(104) From 4c7b7e1d2b1a11680f4bad851e8a7e47b13ce1bc Mon Sep 17 00:00:00 2001 From: Kamil Date: Mon, 17 Oct 2022 19:52:21 +0200 Subject: [PATCH 3/4] Add global debug functions/aliases to IDE helpers --- .../Libs/HelpersGenerator/CustomEntries.lua | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/ScriptExtender/LuaScripts/Libs/HelpersGenerator/CustomEntries.lua b/ScriptExtender/LuaScripts/Libs/HelpersGenerator/CustomEntries.lua index f9881ec8..59ff2a8e 100644 --- a/ScriptExtender/LuaScripts/Libs/HelpersGenerator/CustomEntries.lua +++ b/ScriptExtender/LuaScripts/Libs/HelpersGenerator/CustomEntries.lua @@ -9,6 +9,30 @@ return { Specific = {SubscribableEventType = SubscribableEventType}, Misc = { [[ +--#region Debug/dev functions + +--- Returns the active controlled character. +--- @param playerIndex integer? Defaults to 1. +--- @return EclCharacter|EsvCharacter +function _C(playerIndex) end + +--- Returns the character being examined in the examine UI. +--- Client-only. +--- @return EclCharacter +function _E() end + +--- Returns the item equipped in the Weapon slot of the active controlled character. +--- In the client context, this uses player 1's character. +--- @return EclItem|EsvItem +function _W() end + +-- Aliases for logging functions. +_D = Ext.Dump +_DS = Ext.DumpShallow +_P = Ext.Utils.Print + +--#endregion + --#region Deprecated Functions (moved to Ext modules) --- @deprecated From 30441850eb0db79a7854eece59b679ae4612369b Mon Sep 17 00:00:00 2001 From: Kamil Date: Mon, 17 Oct 2022 20:11:12 +0200 Subject: [PATCH 4/4] Add usage warnings to IDE hints for global debug functions --- .../LuaScripts/Libs/HelpersGenerator/CustomEntries.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ScriptExtender/LuaScripts/Libs/HelpersGenerator/CustomEntries.lua b/ScriptExtender/LuaScripts/Libs/HelpersGenerator/CustomEntries.lua index 59ff2a8e..29130466 100644 --- a/ScriptExtender/LuaScripts/Libs/HelpersGenerator/CustomEntries.lua +++ b/ScriptExtender/LuaScripts/Libs/HelpersGenerator/CustomEntries.lua @@ -11,16 +11,19 @@ return { [[ --#region Debug/dev functions +--- @deprecated For debugging usage only - do not use in mod releases. --- Returns the active controlled character. --- @param playerIndex integer? Defaults to 1. --- @return EclCharacter|EsvCharacter function _C(playerIndex) end +--- @deprecated For debugging usage only - do not use in mod releases. --- Returns the character being examined in the examine UI. --- Client-only. --- @return EclCharacter function _E() end +--- @deprecated For debugging usage only - do not use in mod releases. --- Returns the item equipped in the Weapon slot of the active controlled character. --- In the client context, this uses player 1's character. --- @return EclItem|EsvItem