From 2cb57ef7bbf381806c58ec3b21d84e493695ce4b Mon Sep 17 00:00:00 2001 From: Denneisk <20892685+Denneisk@users.noreply.github.com> Date: Fri, 3 Nov 2023 14:33:04 -0400 Subject: [PATCH] Add selfaware functions for E2 extensions --- .../gmod_wire_expression2/core/selfaware.lua | 28 +++++++++++++++++++ lua/wire/client/e2descriptions.lua | 3 ++ 2 files changed, 31 insertions(+) diff --git a/lua/entities/gmod_wire_expression2/core/selfaware.lua b/lua/entities/gmod_wire_expression2/core/selfaware.lua index de3cee296c..47b9d113f1 100644 --- a/lua/entities/gmod_wire_expression2/core/selfaware.lua +++ b/lua/entities/gmod_wire_expression2/core/selfaware.lua @@ -203,6 +203,34 @@ e2function number entity:canSetName(string name) return IsValid(this) and isOwner(self, this) and canSetName(self, this, name) and 1 or 0 end +--[[******************************************************************************]]-- +-- Extensions + +[nodiscard] +e2function array getExtensions() + return table.Copy(E2Lib.GetExtensions()) +end + +local getExtensionStatus = E2Lib.GetExtensionStatus +[nodiscard] +e2function table getExtensionStatus() + local ret = E2Lib.newE2Table() + local s, stypes, size = ret.s, ret.stypes, ret.size + for _, ext in ipairs(E2Lib.GetExtensions()) do + s[ext] = getExtensionStatus(ext) and 1 or 0 + stypes[ext] = "n" + size = size + 1 + end + ret.s, ret.stypes, ret.size = s, stypes, size -- Do this just because I'm paranoid + + return ret +end + +[nodiscard] +e2function number getExtensionStatus(string extension) + return getExtensionStatus(extension) and 1 or 0 +end + --[[******************************************************************************]]-- diff --git a/lua/wire/client/e2descriptions.lua b/lua/wire/client/e2descriptions.lua index 8a967f3283..6b91fb0a6e 100644 --- a/lua/wire/client/e2descriptions.lua +++ b/lua/wire/client/e2descriptions.lua @@ -898,6 +898,9 @@ E2Helper.Descriptions["ioOutputEntities(s)"] = "Returns an array of all entities E2Helper.Descriptions["runOnLast(n)"] = "If set to 1, the chip will run once when it is removed, setting the last() flag when it does" E2Helper.Descriptions["selfDestruct()"] = "Removes the expression" E2Helper.Descriptions["selfDestructAll()"] = "Removes the expression and all constrained props" +E2Helper.Descriptions["getExtensions()"] = "Returns an array of all the extensions that the server has. This includes disabled extensions!" +E2Helper.Descriptions["getExtensionStatus()"] = "Returns a table of extension names with their statuses" +E2Helper.Descriptions["getExtensionStatus(s)"] = "Returns 1 if the extension is enabled, otherwise 0" -- Debug E2Helper.Descriptions["playerCanPrint()"] = "Returns whether or not the next print-message will be printed or omitted by antispam"