Saving Entities - flatfile.

Hello Facepunch,

I have a little idea i’ve come up with, but before I start I’d like to know the best way of how to approach this. I’m planning on making an entity and this entity will be spawned around the map and will save all them specific entities and locations i.e using a simple console command save_all_testents.

This is my concern, would it be a bad idea every time I spawn that specific entity, add it to a table and if i spawn another, add that one to the table too! So when I want to save them I simply run the command, loop through the table and save their locations etc,

Is this a good method of doing this, does anyone else know any efficient ways?

I appreciate your help, thank you.

From what I know, the best way to approach this situation would be to use a table as what you are trying to do here is to store data, which is what tables are used for.

If you aim to have this on only 1 server then you should save this table to a text file so that when the server is restarted, the entities are still saved. If you plan on using this system with the same entities on multiple servers then you should use a database such as mysql.

Please take into account that I am not an expert so this information may not be accurate, but its what I’ve learned from experience.

You could just use ents.FindByClass(“entity_name”) that creates a table of all the existing entities you specified. You can then loop through that table like so.



for k,v in pairs(ents.FindByClass("entity_name")) do
           print(v:GetPos())
end