📦Package Creation

A guide to creating your own package on gpm.

For the most part, gpm packages do not differ from classic lua addons, main difference is the way they are run and the execution environment, which allows more efficient development of addons, libraries and frameworks.

Make your first package

Creating folder for your package

First what we need to do is create our addon folder in garrysmod/addons like garrysmod/addons/my-first-package/ where my-first-package is our package name.

As we plan to create a package on lua we will need the following folders and full path with them will look like this: garrysmod/addons/my-first-package/lua/packages/

Single-file package ( Simple package )

This is a package that is simply an executable file that runs everywhere identically and automatically, such packages have no version and no parameters, they obey the default configuration.

If we want to create single-file package, we need to .

Multi-file package ( Classic package )

This package can have a full-fledged, almost unlimited complex multi-file structure, the complexity of which depends directly on its developer, such a package must have a package.lua file to ignore default configuration.

If we want to create a package, we need to create and in this folder create a file with package configuration.

package.lua

Example of most package file variables

-- lua/packages/example-package/package.lua
name = "example-package"
version = 000100

-- Files to be used as an entry point into the package, supports relative paths and global relative to "lua/"
init = {
    ["client"] = "cl_init.lua",
    ["server"] = "init.lua",
    ["menu"] = "init.lua"
}

-- If there is no autorun, the package will wait for import from another package
autorun = true

-- Don't touch it if you don't know what you're doing
environment = true

-- Client files ( supports relative paths and global paths by "lua/" )
send = {
    "file.lua",
    "my_addon/file2.lua"
}

-- If false, the logger will not be created by default and logs color
logger = false
color = Color( 255, 255, 0 )

-- Allowed gamemodes list, if nil then all gamemodes are allowed
gamemodes = {
    "sandbox",
    "darkrp"
}

-- Allowed maps list, if nil then all maps are allowed
maps = {
    "gm_construct"
}

-- If true, then the package is allowed to run only in a singleplayer game
singleplayer = false

-- Enables automatic naming for listed libraries, e.g. all hooks with hook = true will have a package identifier in the hook name, if the hook name is a string of course...
autonames = {
    ["properties"] = true,
    ["timer"] = true,
    ["cvars"] = true,
    ["hook"] = true,
    ["net"] = false
}

Tricks

  • Configuration file can run any scripts and operations to get more information about the package, it has access to all glua global variables.

version = file.Read( "my-first-package-version.lua", "DATA" )
  • It is not necessary to declare parameters for a package file as in the example, you can just return a table or create a Package table.

return {
    name = "my-first-package",
    version = "1.0.0",
    autorun = false
}
Package = {
    name = "my-first-package",
    version = "0.0.1",
    autorun = true
}
  • Package file is case insensitive, so we can format it as we like.

Name = "My First Package"
VERSION = "Soo cool version"
AuToRuN = true
return {
    ["Name"] = "MFP",
    ["Version"] = 000100,
    ["AutoRun"] = true
}

Last updated