Skip to content

PLUGIN

Plugin Hook Documentation.

Base hooks for plugins. Hooks are functions that can have code appended to, and are triggered at specific events. NutScript allows you to add hooks via PLUGIN, rather than hook.Add. See: https://wiki.facepunch.com/gmod/Hook_Library_Usage and Why use PLUGIN?

PLUGIN:CharacterLoaded (id)
PLUGIN:CharacterLoaded

Called when a character is fully loaded.

Parameters:

integer id The character ID that was loaded

PLUGIN:CharacterPreSave (character)
PLUGIN:CharacterPreSave

Called right before a character is saved.

Parameters:

Character character The character being saved

PLUGIN:CanPlayerUseChar (client, char)
PLUGIN:CanPlayerUseChar

Checks whether a player can play as a specific character. Return false and a string to prevent a character from being selected.

Parameters:

Client client The player trying to load a character

Character char The character being loaded

Returns:

bool

string Reason the character can't be loaded

PLUGIN:GetDefaultCharDesc (client, faction)
PLUGIN:GetDefaultCharDesc

Returns the default character description used during creation.

Parameters:

Client client The player creating the character

integer faction The faction index of the character

PLUGIN:GetDefaultCharName (client, faction)
PLUGIN:GetDefaultCharName

Returns the default character name used during creation.

Parameters:

Client client The player creating the character

integer faction The faction index of the character

PLUGIN:CheckFactionLimitReached (faction, character, client)
PLUGIN:CheckFactionLimitReached

Whether or not more players are allowed to load a character of a specific faction.

Parameters:

faction faction Faction metadata

Character character The character trying to join

Client client The player trying to join

Returns:

bool

PLUGIN:PlayerLoadedChar (client, character, lastChar)
PLUGIN:PlayerLoadedChar

Runs after a player loads a character.

Parameters:

Client client The player Entity

Character character The new character

Character lastChar [opt] Previous character

PLUGIN:PrePlayerLoadedChar (client, character, lastChar)
PLUGIN:PrePlayerLoadedChar

Runs before a player loads a character.

Parameters:

Client client The player Entity

Character character The new character

Character lastChar [opt] Previous character

PLUGIN:OnCharVarChanged (char, varName, oldVar, newVar)
PLUGIN:OnCharVarChanged

Triggers whenever a character's var is changed.

Parameters:

Character char The character affected

string varName Name of the variable

vararg oldVar Old value

vararg newVar New value

Inventory management hooks

PLUGIN:CanItemBeTransfered (itemObject, curInv, inventory)
PLUGIN:CanItemBeTransfered

Check whether an item can be transferred between inventories.

Parameters:

Item itemObject The item

Inventory curInv Current inventory

Inventory inventory Target inventory

Returns:

bool Return false to block transfer

PLUGIN:CanPlayerDropItem (client, item)
PLUGIN:CanPlayerDropItem

Check if a player can drop an item.

Parameters:

Client client The player

Item item The item

Returns:

bool Return false to block dropping

PLUGIN:CanPlayerInteractItem (client, action, item)
PLUGIN:CanPlayerInteractItem

Check if a player can interact with an item.

Parameters:

Client client The player

string action The action name

Item item The item

Returns:

bool Return false to block interaction

PLUGIN:CanPlayerTakeItem (client, item)
PLUGIN:CanPlayerTakeItem

Check if a player can take an item.

Parameters:

Client client The player

Item item The item

Returns:

bool Return false to block taking

PLUGIN:CreateDefaultInventory (character)
PLUGIN:CreateDefaultInventory

Creates a default inventory for a character.

Parameters:

Character character The character

Returns:

Inventory The created inventory

PLUGIN:CreateInventoryPanel (inventory, parent)
PLUGIN:CreateInventoryPanel

Creates the inventory UI panel.

Parameters:

Inventory inventory The inventory

Panel parent Optional parent panel

Returns:

panel The created panel

PLUGIN:GetDefaultInventoryType (character)
PLUGIN:GetDefaultInventoryType

Determines the inventory type for a character.

Parameters:

Character character The character

Returns:

string Inventory type ID

PLUGIN:OnInventoryCreated (inventory)
PLUGIN:OnInventoryCreated

Called when an inventory is created.

Parameters:

inventory inventory The new inventory

PLUGIN:OnInventoryDeleted (id)
PLUGIN:OnInventoryDeleted

Called when an inventory is deleted.

Parameters:

integer id The inventory ID

PLUGIN:OnInventoryLoaded (inventory)
PLUGIN:OnInventoryLoaded

Called when an inventory is loaded.

Parameters:

inventory inventory The loaded inventory

Item lifecycle hooks

PLUGIN:ItemShowEntityMenu (entity)
PLUGIN:ItemShowEntityMenu

Shows the item entity menu.

Parameters:

vararg entity

PLUGIN:OnItemCreated (item)
PLUGIN:OnItemCreated

Called when an item is created.

Parameters:

Item item The item

PLUGIN:OnItemRegistered (item)
PLUGIN:OnItemRegistered

Called after an item is registered.

Parameters:

Item item The item definition

Salary/Money Hooks

PLUGIN:CreateSalaryTimer (client)
PLUGIN:CreateSalaryTimer

Creates a salary timer for a player.

Parameters:

Client client The player

PLUGIN:GetSalaryAmount (client, faction, class)
PLUGIN:GetSalaryAmount

Gets the salary amount for a player.

Parameters:

Client client The player

table faction Faction table

table class Class table

Returns:

