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

Add selfaware functions for E2 extensions #2823

Merged
merged 3 commits into from
Nov 12, 2023
Merged
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
54 changes: 54 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,48 @@ e2function number entity:canSetName(string name)
return IsValid(this) and isOwner(self, this) and canSetName(self, this, name) and 1 or 0
end

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

local getExtensionStatus = E2Lib.GetExtensionStatus
local e2Extensions
local e2ExtensionsTable
-- See postinit for these getting initialized

__e2setcost(30)

[nodiscard]
e2function array getExtensions()
Vurv78 marked this conversation as resolved.
Show resolved Hide resolved
local ret = {}
for k, v in ipairs(e2Extensions) do -- Optimized copy
ret[k] = v
end
return ret
end

__e2setcost(60)

[nodiscard]
e2function table getExtensionStatus()
Vurv78 marked this conversation as resolved.
Show resolved Hide resolved
local ret = E2Lib.newE2Table()
local s, stypes = ret.s, ret.stypes
ret.size = e2ExtensionsTable.size

for k, v in pairs(e2ExtensionsTable.s) do
s[k] = v
stypes[k] = "n"
end

return ret
end

__e2setcost(5)

[nodiscard]
e2function number getExtensionStatus(string extension)
return getExtensionStatus(extension) and 1 or 0
end


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

Expand Down Expand Up @@ -287,6 +329,18 @@ registerCallback("postinit", function()
end
end
end

e2Extensions = E2Lib.GetExtensions()
e2ExtensionsTable = E2Lib.newE2Table()
do
local s, stypes, size = e2ExtensionsTable.s, e2ExtensionsTable.stypes, 0
for _, ext in ipairs(e2Extensions) do
s[ext] = getExtensionStatus(ext) and 1 or 0
stypes[ext] = "n"
size = size + 1
end
e2ExtensionsTable.size = size
end
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
Loading