Cheat Sheet
A lot of things are common between game engines. Here's how to do a bunch of common stuff.
Console Printing
Log.Info( "It worked!" );
Log.Warning( $"{playername} is an idiot!" );
Log.Error( "Error!" );
Debug Drawing
// draw text at position for 10 seconds
DebugOverlay.Text( "Some Text!", position, Color.Yellow, 10.0f );
// draw a line
DebugOverlay.Line( startPos, endPos );
// draw text on screen
DebugOverlay.ScreenText( "Hello, debug text!\nSupports multiple lines" );
Spawning an Entity
ModelEntity model = new ModelEntity( "models/citizen/citizen.vmdl" );
model.Position = new Vector3( 0, 0, 100 );
Get Entity's Eye Position and Direction
Vector3 eyePos = Entity.AimRay.Position;
Vector3 eyeDir = Entity.AimRay.Forward;
Do a ray trace
// trace 2000 units in eye direction, ignore all entities
TraceResult tr = Trace.Ray( AimRay, 2000 )
.WorldOnly()
.Run();
// If we hit, draw a 2 inch sphere for 10 seconds
if ( tr.Hit )
{
DebugOverlay.Sphere( tr.EndPosition, 2.0f, Color.Red, duration: 10.0f );
}
Create a Server Console Command
[ConCmd.Server( "my_command" )]
public static void MyConsoleCommand()
{
// the client that is calling the console command
var callingClient = ConsoleSystem.Caller;
}
Create a Client Console Command
[ConCmd.Client( "my_command" )]
public static void MyConsoleCommand()
{
}
Console Command Arguments
// my_command Poop 7 false
[ConCmd.Client( "my_command" )]
public static void MyConsoleCommand( string one, int two, bool three )
{
}
Calling a Console Command
MyConsoleCommand( "poop", 7, false );