Monthly Target: $400 Donations: $293
 73% 

[TF2] TF2Attributes (v1.1.1, 08/27/2013)


Post New Thread Reply   
 
Thread Tools Display Modes
Author
FlaminSarge
Veteran Member
Join Date: Jul 2010
Plugin ID:
3560
Plugin Version:
1.1.1
Plugin Category:
Technical/Development
Plugin Game:
Team Fortress 2
Plugin Dependencies:
    Approver:
    Plugin Description:
    Servers with this Plugin:
    1367 
    Old 03-08-2013 , 04:08   [TF2] TF2Attributes (v1.1.1, 08/27/2013)
    Reply With Quote #1

    Update (08/27/2013): 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:
    Code:
    TF2Attrib_SetByName(iEntity, String:strAttrib[], Float:flValue)
    Address:TF2Attrib_GetByName(iEntity, String:strAttrib[])
    bool:TF2Attrib_RemoveByName(iEntity, String:strAttrib[])
    bool:TF2Attrib_RemoveAll(iEntity)
    TF2Attrib_ListDefIndices(iEntity, iDefIndices[])
    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.
    Code:
    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.

    Installation (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.

    Cvars:
    tf2attributes_version -
    do not touch.

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

    Changelog:
    Code:
    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
    Attached Files
    File Type: sp Get Plugin or Get Source (tf2attributes.sp - 11611 views - 24.6 KB)
    File Type: inc tf2attributes.inc (9.4 KB, 6998 views)
    File Type: txt tf2.attributes.txt (7.0 KB, 6576 views)
    File Type: sp Get Plugin or Get Source (tf2attributes_example.sp - 1182 views - 17.2 KB)
    __________________
    Bread EOTL will break everything. Don't even ask.

    All plugins: Randomizer/GiveWeapon, ModelManager, BetheHorsemann, etc. (+SaxtonHale)
    Don't ask me about SourceMod stuff on Steam; instead, post in a thread or send PM here. You will be fed to javalia if you don't.
    Psyduck likes replays.

    Last edited by FlaminSarge; 11-16-2014 at 04:08.
    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 will break everything. Don't even ask.

    All plugins: Randomizer/GiveWeapon, ModelManager, BetheHorsemann, etc. (+SaxtonHale)
    Don't ask me about SourceMod stuff on Steam; instead, post in a thread or send PM here. You will be fed to javalia if you don't.
    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 will break everything. Don't even ask.

    All plugins: Randomizer/GiveWeapon, ModelManager, BetheHorsemann, etc. (+SaxtonHale)
    Don't ask me about SourceMod stuff on Steam; instead, post in a thread or send PM here. You will be fed to javalia if you don't.
    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: Soviet Union
    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
    Oh Ross.
    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).
    __________________
    My SourceMod Plugins
    PropHunt Dev Server: tf2.rbemrose.com:27015
    Testing backlog: NativeVotes, Opt-in MultiMod (low priority)
    Powerlord is online now
    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 will break everything. Don't even ask.

    All plugins: Randomizer/GiveWeapon, ModelManager, BetheHorsemann, etc. (+SaxtonHale)
    Don't ask me about SourceMod stuff on Steam; instead, post in a thread or send PM here. You will be fed to javalia if you don't.
    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 will break everything. Don't even ask.

    All plugins: Randomizer/GiveWeapon, ModelManager, BetheHorsemann, etc. (+SaxtonHale)
    Don't ask me about SourceMod stuff on Steam; instead, post in a thread or send PM here. You will be fed to javalia if you don't.
    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 will break everything. Don't even ask.

    All plugins: Randomizer/GiveWeapon, ModelManager, BetheHorsemann, etc. (+SaxtonHale)
    Don't ask me about SourceMod stuff on Steam; instead, post in a thread or send PM here. You will be fed to javalia if you don't.
    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 12:02.


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