Skip to content

Creating Attributes

nosoop edited this page Apr 2, 2023 · 1 revision

Econ Dynamic is a managed solution for plugins to create new game attributes. The extension handles (re)registration of attributes on an as-needed basis so plugins don't have to worry about those things, and server operators don't have to worry as much on editing files and managing schema definitions.

Quick start

Create a TF2EconDynAttribute handle, set properties, then call Register on the handle. Register does not reset the contents of the handle, so you can quickly create multiple attributes.

These are the available methods:

  • TF2EconDynAttribute.SetClass sets the attribute class. This can be any zero-terminated (normal) string of your choosing; just make sure that it's unique if you don't intend on using one of the game's own classes.
  • TF2EconDynAttribute.SetName sets the attribute name. This identifier is used when applying attributes to entities. Multiple attributes can use the same attribute class, but the name must be unique.
    • If not present, this will be set to the value of the attribute class.
  • TF2EconDynAttribute.SetDescriptionFormat sets the attribute "description format". This is a string constant that defines two things: how the attribute is combined, and how the value is displayed to players.
    • The following are the most common ones:
      • value_is_percentage is multiplicative. A value of 1.5 is rendered as "50%", e.g. "+50% damage bonus".
      • value_is_additive is additive. A value of 3.0 is rendered as "3", e.g. "+3 max pipebombs out".
      • value_is_inverted_percentage is multiplicative. A value of 0.75 is rendered as "25", e.g. "25% faster reload time".
      • value_is_additive_percentage is additive. A value of 0.75 is rendered as "75", e.g. "Melee hits refill 75% of your charge meter"
      • value_is_or is a bitwise-OR operation. A value of 3.0 is rendered as "3", but there's no practical reason to display the raw value as what the bits represent can be defined however the attribute class wants.
    • Note that how the value is displayed is irrelevant for servers, but you may as well set them accurately in case a plugin decides to take it into consideration for formatting purposes.
  • TF2EconDynAttribute.SetDefIndex sets the attribute definition index. If set, this must be unique.
    • This is mostly present for backwards compatibility. You shouldn't need this for the most part, as the extension will automatically allocate an unused one for you, and you should be using TF2Attrib_SetByName and TF2Attrib_SetFromStringValue when assigning attributes to entities.
    • If an attribute exists at the given index, injection of the attribute will fail.
    • TF2EconDynAttribute.ClearDefIndex removes an assigned attribute definition index.
  • TF2EconDynAttribute.SetCustom sets arbitrary key / value pairs.
    • Refer to the attributes section in items_game.txt for recognized combinations.
    • This is present for backwards and forwards compatibility.

To read out the values of attributes, use TF2Attrib_HookValueFloat and TF2Attrib_HookValueInt from TF2Attributes, as you would any other attribute in most situations.

Clone this wiki locally