Server addon beginner question

I’ve finished my first addon recently. It is located in some gamemode (darkrp) lua files and works. Now I want to extract it from there and put it in an own addon folder. But before I can do that I have to go through some basics:

This is the structure of my addon folder:

addons/<addonname>/lua/autorun/init.lua
addons/<addonname>/lua/cl_init.lua
addons/<addonname>/lua/shared.lua

Contents:

/---------------------------------------------------------------------------
shared.lua:
---------------------------------------------------------------------------
/

function sharedWorks ( ply, command, arguments )
MsgN( “shared.lua seems to work.” )
end
concommand.Add( “Test_shared”, sharedWorks )

/---------------------------------------------------------------------------
init.lua:
---------------------------------------------------------------------------
/

AddCSLuaFile( “cl_init.lua” )
AddCSLuaFile( “shared.lua” )

include( ‘shared.lua’ )

function initWorks( ply, command, arguments )
MsgN( “init.lua seems to work.” )
end
concommand.Add( “Test_init”, initWorks )

/---------------------------------------------------------------------------
cl_init.lua:
---------------------------------------------------------------------------
/

include( ‘shared.lua’ )

function cl_initWorks( ply, command, arguments )
MsgN( “cl_init.lua seems to work.” )
end
concommand.Add( “Test_cl_init”, cl_initWorks )

/*---------------------------------------------------------------------------

---------------------------------------------------------------------------*/

This was tested on a dedicated server. Console commands from shared.lua and init.lua work , but cl_init doesn’t show up anything. Also no errors in console. Please tell me my mistake.

If your code is standalone (Not part of a gamemode/entity) you should place it all in the appropriate autorun folder.

lua/autorun/ executes on both the client and the server.
lua/autorun/client/ executes on the client.
lua/autorun/server/ executes on the server.

Since you’re not really initializing anything (a gamemode or an entity) your files can have any name you want them to.

When making a gamemode/entity the server will automatically run init.lua and the client will run cl_init.lua.

Shared.lua is just a commonly used name for a file containing information required by both the client and the server. It doesn’t do anything special.

Your detailed explanation helped me a lot. Thank you. :slight_smile: