Defines the global plugin library, which loads plugins and the schema and dispatches hooks to them.

plugin.Include loads a plugin from its plugin folder or a single file, together with its entities and its extra folders (items, commands, language and so on), and plugin.Add registers a library as a hook module. The functions of every plugin and module are cached by name, and hook.Call is replaced so they run before the regular hooks and the gamemode. plugin.SetUnloaded turns a plugin off.

Summary

Functions

Adds a table as a module whose functions run as hooks, like a plugin's.
Adds a folder name that is loaded from every plugin and the schema.
Adds every function of a table to the hook cache, so it runs as a hook of the same name.
Calls a hook on every loaded plugin, module and the schema, then on the hooks added with hook.Add.
Empties the hook cache, so no plugin hooks run until functions are cached again.
Prints the hook cache to the console.
Returns a registered plugin by name.
Returns the hook cache that hook.Call runs plugin hooks from.
Returns the names of the folders loaded from every plugin, as added with plugin.AddExtra.
Returns every module added with plugin.Add, indexed by name.
Returns every registered plugin, indexed by name.
Returns the folder names of the plugins that are unloaded.
Returns whether the plugin system has been initialized.
Loads a plugin from its plugin folder or from a single Lua file.
Loads and registers the weapons, entities and effects in a plugin's entities folder.
Loads a plugin's or schema's entities and extra folders.
Loads every plugin in a directory's plugins folder, both single files and folders.
Initialize()shared internal
Initializes the plugin system, restoring the saved list of unloaded plugins on the server.
Returns whether a plugin is disabled because a plugin containing it is unloaded.
Returns whether a plugin is unloaded.
New()shared
Creates a new plugin table for the plugin being included.
Registers a plugin, caches its hooks and loads its contents.
Removes a module added with plugin.Add and its hooks.
Removes a plugin's or module's functions from the hook cache.
Sets whether the plugin system has been initialized.
Sets whether a plugin is unloaded and saves the list of unloaded plugins.

Functions

plugin.Add(name, moduleTable, hookOrder)

shared gamemodes/catwork/gamemode/core/libraries/sh_plugin.lua:516

Adds a table as a module whose functions run as hooks, like a plugin's.

plugin.Add('Voices', cw.voices)

Parameters

  • name String Name of the module; also set as the table's name when it has none
  • moduleTable Map The module table
  • hookOrder Number optional, defaults to 0 Stored as the module's hookOrder

See also

Adds a folder name that is loaded from every plugin and the schema.

items folders are loaded with item.IncludeItems, others with util.IncludeDirectory.

Parameters

  • folderName String Name of the folder

plugin.CacheFunctions(obj, id)

shared gamemodes/catwork/gamemode/core/libraries/sh_plugin.lua:468

Adds every function of a table to the hook cache, so it runs as a hook of the same name.

Parameters

  • obj Map The plugin, schema or module table
  • id String optional, defaults to nil Name shown in hook error messages

Calls a hook on every loaded plugin, module and the schema, then on the hooks added with hook.Add.

No gamemode table is passed on, so the gamemode's own function of that name is not called; use hook.Run for that.

local canSpawn = plugin.Call('PlayerCanSpawnItem', player, itemTable)

Parameters

  • name String Name of the hook
  • ... Any Arguments passed to the hook

Returns

  • Any Up to six values returned by the first hook that returned anything

See also

Empties the hook cache, so no plugin hooks run until functions are cached again.

Prints the hook cache to the console.

Returns a registered plugin by name.

Parameters

  • identifier String Name of the plugin

Returns

  • Plugin The plugin, or nil when not registered

Returns the hook cache that hook.Call runs plugin hooks from.

Returns

  • Map Lists of { func, owner, id = moduleName } entries indexed by hook name

Returns the names of the folders loaded from every plugin, as added with plugin.AddExtra.

Returns

  • List<String> The folder names

Returns every module added with plugin.Add, indexed by name.

Returns

  • Map The module tables indexed by name

Returns every registered plugin, indexed by name.

Returns

  • Map<Plugin> The plugins indexed by name

Returns the folder names of the plugins that are unloaded.

Returns

  • Map true for each unloaded plugin's folder name

Returns whether the plugin system has been initialized.

Returns

Loads a plugin from its plugin folder or from a single Lua file.

Creates the global PLUGIN with plugin.New, merges in the plugin.ini data (on the server from the file, on the client from CW_SCRIPT_SHARED), runs sh_plugin.lua unless the plugin is unloaded or disabled, then registers it. A plugin that was already loaded keeps its table on refresh.

