Skip to content

Commit

Permalink
Add selfaware functions for E2 extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
Denneisk committed Nov 3, 2023
1 parent 12e109e commit 2cb57ef
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
28 changes: 28 additions & 0 deletions lua/entities/gmod_wire_expression2/core/selfaware.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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


--[[******************************************************************************]]--

Expand Down
3 changes: 3 additions & 0 deletions lua/wire/client/e2descriptions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 2cb57ef

Please sign in to comment.