Jump to content

Create an array of all prefabs with a tag?


Recommended Posts

Is anyone aware of a method by with an array can be generated that lists all prefabs that have a specific tag?  I'd like to be able to reference all hounds, default or modded, which allows me to edit them or summon them etc.  I have a suspicion that there is no known way to do this, not unless I summon everything and check their stats every time the game is loaded..  Regardless, I figured I'd ask.

Link to comment
Share on other sites

runtime: create a hook function AddTagPostInit within EntityScript, or create a function that runs in AddPrefabPostInitAny to gather instances, or hook CreateEntity&RemoveEntity to do things similar to the game.

static or runtime: run a string match function for every registered prefab file in scripts/prefabs/ and search for 'AddTag'. But this can be wrong if the syntax is complicated.

only once: search in Ents.

  • Like 1
Link to comment
Share on other sites

@Rickzzs
Thanks.  I spoke with IronHunter about this and they believe it would work, though it sounds like it might require more processing power/code than I was expecting.  I was thinking of updating Wirra’s plushies so they could summon modded hounds added by other mods but it sounds like these options might be a bit too taxing.  If you disagree feel free to say so.

Link to comment
Share on other sites

11 hours ago, FurryEskimo said:

@Rickzzs
Thanks.  I spoke with IronHunter about this and they believe it would work, though it sounds like it might require more processing power/code than I was expecting.  I was thinking of updating Wirra’s plushies so they could summon modded hounds added by other mods but it sounds like these options might be a bit too taxing.  If you disagree feel free to say so.

If your target is a selected range of mods you can just run a preprocessor with that mod's file or run in game. And you keep updated with these mods. In this case you can manually search in workshop to find all mods that introduces modded hounds and add them. I think there are few.

Link to comment
Share on other sites

@Rickzzs
While that would work I’d prefer not to have to update the mod forever.  It’s a good idea, though how do I check if another mod is enabled?  Also, can I check if those prefabs exist before I try accessing them?  People may rename the prefabs.

In general I’d prefer to not be expected to update the mod forever, which is why I was hoping there was an easy way to search all prefabs for tags.  Right now I need to maintain the list of available favorite foods and even that’s something I wish could update itself via an array that just references all food items.

Link to comment
Share on other sites

@FurryEskimo A slightly less performant method is to do a AddPrefabPostInitAny and check for the "hound" tag.  Similar to the AddPlayerPostInit example in modutil.  Will rely on mods to have the proper tag for their prefabs, but that's on them to follow proper tagging systems.  Though this method would rely on having one out first before being able to store the reference.  Might be an interesting quirk to the character's summon limits.

For the favorite foods you can player post init, and check for foodaffinity component and see which prefabs have an affinity.  It could be assumed that the highest amount is the player's favourite, but mods will probably break this assumption.  The foodaffinity component's prefab_affinities is the table of prefabs to bonuses that you can iterate over.

Edited by CarlZalph
  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...