Jump to content

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!

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.

Edited by Mobbstar

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.

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
×
  • Create New...