Raised This Month: $7 Target: $400
 1% 

[TF2] TF2Attributes (v1.7.2, 2022/09/18)


Post New Thread Reply   
 
Thread Tools Display Modes
Author
FlaminSarge
Veteran Member
Join Date: Jul 2010
Plugin ID:
3560
Plugin Version:
1.7.2
Plugin Category:
Technical/Development
Plugin Game:
Team Fortress 2
Plugin Dependencies:
    Servers with this Plugin:
    1517 
    Plugin Description:
    A set of natives for plugin developers to use to add/remove attributes from weapons, wearables, and players
    Old 03-08-2013 , 04:08   [TF2] TF2Attributes (v1.7.2, 2022/09/18)
    Reply With Quote #1

    ⚠️For latest fixes/gamedata/etc., see GitHub.⚠️

    Update - 2022/09/18: Pulled in all changes from @nosoop's fork.

    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:
    Code:
    TF2Attrib_SetByName
    TF2Attrib_GetByName
    TF2Attrib_RemoveByName
    TF2Attrib_RemoveAll
    TF2Attrib_ListDefIndices
    TF2Attrib_GetStaticAttribs
    TF2Attrib_GetSOCAttribs
    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.
    Code:
    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.10+):
    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.

    Cvars:
    tf2attributes_version -
    do not touch.

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

    Changelog (outdated, see GitHub below):
    Code:
    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 - 60760 - up to 2022/09/18


    Download: GitHub
    Source: GitHub
    __________________
    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; 09-18-2022 at 07:42.
    FlaminSarge is offline
    FlaminSarge
    Veteran Member
    Join Date: Jul 2010
    Old 03-08-2013 , 04:19   Re: [TF2] TF2Attributes (v1.0.0, 03/08/2013)
    Reply With Quote #2

    Reserved for things.
    __________________
    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.
    FlaminSarge is offline
    FlaminSarge
    Veteran Member
    Join Date: Jul 2010
    Old 03-08-2013 , 07:54   Re: [TF2] TF2Attributes (v1.0.0, 03/08/2013)
    Reply With Quote #3

    Also, heads up, I'm already writing a replacement for the tf2items_manager/tf2items config using this. If anybody else decides to undertake that task as well, let me know.
    __________________
    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.
    FlaminSarge is offline
    NameUser
    Senior Member
    Join Date: Apr 2012
    Location: Bay Area, California
    Old 03-08-2013 , 10:35   Re: [TF2] TF2Attributes (v1.0.0, 03/08/2013)
    Reply With Quote #4

    Whoo-hoo! I've been waiting for this for a while. Time to develop!
    __________________

    Last edited by NameUser; 03-08-2013 at 10:37.
    NameUser is offline
    Send a message via Skype™ to NameUser
    Leonardo
    Veteran Member
    Join Date: Feb 2010
    Location: 90's
    Old 03-08-2013 , 14:18   Re: [TF2] TF2Attributes (v1.0.0, 03/08/2013)
    Reply With Quote #5

    Sweet.
    But too late~
    __________________
    Leonardo is offline
    Powerlord
    AlliedModders Donor
    Join Date: Jun 2008
    Location: Seduce Me!
    Old 03-08-2013 , 14:41   Re: [TF2] TF2Attributes (v1.0.0, 03/08/2013)
    Reply With Quote #6

    Just to be clear, which entities will this work on?

    I'm thinking players, weapons, hats, miscs, and most action items (except Dueling Minigames, Secret Saxtons, and Piles o' Gifts).
    __________________
    Not currently working on SourceMod plugin development.
    Powerlord is offline
    FlaminSarge
    Veteran Member
    Join Date: Jul 2010
    Old 03-08-2013 , 15:36   Re: [TF2] TF2Attributes (v1.0.0, 03/08/2013)
    Reply With Quote #7

    Quote:
    Originally Posted by FlaminSarge View Post
    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).
    sm_dump_netprops netprops.txt, CTRL+F "m_AttributeList" (though I suppose the netclasses aren't very useful for finding the actual entity classnames, sm_dump_datamaps has you covered for classname - netclass conversion needs).

    This modifies the actual entities, not the item server info, so items that pull from the item server (which I presume are gifts, duels, etc) wouldn't be affected, presumably.

    Brb writing Randomizer MvM and UpgradeAnytime.

    I'll also get to work on changing all the code in VSH to use this instead of TF2Items.
    __________________
    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; 03-09-2013 at 03:17.
    FlaminSarge is offline
    FlaminSarge
    Veteran Member
    Join Date: Jul 2010
    Old 03-10-2013 , 07:36   Re: [TF2] TF2Attributes (v1.0.0, 03/08/2013)
    Reply With Quote #8

    I updated the .inc file on March 10th, 2013 to not cause tag mismatches whenever you tried to use the return of SetByName properly. Woops. Also updated the tagging on Remove/RemoveAll.
    __________________
    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.
    FlaminSarge is offline
    Bitl
    Senior Member
    Join Date: Jul 2012
    Old 03-10-2013 , 11:58   Re: [TF2] TF2Attributes (v1.0.0, 03/08/2013)
    Reply With Quote #9

    Quote:
    Originally Posted by FlaminSarge View Post
    I updated the .inc file on March 10th, 2013 to not cause tag mismatches whenever you tried to use the return of SetByName properly. Woops. Also updated the tagging on Remove/RemoveAll.
    The funny thing is, the previous version did not cause tag mismatches, but the new version does.

    EDIT: Actually, after some testing, it does it rarely.
    __________________
    My Plugins
    Modified Plugins:
    Building Spawner
    Monster
    It's Raining Men!
    Tutorials:
    Custom Gamemode

    I DON'T DO PLUGIN REQUESTS.

    Last edited by Bitl; 03-10-2013 at 19:50.
    Bitl is offline
    FlaminSarge
    Veteran Member
    Join Date: Jul 2010
    Old 03-11-2013 , 00:27   Re: [TF2] TF2Attributes (v1.0.0, 03/08/2013)
    Reply With Quote #10

    The thing was, "attrib" returned by Get and Set are Address: tagged, and I bet you're forgetting that tag. Initially, I had forgotten the tag on Set, and the bool: tags on Remove/RemoveAll. Make sure you're tagging the variables you store your returns in properly.
    __________________
    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.
    FlaminSarge is offline
    Reply


    Thread Tools
    Display Modes

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off

    Forum Jump


    All times are GMT -4. The time now is 05:48.


    Powered by vBulletin®
    Copyright ©2000 - 2024, vBulletin Solutions, Inc.
    Theme made by Freecode