Creating Custom Entities/Entity
Creating a Custom Entity/Entities in Garry's Mod
1. Introduction
Custom entities in Garry's Mod offer a way to enhance gameplay and developer flexibility by allowing creators to introduce unique elements, behaviors, and interactions into their games. These entities can range from simple, static models in the game world to complex, interactive objects that can interact with players and other entities in various ways. The ability to create custom entities opens up endless possibilities for game customization, making it a vital skill for any Garry's Mod developer aiming to craft engaging and dynamic game environments.
2. Fundamentals
Basic Definitions
- Entities: In Garry's Mod, entities are objects in the game world. (For the most part)
Key Components
- Initialization: The process of setting up an entity's default state.
- Logic Handling: The code that determines an entity's behavior and responses to game events.
- Shared Configuration: Defines properties across server and client.
3. Setting Up the Environment
Workspace Preparation
- Familiarize yourself with the game's file system, especially the lua/entities directory where custom entities are stored.
Gamemode:
Addon:
Tools and Resources
- VSCode or any preferred Lua editor for writing and editing code.
- Video: "Ep. 13 Creating An Entity #1" by Codeblue
- Video: "Ep. 14 Creating An Entity #2" by Codeblue
- Video: "Ep. 25 Advanced Entity Example" by Codeblue
4. Creating an entity
- Create the Entity Files: Start by creating a folder with the addon or gamemode folder,
lua/entities
for your entity. Inside, create another folder, of the name of your entity e.gtestent
. It should look like thislua/entities/testent
, then create three lua files:shared.lua
,cl_init.lua
, andinit.lua
. - Define the Entity: In shared.lua, define basic properties like entity type, base, and print name.
- Server-Side Setup: Use init.lua to define server-side logic, such as model, physics, and initialization behavior.
- Client-Side Setup: cl_init.lua handles client-side aspects, primarily drawing the entity model.
shared.lua example:
init.lua example:
cl_init.lua example:
The structure should look like this