Garry's Mod
Garry's Mod

Creating Custom Entities (Basic)

Begin creating custom entities in Garry's Mod using Lua scripting. Define unique object properties and behaviors for new game modes and gameplay mechanics.

Creating Custom Entities (Basic)

Garry's Mod's Lua scripting allows you to go beyond existing entities and create your own unique objects with custom behaviors. This opens up a world of possibilities for game modes, interactive props, and unique gameplay mechanics. Even basic entity creation involves understanding how to define an entity's properties and its behavior within the game world.

At its core, creating a custom entity in GMod involves writing a Lua script that defines the entity's class, its appearance (model), its physical properties, and any functions it should perform. You'll typically start by defining a new entity class that inherits from a base GMod entity. This script will then be placed in the `garrysmod/lua/entities/` directory.

A basic custom entity script will define its name, its model, and potentially some initial properties. For example, you might create a simple 'health pack' entity that, when touched by a player, heals them and then removes itself. This involves defining a `Touch` function that checks if the toucher is a player and, if so, applies the healing effect and calls `self:Remove()`.

Essential Components of a Basic Custom Entity Script
  • Entity Definition: `ENT.Type = "anim"` or `ENT.Type = "brush"`, `ENT.Base = "base_gmodentity"`
  • Model: `ENT.PrintName = "My Custom Entity"`, `ENT.Category = "My Entities"`, `ENT.Spawnable = true`, `ENT.AdminSpawnable = true`
  • Appearance: `function ENT:Initialize() self:SetModel("models/path/to/your/model.mdl") end`
  • Behavior (e.g., Touch Function): `function ENT:Touch(entity) if entity:IsPlayer() then entity:SetHealth(entity:Health() + 50) self:Remove() end end`

Remember to place your Lua file (e.g., `my_custom_entity.lua`) in the correct directory (`garrysmod/lua/entities/my_custom_entity/init.lua`). When you start Garry's Mod, your new entity should appear in the spawn menu under the category you defined.