Summer 2026 Music Kit Competition is now here! - Create a summer themed electronic music kit and submit it by - Enter Now!

Scripting
Value Classes

The API uses plain JavaScript objects for vectors, angles, colors, options, and results. These are value shapes rather than constructible native classes.

Vector

const position = { x: 0, y: 0, z: 64 };
Property Type Description
x number X component.
y number Y component.
z number Z component.

All components must be finite numbers.

QAngle

const angles = { pitch: 0, yaw: 90, roll: 0 };
Property Type Description
pitch number Pitch angle.
yaw number Yaw angle.
roll number Roll angle.

All components must be finite numbers.

Color

const color = { r: 255, g: 128, b: 0, a: 255 };
Property Type Required Description
r number yes Red component from 0 through 255.
g number yes Green component from 0 through 255.
b number yes Blue component from 0 through 255.
a number no Alpha component from 0 through 255; defaults to 255.

Entity

Entity is an opaque native object representing a safe Source entity handle. Entity values are returned by the API and cannot be created with new Entity().

The handle is resolved again for every operation. If the Source entity is deleted, entity.IsValid() returns false; other Entity functions throw ReferenceError.

Wrappers have stable identity while their handles remain live. This permits both first === second comparisons and script-owned properties such as piece.square = "e4".

Store entity handles only when necessary and validate them before later use:

const target = Instance.FindEntityByName("temporary_target");

Instance.SetThink(() => {
	if (target?.IsValid())
		Instance.Msg(target.GetClassName());
});

The methods available on entities are documented under Entity Methods and Player Methods.

PointTemplate

PointTemplate is an importable runtime type marker for Source point_template entities. Scripts do not construct it. Use entity instanceof PointTemplate to narrow an Entity before calling ForceSpawn(); see point templates.

TraceResult

Instance.TraceLine and Instance.TraceBox return:

{
	didHit: boolean,
	fraction: number,
	end: Vector,
	normal: Vector,
	hitEntity: Entity | undefined,
	startedInSolid: boolean,
	allSolid: boolean,
}
Property Description
didHit Whether the trace hit something.
fraction Travel fraction from 0 to 1.
end Final trace position.
normal Hit-plane normal.
hitEntity Hit Entity, or undefined.
startedInSolid Whether the trace began inside solid contents.
allSolid Whether the complete trace remained in solid contents.