Some description
The addon creates a unique server-side variable svuid at first startup, which is transferred to the players when they connects. This way the addon understands which config from the data folder should be used.
If you have added / deleted / made important changes, you may need to change the svuid so that all players start using the new config (does not apply to players who first logged into the server). To do this, go to the server folder, go to garrysmod\data\sv_esclib, delete the server_uid.json file and restart the server. In this way you will update the settings of all players, resetting them to the base (from your config)
Entry point
You can use the hook hook.Add("esclib_loaded", "unique_name", function()) to track the loading of the library and then use the function esclib.loader:New("ehud","ehud/",function(load) to connect the addon load to the library.
Example
ehud/lua/autorun/ehud_load.lua - will be launched automatically by Garry's mod
ehud/lua/ehud - main folder with all addon lua files
local function loader()
--Using esclib loader system
--params: unique name, folder, function with loader structure
esclib.loader:New("ehud","ehud/",function(load)
--fonts used in addon
load:Resource("resource/fonts/unisans.ttf")
--In workshop content
load:Resource("sound/ehud_hitmark.wav")
load:MaterialFolder("materials/ehud",true,false) --load.Materials params: path, isrecurse, send2players
--Materials, loaded in this function stored in load.Materials
ehud.Materials = ehud.Materials or {}
table.Merge(ehud.Materials, load.Materials) --save load.Materials to ehud.Materials
load:Shared("config/meta.lua") -- load client and server | see next step(Defining an addon instance)
load:Shared("config/config.lua") -- see next topic
load:Shared("config/language.lua") -- see 3 topic
load:Shared("config/theme.lua") -- see 4 topic
load:Client("core/__core__.lua")--load client file
load:ClientFolder("vgui")--load all files from "vgui" folder
load:Server("core/__servercore__.lua")--load server file
end)
end
--if already exist(lua refresh compat)
if esclib then
if esclib.loader.addons["ehud"] then
if esclib.loader.addons["ehud"].finished then
loader()
end
end
end
--hook itself
hook.Add("esclib_loaded", "ehud_load", function()
loader()
end)
Defining an addon instance
While loading the addon, you will need to create an instance of the addon. In order to do this, you can create a file in the config folder called meta.lua with the following contents:
ehud/lua/ehud/config/meta.lua
ehud = ehud or {} --creating global
ehud.addon = esclib:Addon("ehud")--unique id for addon, saving as ehud attribute
ehud.addon:SetName("EHud") --The main name for the addon, will be displayed in the game
ehud.addon:SetBranch("main") --The name for the addon branch. Used for display only.
ehud.addon:SetVersion(1.1) --can be str or int type. Addon version, used only for displaying
if CLIENT then
ehud.addon:SetColor(Color(13,255,73))--Addon accent color, used only to display
ehud.addon:SetThumbnail(ehud.Materials["ehud_icon.png"])--Icon to display in settings
end
To display the available functions / fields you can use PrintTable(ehud.addon)