[TF2] TF2Attributes (v1.7.2, 2022/09/18)
39 Attachment(s)
⚠️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_SetByNameTF2Attrib_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;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.1Known 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 |
Re: [TF2] TF2Attributes (v1.0.0, 03/08/2013)
Reserved for things.
|
Re: [TF2] TF2Attributes (v1.0.0, 03/08/2013)
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.
|
Re: [TF2] TF2Attributes (v1.0.0, 03/08/2013)
Whoo-hoo! I've been waiting for this for a while. Time to develop!
|
Re: [TF2] TF2Attributes (v1.0.0, 03/08/2013)
Sweet.
But too late~ |
Re: [TF2] TF2Attributes (v1.0.0, 03/08/2013)
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). |
Re: [TF2] TF2Attributes (v1.0.0, 03/08/2013)
Quote:
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. |
Re: [TF2] TF2Attributes (v1.0.0, 03/08/2013)
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.
|
Re: [TF2] TF2Attributes (v1.0.0, 03/08/2013)
Quote:
EDIT: Actually, after some testing, it does it rarely. |
Re: [TF2] TF2Attributes (v1.0.0, 03/08/2013)
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.
|
Re: [TF2] TF2Attributes (v1.0.0, 03/08/2013)
Gonna play with this see what fun stuff can be done. Thnx as always for your work
|
Re: [TF2] TF2Attributes (v1.0.0, 03/08/2013)
Some of you may have noticed that certain attributes added to weapons that really take effect on the player, such as "max health additive bonus", don't work when the attribute is added to the weapon. The reason is that the player's attribute manager cache isn't cleared when the weapon's attributes are updated (Valve corrects for this in their own code, calling ClearCache on the player's attributes right after they make calls to add attributes to weapons), and it only updates when they regen/respawn.
So I'm adding TF2Attrib_ClearCache(entity), which would perform ClearCache on an entity's attributes. Note, however, that Set/Remove/RemoveAll already call ClearCache on the entity that is being added to/removed from (internally), and the only issue is the entity's OWNER (a weapon's player, for instance) not being updated. Thus, should I even add this native, or should I simply clear the attribute cache of m_hOwnerEntity of whatever entity is being used in Set/Remove/RemoveAll? Long story short, we don't NEED TF2Attrib_ClearCache(entity), and I can simply just call ClearCache on the m_hOwnerEntity of any weapons/wearables passed into Set/Remove/RemoveAll. Should I add the native anyways? |
Re: [TF2] TF2Attributes (v1.0.0, 03/08/2013)
Quote:
|
Re: [TF2] TF2Attributes (v1.0.0, 03/08/2013)
I'm not entirely sure if I'm understanding what your reply means, but it seems to me like the first half contradicts the second half: "I don't see why not" = "I don't see why you wouldn't add the native"; "it would be useful to most people to minimize their code" = not having the native, but making the automatic owner cache change a built-in part of the plugin would be useful since then plugin authors don't have to do it in their own code.
Which of the two do you mean? |
Re: [TF2] TF2Attributes (v1.0.0, 03/08/2013)
Quote:
|
Re: [TF2] TF2Attributes (v1.0.0, 03/08/2013)
The next update won't be adding the TF2Attrib_ClearCache native, as it's probably just better to call ClearCache on an entity's m_hOwnerEntity whenever add/remove/removeall are called, just to make sure attributes are properly updated each time they're given/removed. As such, it'll just do that call internally (with proper checks) instead of forcing plugin devs to call it whenever they need the attribute manager cache updated.
|
Re: [TF2] TF2Attributes (v1.0.0, 03/08/2013)
Scratch that last bit, ClearCache is sometimes necessary after editing an attribute's value via TF2Attrib_SetValue(), etc., so that native's going to exist.
Side note, DO NOT USE THE RETURN OF TF2Attrib_SetByName(). It's not the address of the created attribute. I botched that. It's some arbitrary other address that seems to be related to the entity or client who got the attribute. It IS, however, nonzero if the attribute creation was successful, so the next update will change that to bool:TF2Attrib_SetByName(). Hopefully I'm not breaking/misaligning anything by using SetReturnInfo when there isn't supposed to be a return (SetOrAddAttributeByName returns void, apparently). To get the address of an attribute you just created, you'll have to call Get right after Set and hope it grabs the address. |
Re: [TF2] TF2Attributes (v1.0.0, 03/08/2013)
Should I assume there's no function to set attributes by attribute index rather than by name?
Freak Fortress 2 operates on these not just for boss attributes (and there are hundreds of bosses out now) but also for functions that give new weapons to bosses. |
Re: [TF2] TF2Attributes (v1.0.0, 03/08/2013)
Quote:
Then when I was testing, I did not realize that I needed to put the name of the attribute, not the index. |
Re: [TF2] TF2Attributes (v1.0.0, 03/08/2013)
Nothing for *cleanly* adding attributes by index rather than name, unfortunately. You could probably wrap something around TF2ItemsInfo for that.
Or I could try constructing CEconItemAttribute in pawn. But apparently that's messy and bad and don't do it. However, since each attribute index maps to a name, it shouldn't be an issue and should actually make your code more readable than arbitrary numbers would, were you to switch to using this in place of attribs by index. |
Re: [TF2] TF2Attributes (v1.0.0, 03/08/2013)
Just started using this in my mod, but I ran into a small problem
At some point I want to change the players speed, so I tried this: TF2Attrib_SetByName(client,"move speed penalty",0.5); However, it only takes effect after the client switches weapon I've also tried some other tf2 attributes that affect speed, and they seem to have the same problem Is there a way to fix it, or should I somehow change the players active weapon slot to something else and back? This might be happening at a point where the player only has a melee weapon, so I don't know if it'd work then |
Re: [TF2] TF2Attributes (v1.0.0, 03/08/2013)
Try TF2_AddCondition(client, TFCond_SpeedBuffAlly, 0.3); after you give the attribute. It's what VSH does to re-calculate move speed changes.
|
Re: [TF2] TF2Attributes (v1.0.0, 03/08/2013)
Quote:
|
Re: [TF2] TF2Attributes (v1.0.0, 03/08/2013)
Oh, is 0.3 too much? Whoops. I knew there was a duration you could use that wouldn't cause any visual effects, but I was pretty sure that 0.3 wouldn't show anything. My bad.
|
Re: [TF2] TF2Attributes (v1.0.0, 03/08/2013)
The upcoming ClearCache native may or may not also do the trick, but VSH does not in fact use 0.3 (it does for Medic healing speed but that's moot).
Code:
TF2_AddCondition(client, TFCond_SpeedBuffAlly, 0.01); //recalc their speed... I really should just push that ClearCache change. |
Re: [TF2] TF2Attributes (v1.0.0, 03/08/2013)
<3
|
Re: [TF2] TF2Attributes (v1.0.1, 04/24/2013)
Updated on 04/24/2013 for ClearCache and GetByDefIndex.
Please read the notes next to ClearCache in the .inc file, as it tells you when you may/may not need to use it. |
Re: [TF2] TF2Attributes (v1.0.1, 04/24/2013)
I was wondering if it would be possible to make it so that you multiply all the attributes of a weapon by 2. I was thinking of using a large loop but I think that would be too intense. Got any other methods?
|
Re: [TF2] TF2Attributes (v1.0.1, 04/24/2013)
With SteamPipe due tomorrow and me just releasing a plugin that uses TF2Attributes... what's the status on SteamPipe gamedata?
|
Re: [TF2] TF2Attributes (v1.0.1, 04/24/2013)
My sig tells all.
I'll look it up some time tomorrow. Not sure about the x2everything thing. |
Re: [TF2] TF2Attributes (v1.0.1, 04/24/2013)
Quote:
|
[TF2] TF2Attributes (v1.0.1, 04/24/2013)
I checked with the gdc tools. Linux/OS X locations are given as symbol names, which gdc tries to find in the symbol table. Windows locations are given as byte patterns, which gdc tries to find in the code section of the DLL, making sure it finds each only once.
Both seem to be unchanged for the methods used by TF2Attributes. |
Re: [TF2] TF2Attributes (v1.0.1, 04/24/2013)
Nothing broke with this with SteamPipe on Windows, so we're good to go.
|
Re: [TF2] TF2Attributes (v1.0.1, 04/24/2013)
Sort of still stuck in a circle of figuring out why item attributes are applying themselves to the "Action" slot despite filtering out item ID's numbers by checking against the string trie. It's currently taking Melee (or, if available, PDA/PDA2 onto Action.) Even if I remove the melee slot before TF2Attributes apply, then it will just apply the secondary slot's attributes onto the Action slot. (I did try replacing "decl" with "new" in several places, Sarge, but it only made a difference on the first round, not any subsequent ones)
Tested by viewing stats in the MVM maps. Any clues on whether I'm doing this all wrong? Code:
public TF2Items_OnGiveNamedItem_Post(client, String:classname[], itemDefinitionIndex, itemLevel, itemQuality, entityIndex) |
Re: [TF2] TF2Attributes (v1.0.1, 04/24/2013)
Have you tried flat-out rejecting certain indices or classnames instead of relying on GetTrieString to reject them?
|
Re: [TF2] TF2Attributes (v1.0.1, 04/24/2013)
Oh man. I just... wow. I'm an idiot. I did try that days ago, but when I revisited it just now, I had a && where a || should've been. (Plus, I fixed something odd with ExplodeString returning ghost attributes, so the other problem is fixed.)
Thank you so much Sarge, and really sorry I've been bugging you :P |
Re: [TF2] TF2Attributes (v1.0.1, 04/24/2013)
Hello i've got a small problem with plugin. Halloween Attributes doesn't seem to work even with 'tf_forced_holiday'
|
Re: [TF2] TF2Attributes (v1.0.1, 04/24/2013)
Valve intentionally broke those, I believe. (What with Halloween being over, and all...still though :|)
|
Re: [TF2] TF2Attributes (v1.0.1, 04/24/2013)
Ya, Valve broke both Halloween and MvM stuff just for the creative community :(
Should be a work around in the future, somehow. |
Re: [TF2] TF2Attributes (v1.0.1, 04/24/2013)
Can a native to get all of the attributes on an entity be implemented (as opposed to having to blindly guess whether an entity even has an attribute)?
|
| All times are GMT -4. The time now is 14:21. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.