1313 * @return True if the attribute was added successfully, false if entity does not have m_AttributeList.
1414 * @error Invalid entity index or attribute name passed.
1515 */
16- native bool TF2Attrib_SetByName (int iEntity , char [] strAttrib , float flValue );
16+ native bool TF2Attrib_SetByName (int iEntity , const char [] strAttrib , float flValue );
1717
1818/* *
1919 * Sets an attribute's value on an entity, adding it if it isn't on the entity.
@@ -27,6 +27,23 @@ native bool TF2Attrib_SetByName(int iEntity, char[] strAttrib, float flValue);
2727 */
2828native bool TF2Attrib_SetByDefIndex (int iEntity , int iDefIndex , float flValue );
2929
30+ /* *
31+ * Parses the attribute name and value strings and applies it on the entity. This parses
32+ * numeric and string attributes.
33+ *
34+ * If you use this on a non-numeric attribute, make sure that only the server reads off of that
35+ * attribute. Non-primitive values aren't replicated correctly between the client and the
36+ * server; the client will read garbage and may crash!
37+ *
38+ * @param iEntity Entity index to set the attribute on. Must have m_AttributeList.
39+ * @param strAttrib Name of the attribute, as from the "name" key in items_game.
40+ * @param strValue Value to set the attribute to.
41+ *
42+ * @return True if the attribute was added successfully, false if the attribute name was invalid.
43+ * @error Invalid entity index or entity does not have m_AttributeList.
44+ */
45+ native bool TF2Attrib_SetFromStringValue (int iEntity , const char [] strAttrib , const char [] strValue );
46+
3047/* *
3148 * Returns the address of an attribute on an entity.
3249 *
@@ -36,7 +53,7 @@ native bool TF2Attrib_SetByDefIndex(int iEntity, int iDefIndex, float flValue);
3653 * @return Address of the attribute on the entity, or Address_Null if the attribute does not exist on the entity.
3754 * @error Invalid entity index or attribute name passed.
3855 */
39- native Address TF2Attrib_GetByName (int iEntity , char [] strAttrib );
56+ native Address TF2Attrib_GetByName (int iEntity , const char [] strAttrib );
4057
4158/* *
4259 * Returns the address of an attribute (by attribute index) on an entity.
@@ -58,7 +75,7 @@ native Address TF2Attrib_GetByDefIndex(int iEntity, int iDefIndex);
5875 * @return True if the SDKCall was made, false if entity had invalid address or m_AttributeList missing.
5976 * @error Invalid entity index or attribute name passed.
6077 */
61- native bool TF2Attrib_RemoveByName (int iEntity , char [] strAttrib );
78+ native bool TF2Attrib_RemoveByName (int iEntity , const char [] strAttrib );
6279
6380/* *
6481 * Removes an attribute from an entity.
@@ -134,6 +151,20 @@ native void TF2Attrib_SetValue(Address pAttrib, float flValue);
134151 */
135152native float TF2Attrib_GetValue (Address pAttrib );
136153
154+ /* *
155+ * Returns the string data from its raw value representation (a CAttribute_String instance).
156+ *
157+ * WARNING: This dereferences the input value! Feeding it values that aren't CAttribute_String pointers will result in unexpected behavior, potentially crashing the server.
158+ * In the case where you only want the currently active value, use TF2Attrib_HookValueString instead.
159+ *
160+ * @param pRawValue Raw attribute value. You can get this value with either TF2Attrib_GetValue, TF2Attrib_GetSOCAttribs, or TF2Attrib_GetStaticAttribs.
161+ * @param buffer Buffer to store the resulting string to.
162+ * @param maxlen Maximum length of the buffer.
163+ *
164+ * @return Number of bytes written.
165+ */
166+ native int TF2Attrib_UnsafeGetStringValue (any pRawValue , char [] buffer , int maxlen );
167+
137168/* *
138169 * Sets the value of m_nRefundableCurrency on an attribute.
139170 *
@@ -202,6 +233,72 @@ native int TF2Attrib_GetSOCAttribs(int iEntity, int[] iAttribIndices, float[] fl
202233 */
203234native bool TF2Attrib_IsIntegerValue (int iDefIndex );
204235
236+ /* *
237+ * Returns true if an attribute with the specified name exists.
238+ *
239+ * @param strAttrib Name of the attribute, as from the "name" key in items_game.
240+ *
241+ * @return True if the attribute exists, false otherwise.
242+ */
243+ native bool TF2Attrib_IsValidAttributeName (const char [] strAttrib );
244+
245+ /* *
246+ * Adds a custom, potentially temporary attribute to a player.
247+ *
248+ * @param client Client index to set the attribute on.
249+ * @param strAttrib Name of the attribute, as from the "name" key in items_game.
250+ * @param flValue Value to set m_flValue to.
251+ * @param flDuration Duration of the attribute. If less than 0, the attribute will not be automatically removed.
252+ *
253+ * @noreturn
254+ */
255+ native void TF2Attrib_AddCustomPlayerAttribute (int client , const char [] strAttrib , float flValue , float flDuration = -1.0 );
256+
257+ /* *
258+ * Removes a previously applied custom attribute on a player.
259+ *
260+ * @param client Client index to remove the attribute from.
261+ * @param strAttrib Name of the attribute, as from the "name" key in items_game.
262+ *
263+ * @noreturn
264+ */
265+ native void TF2Attrib_RemoveCustomPlayerAttribute (int client , const char [] strAttrib );
266+
267+ /* *
268+ * Applies a transformation to the given initial value, following the rules according to the given attribute class.
269+ *
270+ * @param flInitial Initial float value.
271+ * @param attrClass The attribute class, as from the "attribute_class" key in items_game.
272+ * @param iEntity The entity that should be checked. Checking players also checks their equipped items.
273+ *
274+ * @return Transformed initial value.
275+ */
276+ native float TF2Attrib_HookValueFloat (float flInitial , const char [] attrClass , int iEntity );
277+
278+ /* *
279+ * Applies a transformation to the given initial value, following the rules according to the given attribute class.
280+ *
281+ * @param nInitial Initial integer value.
282+ * @param attrClass The attribute class, as from the "attribute_class" key in items_game.
283+ * @param iEntity The entity that should be checked. Checking players also checks their equipped items.
284+ *
285+ * @return Transformed initial value.
286+ */
287+ native int TF2Attrib_HookValueInt (int nInitial , const char [] attrClass , int iEntity );
288+
289+ /* *
290+ * Applies a transformation to the given initial value, following the rules according to the given attribute class.
291+ *
292+ * @param initial Initial string value. (This appears to only be returned if the entity doesn't have the attribute.)
293+ * @param attrClass The attribute class, as from the "attribute_class" key in items_game.
294+ * @param iEntity The entity that should be checked. Checking players also checks their equipped items.
295+ * @param buffer Transformed initial value.
296+ * @param maxlen Buffer size.
297+ *
298+ * @return Number of bytes written.
299+ */
300+ native int TF2Attrib_HookValueString (const char [] initial , const char [] attrClass , int iEntity , char [] buffer , int maxlen );
301+
205302/* *
206303 * Gets whether the plugin loaded without ANY errors.
207304 * For the purpose of allowing dependencies to ignore the plugin if this returns false.
@@ -244,63 +341,12 @@ public void __pl_tf2attributes_SetNTVOptional()
244341 MarkNativeAsOptional (" TF2Attrib_GetSOCAttribs" );
245342 MarkNativeAsOptional (" TF2Attrib_ListDefIndices" );
246343 MarkNativeAsOptional (" TF2Attrib_IsIntegerValue" );
344+ MarkNativeAsOptional (" TF2Attrib_IsValidAttributeName" );
345+ MarkNativeAsOptional (" TF2Attrib_AddCustomPlayerAttribute" );
346+ MarkNativeAsOptional (" TF2Attrib_RemoveCustomPlayerAttribute" );
347+ MarkNativeAsOptional (" TF2Attrib_HookValueFloat" );
348+ MarkNativeAsOptional (" TF2Attrib_HookValueInt" );
349+
247350 MarkNativeAsOptional (" TF2Attrib_IsReady" );
248-
249- // MarkNativeAsOptional("TF2Attrib_SetInitialValue");
250- // MarkNativeAsOptional("TF2Attrib_GetInitialValue");
251- // MarkNativeAsOptional("TF2Attrib_SetIsSetBonus");
252- // MarkNativeAsOptional("TF2Attrib_GetIsSetBonus");
253351}
254352#endif
255-
256- //OLD things lie here
257- //flInitialValue and bSetBonus don't exist anymore
258- /* *
259- * Sets the value of m_flInitialValue on an attribute.
260- *
261- * @param pAttrib Address of the attribute.
262- * @param flValue Value to set m_flInitialValue to.
263- *
264- * @noreturn
265- */
266- //native TF2Attrib_SetInitialValue(Address pAttrib, float flValue);
267-
268- /* *
269- * Returns the value of m_flInitialValue on an attribute.
270- *
271- * @param pAttrib Address of the attribute.
272- *
273- * @return The floating point value of m_flInitialValue on the attribute.
274- */
275- //native float TF2Attrib_GetInitialValue(Address pAttrib);
276-
277- /* *
278- * Sets the boolean value of m_bSetBonus on an attribute.
279- *
280- * @param pAttrib Address of the attribute.
281- * @param bSetBonus Value to set m_bSetBonus to.
282- *
283- * @noreturn
284- */
285- //native TF2Attrib_SetIsSetBonus(Address pAttrib, bool bSetBonus);
286-
287- /* *
288- * Returns the boolean value of m_bSetBonus on an attribute.
289- *
290- * @param pAttrib Address of the attribute.
291- *
292- * @return The boolean value of m_bSetBonus on the attribute.
293- */
294- //native bool TF2Attrib_GetIsSetBonus(Address pAttrib);
295-
296- //stock TF2Attrib_IsIntegerValue(iDefIndex)
297- //{
298- // switch (iDefIndex)
299- // {
300- // case 133, 143, 147, 152, 184, 185, 186, 192, 193, 194, 198, 211, 214, 227, 228, 229, 262, 294, 302, 372, 373, 374, 379, 381, 383, 403, 420:
301- // {
302- // return true;
303- // }
304- // }
305- // return false;
306- //}
0 commit comments