Modifying Existing Entities (Basic)
Garry's Mod allows for deep customization, and a fundamental aspect of this is the ability to modify existing entities—the objects and characters that populate the game world. This can range from simple property changes using the Toolgun to more complex alterations through Lua scripting, enabling you to tailor the game's elements to your needs.
Entities are the core components of any Garry's Mod experience. They include everything from static props and dynamic physics objects to NPCs, weapons, and even triggers. Modifying these entities can change their behavior, appearance, or how they interact with the game world.
Using the Toolgun for Basic Modifications:
The Toolgun is your primary interactive tool in Sandbox mode. It comes with various "tools" that allow for basic entity manipulation:
- Physgun: Used to grab, move, rotate, and freeze physics-enabled entities.
- Weld Tool: Connects two entities together, creating rigid structures.
- Color Tool: Changes the color and material of props.
- Material Tool: Applies different textures to entities.
- NPC Tool: Spawns and manipulates NPCs.
- Constraint Tools (Hinge, Pulley, etc.): Create more complex physical connections between entities.
For example, you can use the Color Tool to change a red barrel to blue, or the Material Tool to make a wooden crate look like metal. The Physgun allows you to assemble complex contraptions by moving and positioning entities precisely.
Modifying Entities with Lua Scripting (Beginner):
For more advanced modifications, Lua scripting is necessary. Even basic scripting can achieve sificant changes. Here are some fundamental concepts:
- Accessing Entities: You can get references to entities in the world. For example, `ents.FindByClass('prop_physics')` can find all physics props.
- Modifying Properties: Once you have an entity, you can change its properties. For instance, to change a prop's gravity:
-- Find a specific prop (e.g., by its name or a unique identifier)
local myProp = ents.GetByName('my_unique_prop_name')
if myProp then
myProp:SetGravity(0.5) -- Set gravity to half of normal
end
- Spawning Entities with Custom Properties: You can spawn new entities with specific initial settings.
- Modifying NPC Behavior: You can change NPC health, speed, or even their AI routines.
Example: Making a Prop Float
A simple Lua script could find a specific prop and continuously apply an upward force to make it float:
hook.Add('Think', 'FloatProp', function()
local prop = ents.GetByName('floating_crate') -- Assume you named a prop 'floating_crate'
if IsValid(prop) then
prop:SetVelocity(Vector(0, 0, 50)) -- Apply upward velocity
end
end)
This script, when run, would continuously push the entity named 'floating_crate' upwards. Even basic modifications like these can drastically alter how entities behave and interact within your Garry's Mod world.