Creating a workaround

Learn to code your own workaround

circle-info

This tutorial assumes you are familiar with coding in Garry's Mod and creating addons.


What is a workaround?

A workaround is a system which can be toggled on & off (in the Base's page menu). Its purpose is mainly to allow users to choose to fix issues & conflicts with external addons. A workaround can be targeted for a specific realm (server, client or both) in order to fix all eventual issues.

All workarounds (except during hot reload) are initialized during the GM:InitPostEntity hook, assuming that during this time, all fixable hooks should be defined.

Examples

See these two examples from the base:


Setting up the file structure

There are multiple ways of setting up the file structure to define the workarounds:

  • creating the Lua file in lua/autorun/

  • creating the Lua file in lua/guthscp/base/workarounds/

  • creating the Lua file in a folder of your module and add it to your requires (recommended)

circle-exclamation

Defining the workaround

Open your script and start by creating a WORKAROUND local table which you register as follow:

The WORKAROUND table is what defines your workaround, it will contains properties like the name, the targeted realm & methods that you will define. You also have to specify the identifier of your workaround yourself in the registering function call: choose a unique & recognizable name so it doesn't conflict with any other workarounds.

Now, you should fill the required properties:

This is the bare minimum to make a workaround register in the system and to see it in the guthscpbase menu. Of course, edit them as you'll like.

circle-info

For more information about the workaround class, read this page.


Adding logic

circle-exclamation

Last updated