S&box Wiki

Entity Tags

Entity Tags

Entities can be tagged with string tags. These tags are networked, so are also available for query on the client.

Setting Tags

// set one tag on the entity player_entity.Tags.Add( "player" ); // set multiple tags on the entity enemy_entity.Tags.Add( "enemy", "threat" ); // updating tags programatically (adds if true, removes if false) door_entity.Tags.Set( "locked", IsLocked() ); // removing tags enemy_entity.Tags.Remove( "threat" );

Querying Tags

if ( enemy.Tags.Has( "threat" ) ) { // run away }

Using in Traces

// Only hit entities with the world tag tr = Trace.Ray( startpos, endpos ) .WithTag( "world" ) .Run(); // Hit enemies that are a threat tr = Trace.Ray( startpos, endpos ) .WithAllTags( "enemy", "threat" ) .Run(); // Hit enemies or players tr = Trace.Ray( startpos, endpos ) .WithAnyTags( "enemy", "player" ) .Run(); // Hit anything but players tr = Trace.Ray( startpos, endpos ) .WithoutTags( "player" ) .Run(); // Hit anything but players and world tr = Trace.Ray( startpos, endpos ) .WithoutTags( "player", "world" ) .Run();

Detecting Tag Changes

protected override void OnTagAdded( string tag ) { } protected override void OnTagRemoved( string tag ) { }

Special Pages


Wikis

?

Render Time: 43ms

DB GetPage 31
Generate Html 2
SaveChanges (1) 6
Render Body 0
Render Sidebar 1