Jump to content

Searching for a specific prefab


Somnei

Recommended Posts

Hey! 

I need a function which finds a specific entity within a certain prefab.

My script links an item and a mob together using an id, and upon the mob's death I want it to locate the correct item linked with the mob, and de-link them so that the item is reusable with another mob.

 

What I am looking for is something similar to the existing function "TheSim:FindFirstEntityWithTag("tag")" but something a little more versatile since adding a tag upon linking the items doesn't seem to work properly when saving and loading. I've tried using the "c_findnext()" function from consolecommands, but looping that function several times to find the right entity among others (like ~20) makes the game freeze for a while.

 

So, does anyone have and recommend of an existing function, or knows where I can find the other "TheSim" functions? Sorry if I'm unclear, kinda tired from messing around with this all day lol

Link to comment
Share on other sites

You can iterate though all entities in the global "Ents" table. Many mods use this method, for example my mod Industrial Resolution.

 

Also, ids sound complicated. You can link the entities using direct references. (e.g. inst.linkedinst = otherinst)

Link to comment
Share on other sites

You can iterate though all entities in the global "Ents" table. Many mods use this method, for example my mod Industrial Resolution.

 

Also, ids sound complicated. You can link the entities using direct references. (e.g. inst.linkedinst = otherinst)

 

Yeah, I used the ents and it totally worked. Just a minute ago I realized that I might have been able to localize the right object simply by identifying the mobs' leader. (basically I just made everything much more complicated than it had to be)

But well, in the end I managed to get generated ids to work and everything worked out. In the future I will probably just use references, so thanks for that suggestion. I was thinking it might work, but I was so stuck on making this work that I didn't even bother checking haha

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...