View Single Post
Author Message
Veteran Member
Join Date: Jul 2010
Old 03-08-2013 , 05:08   [TF2] TF2Attributes (v1.2.1, 07/02/2015)
Reply With Quote #1

Latest gamedata will usually be here, use the 'Raw' button to download/save it, or use this link.

GitHub releases:

Update (07/02/2015): Updated .inc and tf2attributes.sp. See GitHub for more details.

The description line up there should be pretty self-explanatory.

This basically offers a bunch of natives for setting, getting, and modifying attributes on any entity that has m_AttributeList (GetEntSendPropOffs(entity, "m_AttributeList") > 0).

Available natives are all listed in the .inc file, so definitely go read that! It's redundant to copy all of them here, but just know that you're probably looking for:
There are other natives that exist to modify the attributes whose addresses are returned by the Get functions.

TF2Attrib_IsIntegerValue(iDefIndex) takes in an attribute definition index (as returned by TF2Attrib_GetDefIndex(Address:pAttrib)), and returns true if the attribute interpreted as an integer rather than as a float (items_game's definitions of this aren't accurate, so I hardcoded the native for the attributes that I found were stored as ints, such as "kill eater"). Let me know if the internal list needs updating.

Any attribute index that returns true for TF2Attrib_IsIntegerValue should be used with a Float: tag or view_as<float>() rather than float() for TF2Attrib_SetByName, TF2Attrib_SetValue, and TF2Attrib_SetInitialValue, as in the following code block, if you want the number to match up to what appears/happens in game.
int value = 20;
TF2Attrib_SetByName(entity, "kill eater", view_as<float>(value)); //sets strange kill count to 20, DO NOT USE 20.0
value = 30;
TF2Attrib_SetValue(pAttrib, view_as<float>(value)); //sets strange kill count to 30
int result = view_as<int>(TF2Attrib_GetValue(pAttrib));
PrintToChatAll("%d", result); //prints "30" to chat
One last note, attributes get wiped if the weapon/wearable entity gets removed, but attributes added to players will not get reset, and you will have to remove them on your own. However, set bonuses that you remove will get reapplied when the player regenerates.

Installation (SM1.7+):
1) Place tf2attributes.smx ("Get Plugin" for tf2attributes.sp) in the server's sourcemod plugins folder (normally "addons/sourcemod/plugins/").
2) Place tf2.attributes.txt in the server's sourcemod gamedata folder (normally "addons/sourcemod/gamedata/").
3) Write or install a plugin that uses these natives. If writing the plugin, you will need to #include <tf2attributes>, which means you will need to place in the "include" folder of wherever you develop/compile SourceMod plugins.

tf2attributes_example.sp is an example plugin that offers several root-level admin commands to test out the various natives. You can ignore it if you want to.

tf2attributes_version -
do not touch.

This registers a plugin library (via RegPluginLibrary) named "tf2attributes".

GitHub releases:
I'm going to start favoring GitHub releases over attachments here, but I'll keep them here for now too since tf2attributes.sp compiles on the forums.

07/02/2015 - v1.2.1
* GunMettle gamedata
* Changed error behavior of the Get*Attribs natives (errors on call if gamedata failed to load, but does not SetFailState on plugin)

06/23/2015 - v1.2.0
* Added two new natives: TF2Attrib_GetStaticAttribs and TF2Attrib_GetSOCAttribs. See the .inc file for more info.
* Updated gamedata; TF2Attrib_ClearCache should work now
* Changed TF2Attrib_IsIntegerValue to a native
* Added TF2Attrib_IsReady native, which basically just says whether  all the gamedata loaded properly. I don't know what anybody would use it  for, but I remember being asked for it at some point.       

08/27/2013 - v1.1.1
*TF2Attrib_ClearCache now functional again. Use it if you add an attribute but don't see the effects immediately on the player (or whenever you want to see the effects). If it ever breaks, it'll just go back to failing silently.
*Added Set/RemoveByDefIndex.
*Fixed handling of "counts as assister is some kind of pet this update is going to be awesome".

07/20/2013 - v1.1.0
*TF2Attrib_ClearCache will silently fail (it will do absolutely nothing) while I figure out whether it still works and whether it works as intended.
*Added TF2Attrib_ListDefIndices, which will list the attributes on an entity.
*Removed TF2Attrib_Set/GetIsSetBonus and TF2Attrib_Set/GetInitialValue, since those aren't on attributes anymore.
*Fixed everything else
*Please note that because of the way attributes are now applied to weapons, you probably cannot remove the attributes that come with a weapon (same reason as TF2Items). You can only add and remove extra attributes (those applied by TF2Items and this plugin).

 04/24/2013 - v1.0.1
*Added TF2Attrib_ClearCache native, must be called after calls to TF2Attrib_Set*(Address:pAttrib, *) in order for the values to update properly. Does not need to be called after calls to SetByName/Remove/RemoveAll. May need to be called on m_hOwnerEntity of weapons/wearables to properly update things like max health. Read the .inc for info.
*Added TF2Attrib_GetByDefIndex(iEntity, iDefIndex), gets the attribute address by the attribute's definition index (the arbitrary numbers we know and love). For instance, iDefIndex 150 is "turn to gold", so TF2Attrib_GetByDefIndex(iEntity, 150) would return the same thing as TF2Attrib_GetByName(iEntity, "turn to gold").
*All five files were updated. Added a new command to the example plugin.

03/08/2013 - v1.0.0
*Initial release
Planned Features:
TF2Attrib_GetByDefIndex(iEntity, iDefIndex), to get an attribute off an item by its defindex rather than by its name. It's nearly done, will be in the next update, I just wanted to push this first. Done.

Known Weirdness:
I would not recommend using TF2Attrib_SetDefIndex() at all. It doesn't behave as you'd expect it to, and while it does set the definition index of a given attribute, the game still treats it as the original attribute, though when it goes to look up the attribute by name it uses the 'new name' (as if it were actually the new attribute index). This messes up calls to GetByName and SetByName, so just... don't do it.
HOWEVER... if you call TF2Attrib_ClearCache() after SetDefIndex, the game will properly update that attribute to be the new attribute... I think...

... Did I forget anything?
asherkin gets all my cookies

Previous plugin views - 12800 (thru 07/02/2015)

Latest gamedata is in the GitHub link at the top of this post, usually.
Attached Files
File Type: sp Get Plugin or Get Source (tf2attributes.sp - 28125 views - 31.7 KB)
File Type: inc (11.5 KB, 16839 views)
File Type: sp Get Plugin or Get Source (tf2attributes_example.sp - 3448 views - 18.1 KB)
Bread EOTL GunMettle Invasion Jungle Inferno will break everything. Don't even ask.

All plugins: Randomizer/GiveWeapon, ModelManager, etc.
Post in plugin threads with questions.
Steam is for playing games.
You will be fed to javalia otherwise.
Psyduck likes replays.

Last edited by FlaminSarge; 07-08-2017 at 08:56.
FlaminSarge is offline