Mobbstar Posted July 19, 2014 Share Posted July 19, 2014 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 https://forums.kleientertainment.com/forums/topic/38710-best-way-to-find-if-there-is-an-instance/ Share on other sites More sharing options...
Heavenfall Posted July 19, 2014 Share Posted July 19, 2014 Use global table Ents which holds a list of all existing prefabs. Link to comment https://forums.kleientertainment.com/forums/topic/38710-best-way-to-find-if-there-is-an-instance/#findComment-512707 Share on other sites More sharing options...
Mobbstar Posted July 19, 2014 Author Share Posted July 19, 2014 (edited) Use global table Ents which holds a list of all existing prefabs. If stumbled upon that in my research: Your post regarding flowersEnts is a table... 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 July 19, 2014 by Mobbstar Link to comment https://forums.kleientertainment.com/forums/topic/38710-best-way-to-find-if-there-is-an-instance/#findComment-512711 Share on other sites More sharing options...
DeathDisciple Posted July 19, 2014 Share Posted July 19, 2014 If stumbled upon that in my research: Your post regarding flowersEnts is a table... 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 likelocal counter=0for k,v in pairs(GLOBAL.Ents) do if(v.prefab==your_prefab_name)then counter=counter+1 endendor such. Obviously the above is prone to typos as I'm writing blindly but you get the idea. Link to comment https://forums.kleientertainment.com/forums/topic/38710-best-way-to-find-if-there-is-an-instance/#findComment-512715 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now