: All five files updated (four now that tf2attributes.sp compiles on the forum). Check the changelog. Two new natives, fixed ClearCache.
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:
TF2Attrib_SetByName(iEntity, String:strAttrib, Float:flValue)
The other natives exist to modify the attributes whose addresses are returned by the Get functions.
There's also a stock TF2Attrib_IsIntegerValue(iDefIndex), which takes in an attribute definition index (as returned by TF2Attrib_GetDefIndex(Address:pAttrib)), and returns true if the attribute is stored as an integer rather than as a float (items_game's definitions of this aren't accurate, so I hardcoded the stock for the attributes that I found were stored as ints, such as "kill eater").
Any attribute index that returns true for TF2Attrib_IsIntegerValue should be used with a Float: tag 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.
new value = 20;
TF2Attrib_SetByName(entity, "kill eater", Float:value); //sets strange kill count to 20, DO NOT USE 20.0
value = 30;
TF2Attrib_SetValue(pAttrib, Float:value); //sets strange kill count to 30
new result = _: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.
(YOU WILL NEED SM 1.5+
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 tf2attributes.inc 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.
do not touch.
This registers a plugin library (via RegPluginLibrary) named "tf2attributes".
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.
*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
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.
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