S&box Wiki

Linking Entities to Hammer

Linking Entities to Hammer

Entities defined in your addon will automatically generate an FGD and put it into your addons config folder.

Creating an entity

Create a partial class and make it inherit from Entity - ModelEntity, AnimEntity, etc.. derive from this too.

To link this entity to Hammer you need to add a [Library] Attribute to your class, this will define the entity name and description. A basic example:

[Library("info_player_spawn", Description = "It indicates the position and facing direction at which the player will spawn.")] public partial class SpawnPoint : Entity { }

Optional class attributes

All of these are optional attributes that can be added to your class to change the behaviour in Hammer.

[Hammer.Solid]

[Hammer.Solid] tells Hammer this entity is brush based.

[Hammer.Solid]

[Hammer.EditorModel]

[Hammer.EditorModel] tells Hammer what model to use for the entity and is added to the class.

[Hammer.EditorModel( "models/editor/playerstart.vmdl" )]

[Hammer.EditorSprite]

[Hammer.EditorSprite] tells Hammer what model to use for the entity and is added to the class.

[Hammer.EditorSprite( "editor/info_target.vmat" )]

[Hammer.EntityTool]

[Hammer.EntityTool] appends this Entity to Hammer's Entity tool list like so:

image.png
[Hammer.EntityTool( "Player Spawnpoint", "Player", "Defines a point where the player can (re)spawn" )]

[Hammer.Model]

[Hammer.Model] makes it so the model, skin and bodygroups can be set and changed in Hammer.

[Hammer.Model]

[Hammer.Skip]

[Hammer.Skip] can be used if you do not want your entity exposed in Hammer.

[Hammer.Skip]

Exposing properties to Hammer

Any property in your class can be exposed to Hammer using the [Property] attribute.

An example of a property being defined:

public partial class MyEntity : Entity { [Property( Name = "variable_name", Title = "Variable Title", Help = "Help text for variable" )] [Sandbox.Internal.DefaultValue( "Default Value" )] public string MyVariable { get; set; } = "Default Value"; }
Sandbox.Internal.DefaultValue is in the internal namespace so behavior could change.

Your entity properties will then show up in Hammer:

image.png

Supported property types:

  • int
  • float
  • bool
  • Vector3
  • string
  • Rotation
  • Angles
  • SoundEvent
  • Material

Inputs

Any method in your entity class can be exposed to Hammer as an input using the [Input] attribute - parameters you define are automatically handled.

An example of an input being defined:

public partial class MyEntity : Entity { [Input] public void DoSomethingElse(string str) { } [Input( Name = "DoSomething", Help = "Help text for input" )] public void SomeInput() { } }

Outputs

Any Output in your entity class is automatically exposed to Hammer as an output.

An example of an output being defined:

public partial class MyEntity : Entity { [Sandbox.Internal.Description( "Fires when something happens" )] public Output OnSomethingHappened; }

Firing Outputs

You can fire your output using Entity.FireOutput(name, sender) like this:

public static void MakeItDoSomething(SomeEntity ent) { ent.FireOutput("OnSomethingHappened", null); }
Are additional FireOutput codegenned from the Output properties?

Special Pages


Wikis

?

Render Time: 62ms

DB GetPage 44
Generate Html 3
SaveChanges (1) 11
Render Body 0
Render Sidebar 0