Raised This Month: $51 Target: $400
 12% 

Solved [TF2] Multiplying attributes crashing clients


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
oplkill
Member
Join Date: Aug 2015
Old 12-26-2020 , 15:13   [TF2] Multiplying attributes crashing clients
Reply With Quote #1

I trying to make multiply attributes for weapons, but when i do that clients just crashing in all way that i tryed to do.

I tryed to use standart tf2 attributes library and https://github.com/nosoop/SM-TFEconData/releases, but them both crashing clients.

Way 1
PHP Code:
int defIndixes[16];
float defValues[16];
int multiply 100;
const 
int numWeaponSlots 3;
int slot[numWeaponSlots] = {WeaponSlot_PrimaryWeaponSlot_SecondaryWeaponSlot_Melee};

for (
int i=0i<numWeaponSlotsi++)
{
    
int weapIndex GetPlayerWeaponSlot(clientslot[i]);
    
int numAttrs TF2Attrib_GetStaticAttribs(GetItemDefinition(weapIndex), defIndixesdefValues);
    for (
int b 0numAttrsb++)
    {
        
char typedescription[32];
        if ( 
TF2Econ_GetAttributeDefinitionStringdefIndixes[b], "description_format"typedescription32 ) )
        {
            if ( 
StrEqualtypedescription"value_is_additive" ) || StrEqualtypedescription"value_is_percentage" ) && 
                
defValues[b] < 100.0 //for some reason some values are not Float
            
{       
                
TF2Attrib_SetByDefIndex(weapIndexdefIndixes[b], defValues[b] * multiply);
            }
        }
    }
    if (
numAttrs 0)
        
TF2Attrib_ClearCache(weapIndex);

Way 2
PHP Code:
bool isCompatibleItem(char[] classnameint iItemDefinitionIndex)
{
    return 
StrContains(classname"tf_weapon") != -||
        
StrEqual(classname"saxxy") ||
        
StrEqual(classname"tf_wearable_demoshield") ||
        (
StrEqual(classname"tf_wearable") &&
        (
iItemDefinitionIndex == 133 ||
        
iItemDefinitionIndex == 444 ||
        
iItemDefinitionIndex == 405 ||
        
iItemDefinitionIndex == 608 ||
        
iItemDefinitionIndex == 57 ||
        
iItemDefinitionIndex == 231 ||
        
iItemDefinitionIndex == 642));
}

public 
int TF2Items_OnGiveNamedItem_Post(int clientchar[] classnameint itemDefinitionIndexint itemLevelint itemQualityint entityIndex)
{
    
int multiply 100;
    if (!
isCompatibleItem(classnameitemDefinitionIndex)
    || (
itemQuality == && itemDefinitionIndex != 266)
    || 
itemQuality == || itemQuality == 10)
    {
        return;
    }

    
int defIndixes[16];
    
float defValues[16];
    
int numAttrs TF2Attrib_GetStaticAttribs(GetItemDefinition(entityIndex), defIndixesdefValues);

    for (
int b 0numAttrsb++)
    {
        
char typedescription[32];
        if ( 
TF2Econ_GetAttributeDefinitionStringdefIndixes[b], "description_format"typedescription32 ) )
        {
            if ( 
StrEqualtypedescription"value_is_additive" ) || StrEqualtypedescription"value_is_percentage" ) && defValues[b] < 100.0 )
            {       
                
TF2Attrib_SetByDefIndex(entityIndexdefIndixes[b], defValues[b] * multiply);
            }
        }
    }

What i do wrong?

Last edited by oplkill; 12-27-2020 at 10:18.
oplkill is offline
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 12-26-2020 , 20:58   Re: [TF2] Multiplying attributes crashing clients
Reply With Quote #2

Did you update to the newer version?

https://github.com/nosoop/SM-TFEconData/issues/7
PC Gamer is offline
oplkill
Member
Join Date: Aug 2015
Old 12-27-2020 , 05:52   Re: [TF2] Multiplying attributes crashing clients
Reply With Quote #3

em, yes, i using latest November 2 2020 version in release.
I updated gamedata to latest, but its still crashing clients. (not server!)
In server do not showing any error messages only that:
Quote:
Entity 1 (class 'player') reported ENTITY_CHANGE_NONE but 'm_nPlayerCondEx3' changed.
STEAMAUTH: Client Oplkill received failure code 6
Mostly crashing happening when i changing weapon in hands.(pressing 1/2/3 key)

Last edited by oplkill; 12-27-2020 at 05:53.
oplkill is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 12-27-2020 , 07:30   Re: [TF2] Multiplying attributes crashing clients
Reply With Quote #4

Printing which attributes are actually being modified is a good way to figure this out.

In particular, it looks like min_viewmodel_offset presents itself as additive, but string types aren't replicated across the client-server divide. Adding an additional check for attribute_type == "string" should resolve this.

There might be some other non-numeric types that need their own detection methods.
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)

Last edited by nosoop; 12-27-2020 at 07:49.
nosoop is offline
oplkill
Member
Join Date: Aug 2015
Old 12-27-2020 , 10:17   Re: [TF2] Multiplying attributes crashing clients
Reply With Quote #5

Thanks for helping, i found solution!

PHP Code:
void SetAttributesMultiply(int clientint multiply)
{
    
int defIndixes[16];
    
float defValues[16];

    const 
int numWeaponSlots 3;
    
int slot[numWeaponSlots] = {WeaponSlot_PrimaryWeaponSlot_SecondaryWeaponSlot_Melee};
 
    for (
int i=0i<numWeaponSlotsi++)
    {
        
int weapIndex GetPlayerWeaponSlot(clientslot[i]);
        if (!
IsValidEntity(weapIndex))
            continue;
        
int numAttrs TF2Attrib_GetStaticAttribs(GetItemDefinition(weapIndex), defIndixesdefValues);
        for (
int b 0numAttrsb++)
        {
            if (
defIndixes[b] == 817 || defIndixes[b] == 796//just for sure
            
{
                continue;
            }

            
char typedescription[32];
            if ( 
TF2Econ_GetAttributeDefinitionStringdefIndixes[b], "description_format"typedescription32 ) )
            {
                if (( 
StrEqualtypedescription"value_is_additive" ) || StrEqualtypedescription"value_is_percentage" )) && 
                        !
StrEqualtypedescription"string") && 
                        (
defValues[b] < -0.01 || defValues[b] > 0.01) && defValues[b] < 100.0 && 
                        (
defValues[b] < 0.98 || defValues[b] > 1.01))
                {       
                    
TF2Attrib_SetByDefIndex(weapIndexdefIndixes[b], defValues[b] * multiply);
                }
            }
        }
        if (
numAttrs 0)
            
TF2Attrib_ClearCache(weapIndex);
    }

You need to call that function with "1", when player dead and round win, for preventing crashes.
PHP Code:
SetAttributesMultiply(client1); 
oplkill is offline
Reply



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 13:12.


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