Repository navigation
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.
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.SetClasssets 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.SetNamesets 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.SetDescriptionFormatsets 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_percentageis multiplicative. A value of 1.5 is rendered as "50%", e.g. "+50% damage bonus". -
value_is_additiveis additive. A value of 3.0 is rendered as "3", e.g. "+3 max pipebombs out". -
value_is_inverted_percentageis multiplicative. A value of 0.75 is rendered as "25", e.g. "25% faster reload time". -
value_is_additive_percentageis additive. A value of 0.75 is rendered as "75", e.g. "Melee hits refill 75% of your charge meter" -
value_is_oris 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.
- The following are the most common ones:
-
TF2EconDynAttribute.SetDefIndexsets 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_SetByNameandTF2Attrib_SetFromStringValuewhen assigning attributes to entities. - If an attribute exists at the given index, injection of the attribute will fail.
-
TF2EconDynAttribute.ClearDefIndexremoves an assigned attribute definition index.
- 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
-
TF2EconDynAttribute.SetCustomsets arbitrary key / value pairs.- Refer to the
attributessection initems_game.txtfor recognized combinations. - This is present for backwards and forwards compatibility.
- Refer to the
To read out the values of attributes, use TF2Attrib_HookValueFloat and TF2Attrib_HookValueInt from TF2Attributes, as you would any other attribute in most situations.