Your First Lua Plugin
Briefing
Section titled “Briefing”A ‘plugin’ in Autorun-ng refers to an isolated package of either Lua code or a shared library. These can extend behavior of Autorun-ng using the API it provides.
Creating the plugin
Section titled “Creating the plugin”-
Create a folder named
my_first_plugininautorun/plugins:Terminal window mkdir -p autorun/plugins/my_first_pluginTerminal window mkdir autorun\plugins\my_first_plugin -
Add a
plugin.tomlfile inside of the folder:[plugin]name = "my_first_plugin"author = "you"version = "0.1.0"description = "This does the thing and it does it well"language = "lua" -
Add your
srcdirectory, alongsideclientandmenudirectories inside, with their respectiveinit.luafiles. You can leave them empty for now.Your folder structure should look like this:
Directorymy_first_plugin
Directorysrc
Directoryclient
- init.lua
Directorymenu
- init.lua
- plugin.toml
Your plugin now exists and will run the code inside. It’s time to write it.
Writing your first code
Section titled “Writing your first code”🟠 client
Section titled “🟠 client”This folder is for code that will run when you are in a server. It will run alongside addon code. This is where you should be worried about anti-cheat detection and creepy addons messing with stuff.
The init.lua file inside will run a single time whenever you join a server.
Example Code
Section titled “Example Code”Let’s make a simple plugin that prints a message to your Autorun console when you join a server.
local hostName = _G.GetHostName()Autorun.print("Hey, I just joined " .. hostName .. "!")What does this do?
Section titled “What does this do?”local hostName = _G.GetHostName()- This gets the server’s hostname using the GetHostName global C function provided by Garry’s Mod.Autorun.print("Hey, I just joined " .. hostName .. "!")- This prints your message to the Autorun console, NOT the in-game console. You’d useprintfor that.
🟢 menu
Section titled “🟢 menu”This folder is for code that will run in the Garry’s Mod menu a single time upon startup.
You don’t have to worry about detection here. No addon runs in the menu. This folder is just nice for if you want to customize your menu experience.
Example Code
Section titled “Example Code”Let’s make a simple plugin that prints today’s date and greets the user when you start Garry’s Mod.
local date = os.date("%Y-%m-%d")Autorun.print("Today is " .. date .. ", hello user.")What does this do?
Section titled “What does this do?”local date = os.date("%Y-%m-%d")- This gets today’s date in the format “YYYY-MM-DD” using Lua’s built-in os.date function.Autorun.print("Today is " .. date .. ", hello user.")- This prints your message to the Autorun console, NOT the in-game console. You’d useprintfor that.
Finished
Section titled “Finished”For menu plugins, you’ll have to restart Garry’s Mod for them to activate as they only run once upon startup of Autorun-ng.
This was a guide for a very basic plugin, it didn’t even go into events like Autorun.on!
For that, you’ll have to read the next guide.