Skip to content

Your First Lua Plugin

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.

  1. Create a folder named my_first_plugin in autorun/plugins:

    Terminal window
    mkdir -p autorun/plugins/my_first_plugin
  2. Add a plugin.toml file 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"
  3. Add your src directory, alongside client and menu directories inside, with their respective init.lua files. 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.

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.

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 .. "!")
  1. local hostName = _G.GetHostName() - This gets the server’s hostname using the GetHostName global C function provided by Garry’s Mod.
  2. Autorun.print("Hey, I just joined " .. hostName .. "!") - This prints your message to the Autorun console, NOT the in-game console. You’d use print for that.

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.

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.")
  1. 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.
  2. Autorun.print("Today is " .. date .. ", hello user.") - This prints your message to the Autorun console, NOT the in-game console. You’d use print for that.

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.