Add entities in a loop

Hello, I’m currently working on some scripted entities and since they all use the same cl_init.lua and init.lua with shared.lua containing settings, I was woundering if instead of having a folder for each one of them I could just have a base entity and all other entities are created in a loop with different shared.lua or taking settings from another file containing settings for each individual entity and how could I do this.
Hopefully someone can help me, thank you in advance.

Yes.
Just create a generic table like data that’ll hold all info differentiating this entity from others.

For example… if you have entity called ent_food and you want it to have a different model, name and recover different amount of hunger - you simply do:

self.data = {}
self.data.name = “Placeholder”
self.data.recovery = 0
self.data.model = “example.mdl”

Then after you spawn it, you can either add a function to entity for applying different template or you can apply it right away.

self.data = someconfig[ “Melon” ]
self:SetModel( self.data.model )

etc.

But is there a way of creating theese entities as seperate ones at once, for example counting how many entities are in a seperate data table and adding them with their own data table.
So for example I have ent_food as the base and two tables in a config called ent_burger and ent_orange, it adds theese entities as sperate ones and they both have thier own class.

Separate class? Not really, unless you toy with http://wiki.garrysmod.com/page/Category:list

Alright, So I guess my best bet would be having a config containing settings for all entities and just have 1 line in each entity’s shared.lua calling the table from the config, right?

My main problem is simplifying the process of adding new entities and editing their settings, but I guess this would work to some extent, without having to edit each single entity’s files, instead just using the main config and editing a single line in shared.lua to match the table.

You aren’t actually simplifying the process.
Using as many as possible amount of files (not fully true, the number should be sensible but categorising stuff and putting it into separate files is smart).

[editline]30th December 2016[/editline]

I would suggest having one template entity per thing - just like with ent_food for melons, oranges etc.
If you have difficulty for example - storing them in your inventory, you can always store the data too and make your inventory interprete it.

Get the existing base entity with

change various variables on what that function returns, and register your new entity with

Thanks for all the Help Netheous!

Gonna try out that method Fruitwesp, seems like what I wanted to use initially.

UPDATE: Testing out the method you suggested Fruitwesp, even without changing any variables and registering a new entity, I get an invisible entity, Functions seem to work fine, but the entity is invisible and I get


Error creating 'test1' (Make sure the file is AddCSLuaFile'd and there aren't any errors!)

tried doing the same with other entities and getting the same error and invisible entity.
Any Idea why this is happening?