Tool Meta
The ToolGun interacts with the world through specialized meta functions.
This guide lists utilities for object manipulation and ghost entity management.
Overview
Tool meta functions track hovered entities, create ghost previews, and wrap common building operations.
They ensure consistent behavior across custom tools in Lilia.
Create
Purpose
Creates a new tool object with default values.
Parameters
- None
Realm
Shared
Returns
- table: The newly created tool object.
Example Usage
-- Create a new tool instance and configure it
local tool = ToolGunMeta:Create()
tool.Mode = "lia_dooredit"
tool.SWEP = weapon -- weapon variable from your SWEP
tool.Owner = client -- client that spawned the tool
CreateConVars
Purpose
Creates client and server ConVars for this tool.
Parameters
- None
Realm
Shared
Returns
None
: This function does not return a value.
Example Usage
GetServerInfo
Purpose
Returns the server ConVar for the given property.
Parameters
property
(string): Property name.
Realm
Shared
Returns
- ConVar: The server ConVar object.
Example Usage
-- Check if the server allows using this tool
local allow = tool:GetServerInfo("allow_use"):GetBool()
BuildConVarList
Purpose
Returns a table of client ConVars prefixed by the tool mode.
Parameters
- None
Realm
Shared
Returns
- table: Table of convars.
Example Usage
GetClientInfo
Purpose
Retrieves a client ConVar value as a string.
Parameters
property
(string): ConVar name without mode prefix.
Realm
Shared
Returns
- string: The value stored in the ConVar.
Example Usage
GetClientNumber
Purpose
Retrieves a numeric client ConVar value.
Parameters
-
property
(string): ConVar name without mode prefix. -
default
(number): Value returned if the ConVar doesn't exist.
Realm
Shared
Returns
- number: The numeric value of the ConVar.
Example Usage
Allowed
Purpose
Determines whether this tool is allowed to be used.
Parameters
- None
Realm
Shared
Returns
- boolean: True if the tool is allowed.
Example Usage
-- Gate tool usage behind an admin check
function TOOL:Allowed()
return self.AllowedCVar:GetBool() and self:GetOwner():IsAdmin()
end
Init
Purpose
Placeholder for tool initialization.
Parameters
- None
Realm
Shared
Returns
None
: This function does not return a value.
Example Usage
GetMode
Purpose
Gets the current tool mode string.
Parameters
- None
Realm
Shared
Returns
- string: Tool mode name.
Example Usage
GetSWEP
Purpose
Returns the SWEP associated with this tool.
Parameters
- None
Realm
Shared
Returns
- SWEP: The tool's weapon entity.
Example Usage
GetOwner
Purpose
Returns the player who owns the associated weapon.
Parameters
- None
Realm
Shared
Returns
- Player: Owner of the tool.
Example Usage
GetWeapon
Purpose
Retrieves the weapon entity this tool is attached to.
Parameters
- None
Realm
Shared
Returns
- Weapon: The weapon object.
Example Usage
LeftClick
Purpose
Handles the left-click action. Override for custom behavior.
Parameters
- None
Realm
Shared
Returns
- boolean: False by default.
Example Usage
-- Example override performing a build action
function TOOL:LeftClick(trace)
self:AddPoint(trace.HitPos)
return true
end
RightClick
Purpose
Handles the right-click action. Override for custom behavior.
Parameters
- None
Realm
Shared
Returns
- boolean: False by default.
Example Usage
-- Example override for an alternate action
function TOOL:RightClick(trace)
openContextMenu(trace.Entity)
return true
end
Reload
Purpose
Clears stored objects when the tool reloads.
Parameters
- None
Realm
Shared
Returns
None
: This function does not return a value.
Example Usage
Deploy
Purpose
Called when the tool is equipped. Releases ghost entity.
Parameters
- None
Realm
Shared
Returns
None
: This function does not return a value.
Example Usage
Holster
Purpose
Called when the tool is holstered. Releases ghost entity.
Parameters
- None
Realm
Shared
Returns
None
: This function does not return a value.
Example Usage
Think
Purpose
Called every tick; releases ghost entities by default.
Parameters
- None
Realm
Shared
Returns
None
: This function does not return a value.
Example Usage
CheckObjects
Purpose
Validates stored objects and clears them if invalid.
Parameters
- None
Realm
Shared
Returns
None
: This function does not return a value.
Example Usage
ClearObjects
Purpose
Removes all stored objects from the tool.
Parameters
- None
Realm
Shared
Returns
None
: This function does not return a value.
Example Usage
ReleaseGhostEntity
Purpose
Removes the ghost entity used for previewing placements.
Parameters
- None
Realm
Shared
Returns
None
: This function does not return a value.
Example Usage