number Amount

PLUGIN:GetSalaryInterval (client, faction)
PLUGIN:GetSalaryInterval

Gets the salary interval.

Parameters:

Client client The player

table faction Faction table

Returns:

number Interval

PLUGIN:GetSalaryLimit (client, faction, class)
PLUGIN:GetSalaryLimit

Gets the salary cap.

Parameters:

Client client The player

table faction Faction table

table class Class table

Returns:

number Limit

PLUGIN:OnPickupMoney (client, moneyEntity)
PLUGIN:OnPickupMoney

Called when a player picks up money

Parameters:

Client client Player picking up

Entity moneyEntity Money entity being picked up

Plugin system

PLUGIN:DoPluginIncludes (path, PLUGIN)
PLUGIN:DoPluginIncludes

Loads extra plugin files.

Parameters:

string path Directory path

table PLUGIN The plugin table

PLUGIN:InitializedItems ()
PLUGIN:InitializedItems

Called after all items have loaded.

PLUGIN:InitializedPlugins ()
PLUGIN:InitializedPlugins

Called after plugins are initialized.

PLUGIN:InitializedSchema ()
PLUGIN:InitializedSchema

Called after schema is initialized.

PLUGIN:OnMySQLOOConnected ()
PLUGIN:OnMySQLOOConnected

Called when MySQLOO connects.

PLUGIN:PluginLoaded (uniqueID, PLUGIN)
PLUGIN:PluginLoaded

Called after plugin is loaded.

Parameters:

string uniqueID The plugin ID

table PLUGIN The plugin table

PLUGIN:PluginShouldLoad (uniqueID)
PLUGIN:PluginShouldLoad

Decides whether plugin should load.

Parameters:

string uniqueID Plugin ID

Returns:

bool Return false to block load

PLUGIN:RegisterPreparedStatements ()
PLUGIN:RegisterPreparedStatements

Called when prepared statements should be registered.

PLUGIN:OnLoadTables ()
PLUGIN:OnLoadTables

Called when DB tables are loading.

PLUGIN:NutScriptTablesLoaded ()
PLUGIN:NutScriptTablesLoaded

Called when DB tables are loaded.

PLUGIN:OnWipeTables ()
PLUGIN:OnWipeTables

Called when DB tables are being wiped.

PLUGIN:SetupDatabase ()
PLUGIN:SetupDatabase

Sets up DB config.

Client-side UI

PLUGIN:ScreenResolutionChanged (oldW, oldH)
PLUGIN:ScreenResolutionChanged

Called when the screen resolution changes. This is triggered by a timer that checks resolution every second.

Parameters:

integer oldW Previous screen width

integer oldH Previous screen height

PLUGIN:CharacterListLoaded ()
PLUGIN:CharacterListLoaded

Shows character list loaded.

PLUGIN:CreateLoadingScreen ()
PLUGIN:CreateLoadingScreen

Creates loading screen.

PLUGIN:LoadNutFonts (font, genericFont, configFont)
PLUGIN:LoadNutFonts

Loads fonts.

Parameters:

string font Main font

string genericFont Secondary font

string configFont Config font

PLUGIN:NutScriptLoaded ()
PLUGIN:NutScriptLoaded

Framework loaded.

PLUGIN:ShouldDrawEntityInfo (entity)
PLUGIN:ShouldDrawEntityInfo

Checks if info should draw.

Parameters:

Entity entity The entity

Returns:

bool Should draw info

PLUGIN:ShouldCreateLoadingScreen ()
PLUGIN:ShouldCreateLoadingScreen

Checks if loading screen should appear.

PLUGIN:SetupQuickMenu (menu)
PLUGIN:SetupQuickMenu

Sets up quick menu.

Parameters:

Derma menu Quick menu panel

PLUGIN:DrawNutModelView (panel, ent)
PLUGIN:DrawNutModelView

Draws model view in panel.

Parameters:

Derma panel Model panel

Entity ent Entity

Logging

PLUGIN:OnServerLog (client, logType, ...)
PLUGIN:OnServerLog

Server log output.

Parameters:

Client client The client

string logType Log type

vararg ... Extra data

Bot hooks

PLUGIN:SetupBotCharacter (client)
PLUGIN:SetupBotCharacter

Sets up bot character.

Parameters:

Client client The bot

PLUGIN:SetupBotInventory (client, character)
PLUGIN:SetupBotInventory

Sets up bot inventory.

Parameters:

Client client The bot

Character character The bot character

Combat system

PLUGIN:PlayerGetFistDamage (client, damage, context)
PLUGIN:PlayerGetFistDamage

Gets damage for fist SWEP.

Parameters:

Client client The attacker

integer damage Default damage

table context Damage context

Attribute system

PLUGIN:OnCharAttribBoosted (client, character, attribID, boostID, boostAmount)
PLUGIN:OnCharAttribBoosted

Called on attribute boost.

Parameters:

Client client The client

Character character The character

string attribID Attribute ID

string boostID Boost ID

number boostAmount Boost value

Fallover

PLUGIN:OnCharFallover (client, ragdoll, fellover)
PLUGIN:OnCharFallover

Called when fallover state changes.

Parameters:

Client client The client

Entity ragdoll The ragdoll

boolean fellover Is ragdolled

Class hooks

PLUGIN:OnPlayerJoinClass (client, class, oldClass)
PLUGIN:OnPlayerJoinClass

Called when a player changes classes.

Parameters:

Client client The player changing classes

number class New class index

number oldClass Previous class index