some confusion about the lua filestructure

Alright, so I have lua files for some SENTS in a bunch of subdirectories. How does GMOD get told to load them? When I have the files in simply /lua/entities everything works, but when I put stuff in subdirs within /lua/ents, or in an addon, it doesn’t. Do I need an autorun script to do this?

It depends on if it’s a gamemode entity, an addon, or directly installed into the lua/ dir.

Gamemodes look in gamemode_name/entities/* for any .lua files. If any are found then they will be executed serverside, if you call AddCSLua in that file it will be sent to the client. The client will auto-run the file as well. That’s the standard way for fully shared entities. Next it will check gamemode_name/entities/* for folders. Any folders found will then be checked for an init.lua. If one is found then it will be run serverside and it is the devs job to AddCSLua the client/shared files. On the client it will look for a cl_init.lua, if it finds one then it will execute that clientside. From that file you can then include shared.lua or any other files.

Addons work similar to how you would just drop the entity into your lua/ dir. An addon gets it’s content mounted relative to the garrysmod/ dir. And like gamemode entities the server will look in lua/entities/* for either entity_name.lua first and run it serverside. Then it will look for subfolders in the lua/entities/* directory and run init.lua serverside and then cl_init.lua clientside (You still need to AddCSLua cl_init.lua in the init.lua though!).

Garrysmod loads from specific magic directories automatically.
These include:
lua/autorun/*
lua/autorun/client/*
lua/autorun/server/*
lua/entities/*
lua/weapons/*
lua/effects/*

If you want to put stuff anywhere else, you’re going to need to include that yourself.