For a single-file plugin the folder name is taken from the parent directory, which is always plugins.

Parameters

  • directory String Lua path of the plugin's plugin folder, or of a .lua file

plugin.IncludeEntities(folder)

shared gamemodes/catwork/gamemode/core/libraries/sh_plugin.lua:561

Loads and registers the weapons, entities and effects in a plugin's entities folder.

Each weapons, entities and effects subfolder may hold folders (with shared.lua, init.lua and cl_init.lua) or single files, loaded with SWEP, ENT or EFFECT set and registered under the file or folder name. Effects are only registered on the client.

Parameters

  • folder String Lua path of the entities folder

plugin.IncludeExtras(directory)

shared gamemodes/catwork/gamemode/core/libraries/sh_plugin.lua:662

Loads a plugin's or schema's entities and extra folders.

Parameters

  • directory String Lua path of the plugin or schema folder

See also

plugin.IncludePlugins(directory)

shared gamemodes/catwork/gamemode/core/libraries/sh_plugin.lua:633

Loads every plugin in a directory's plugins folder, both single files and folders.

Initializes the plugin system first when needed.

Parameters

  • directory String Lua path of the directory that contains the plugins folder

Internal

This function is internal. It is not part of the public API and may change without notice.

Called by plugin.IncludePlugins before the first plugin is loaded.

Initializes the plugin system, restoring the saved list of unloaded plugins on the server.

Does nothing when already initialized.

plugin.IsDisabled(name, bFolder)

shared gamemodes/catwork/gamemode/core/libraries/sh_plugin.lua:157

Returns whether a plugin is disabled because a plugin containing it is unloaded.

Unloaded plugins are looked up with plugin.FindByID by folder name, so this only finds parents whose folder name matches their name.

Parameters

  • name String Name of the plugin, or its folder name when bFolder is set
  • bFolder Boolean optional, defaults to nil Treat name as a folder name

Returns

  • Boolean Whether the plugin is disabled

plugin.IsUnloaded(name, bFolder)

shared gamemodes/catwork/gamemode/core/libraries/sh_plugin.lua:210

On the server

Returns whether a plugin is unloaded.

Parameters

  • name String Name of the plugin, or its folder name when bFolder is set
  • bFolder Boolean optional, defaults to nil Treat name as a folder name

Returns

  • Boolean Whether the plugin is unloaded; always false for the schema

On the client

Returns whether a plugin is unloaded, taking overrides set with plugin.SetUnloaded into account.

Parameters

  • name String Name of the plugin, or its folder name when bFolder is set
  • bFolder Boolean optional, defaults to nil Treat name as a folder name

Returns

  • Boolean Whether the plugin is unloaded; always false for the schema

Defined in

Creates a new plugin table for the plugin being included.

Uses the PLUGIN_BASE_DIR and PLUGIN_FOLDERNAME globals set by plugin.Include.

Returns

  • Plugin The new plugin

Registers a plugin, caches its hooks and loads its contents.

Unless the plugin is unloaded, its functions are added to the hook cache, its extras (items, commands, entities...) are loaded with plugin.IncludeExtras and, on the client, a page is added to the directory. The plugins inside a folder plugin's plugins folder are then loaded.

Parameters

  • pluginTable Plugin The plugin

Removes a module added with plugin.Add and its hooks.

Parameters

  • name String Name of the module

Removes a plugin's or module's functions from the hook cache.

Parameters

  • id Any The table, or the name of a registered plugin

plugin.SetInitialized(bInitialized)

shared gamemodes/catwork/gamemode/core/libraries/sh_plugin.lua:273

Sets whether the plugin system has been initialized.

Parameters

  • bInitialized Boolean Whether the plugin system has initialized

plugin.SetUnloaded(name, isUnloaded)

shared gamemodes/catwork/gamemode/core/libraries/sh_plugin.lua:189

On the server

Sets whether a plugin is unloaded and saves the list of unloaded plugins.

The change takes effect the next time plugins are loaded. The schema cannot be unloaded.

Parameters

  • name String Name of the plugin
  • isUnloaded Boolean Whether the plugin should be unloaded

Returns

  • Boolean Whether the plugin was found

On the client

Overrides whether a plugin is shown as unloaded on the client.

Only changes what plugin.IsUnloaded returns on the client, e.g. to reflect a pending change.

Parameters

  • name String Name of the plugin
  • isUnloaded Boolean Whether the plugin should count as unloaded; nil removes the override

Defined in

Defined in