AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   [TF2attributes] Grab attributs of a player ? (https://forums.alliedmods.net/showthread.php?t=233130)

Arkarr 01-10-2014 07:53

[TF2attributes] Grab attributs of a player ?
 
Just wondering if there is anyway to grab a attribut of a player ?

I have done this :
PHP Code:

new hClientWeapon GetEntPropEnt(clientProp_Send"m_hActiveWeapon");
new 
Address:attr TF2Attrib_GetByName(hClientWeapon"damage bonus");
new 
result _:TF2Attrib_GetValue(attr); 

but it seems to crash my server...

And after I correctly grab the value of attribute in 'result' can I use it to like this ?

PHP Code:

TF2Attrib_SetByName(client"damage bonus"result); 


friagram 01-10-2014 09:48

Re: [TF2attributes] Grab attributs of a player ?
 
you need to validate the return values...
also, if it doesn't matter what the value is, you can just set it, and it will overwrite the existing one.
Likewise, you can call remove and it will safely remove it even if it's not there.

Powerlord 01-10-2014 09:55

Re: [TF2attributes] Grab attributs of a player ?
 
Is this on a Windows or Linux server?

It could be that the gamedata in TF2Attributes broke in a recent update (like yesterday's update).

Quote:

Originally Posted by Arkarr (Post 2083869)
PHP Code:

new result _:TF2Attrib_GetValue(attr); 


Incidentally, that's not how you convert a Float value to an int value... you need RoundFloat or one of the other Round functions for that.

friagram 01-10-2014 10:47

Re: [TF2attributes] Grab attributs of a player ?
 
Yeah, doing that will get you an int of something like 91829382193 or something, when you wanted 2

int > float do float(val)
float > int use RoundFloat, RoundToNearest, RoundToCeil, or RoundToFloor
convert anything to boolean just do bool:val

Arkarr 01-10-2014 11:07

Re: [TF2attributes] Grab attributs of a player ?
 
Windows server, I'm trying to save the old to apply it later. I don't know how to validate the value. Fonction for this ?
Exemple :
1) Original "damage bonus" = 10%, I save it somewhere
2) I set to 50% using TF2Attrib_SetByName(client, "damage bonus", 0.50); and start a timer.
3) When timer end, I apply back the original value. (10%) using TF2Attrib_SetByName(client, "damage bonus", OLD_VALUE);

So the correct to do this should be this ?
PHP Code:

//Save old attrbiut value into result, wich is Float
new hClientWeapon GetEntPropEnt(clientProp_Send"m_hActiveWeapon"); 
new 
Address:attr TF2Attrib_GetByName(hClientWeapon"damage bonus"); 
new 
Float:result _:TF2Attrib_GetValue(attr);

//I change the value to 50%:
TF2Attrib_SetByName(client"damage bonus"0.50);

//Timer end, I apply back the original 10% :
TF2Attrib_SetByName(client"damage bonus"result); 


Powerlord 01-10-2014 11:15

Re: [TF2attributes] Grab attributs of a player ?
 
PHP Code:

new Float:result _:TF2Attrib_GetValue(attr); 

Close, but it really should be

PHP Code:

new Float:result TF2Attrib_GetValue(attr); 


Arkarr 01-10-2014 11:18

Re: [TF2attributes] Grab attributs of a player ?
 
Thanks, gonna test. And what with this validation of value ?

friagram 01-10-2014 11:22

Re: [TF2attributes] Grab attributs of a player ?
 
It should be noted that you will not always be able to get "old values" or even stock values from items, as they are not accessable at the moment, and will return as if the item doesn't have them at all (when in fact they do).

You'll always be able to read them however, if they were applied with tf2attributes, or if they are MVM upgrades.

Arkarr 01-10-2014 11:27

Re: [TF2attributes] Grab attributs of a player ?
 
Well, that's why my server crash ? Because when I run the plugin, server immediatly crash, without warnings.

EDIT : Well, you can't grab atttribut on weapon but only on player! That's why my server crash.

So the correct code is :
PHP Code:

//Save old attrbiut value into result, wich is Float
//new hClientWeapon = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon"); 
new Address:attr TF2Attrib_GetByName(client"damage bonus"); 
new 
Float:result TF2Attrib_GetValue(attr);

//I change the value to 50%:
TF2Attrib_SetByName(client"damage bonus"0.50);

//Timer end, I apply back the original 10% :
TF2Attrib_SetByName(client"damage bonus"result); 



All times are GMT -4. The time now is 20:40.

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