Jump to content

Best way to find if there is an instance?


Recommended Posts

I am almost done with the 1.0 of my most recent mod (beta is already avaible), but I stumbled upon this issue:

 

How does one detect whether there is an instance of a prefab in the world?

 

I really just want to know if there are any instances, numbers would be a bonus. But the prefabs don't have unique tags, or any.

FindEntities only works with tags, so that falls through.

I don't know enough about the way instances are handled by the game, to find an answer myself. There doesn't seem to be such an method in use by the base game, at most it's FindEntities.

I've been looking for c_gonext("prefab"), but can't find it.

 

Anyone who has an idea to this is free to post it below. Thank you in advance!

Link to comment
Share on other sites

Use global table Ents which holds a list of all existing prefabs.

 

If stumbled upon that in my research: Your post regarding flowers

Ents is a table...  :wilson_facepalm:

 

EDIT: Thanks a lot, it works well in my simple function. I'll improve it for advanced conditions, and maybe upload the full version of the mod tonight already. Of course I've scribbled down a little "thx Heavenfall" in the code. I hope you are fine with that.

 

EDIT2: Thanks ninjaDescipline, I appreciate that you give a example of how to use Ents. I made my function already, maybe someone else needs it though. And then they will find this threadful thread, along with an clear answer.

Link to comment
Share on other sites

If stumbled upon that in my research: Your post regarding flowers

Ents is a table...  :wilson_facepalm:

 

Ents is a table containing all entities, what you want to do is write your own function based on it that would return... whatever you need really, doing something like

local counter=0for k,v in pairs(GLOBAL.Ents) do   if(v.prefab==your_prefab_name)then      counter=counter+1   endend

or such. Obviously the above is prone to typos as I'm writing blindly but you get the idea.

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...