Last active
June 5, 2024 18:22
-
-
Save juanarzola/371dcc7b282d64dc9135728fcb256d2a to your computer and use it in GitHub Desktop.
For ScriptExtender with Baldur's Gate 3: Output all Entities that match a component name and display name (empty string matches all)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- _Ents: Filters current entities in the engine, matching their component names and/or display names. | |
-- | |
-- @param pattern: filter by entities with component names matching pattern. Empty string "" matches all. | |
-- @param displayNamePattern: filter by entities with displayName (where displayName is a heuristic determined | |
-- from various components) matching `displayNamePattern`. Empty string "" matches all. | |
-- @param withComponents: include component names in the output result | |
-- | |
_Ents = function(pattern, displayNamePattern, withComponents) | |
local entities = Ext.Entity.GetAllEntities() | |
local result = {} | |
local i = 0 | |
for key, entity in pairs(entities) do | |
-- match by component name | |
local componentNames = entity:GetAllComponentNames(true) | |
local foundComponent = false | |
for name, nameVal in pairs(componentNames) do | |
if string.find(nameVal, pattern) then | |
foundComponent = true | |
break | |
end | |
end | |
if foundComponent then | |
local uuid = (entity.Uuid and entity.Uuid.EntityUuid) and entity.Uuid.EntityUuid or key | |
local statsId = (entity.Data and entity.Data.StatsId ~= "") and entity.Data.StatsId or "unnamed" | |
local displayName = (entity.DisplayName and entity.DisplayName.Name ~= "") and entity.DisplayName.Name or statsId | |
local key = displayName .. "(" .. uuid .. ")" | |
-- match by displayName | |
if string.find(key, displayNamePattern) then | |
if withComponents then | |
result[key] = componentNames | |
else | |
result[i] = key | |
i = i + 1 | |
end | |
end | |
end | |
end | |
return result | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment