Raised This Month: $32 Target: $400
 8% 

Solved [TF2] Converting to Econ Data


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 12-24-2021 , 05:09   [TF2] Converting to Econ Data
Reply With Quote #1

I'm having a bit of difficulty converting a plugin from tf2itemsinfo over to econ data

Original code source (not mine): https://github.com/NoradTF2/Fixed-Uber-Upgrades

I'm struggling with the proper way to use TF2Econ_GetItemStaticAttributes to replace TF2II_GetItemNumAttributes, TF2II_GetItemAttributeID, and TF2II_GetItemAttributeValue.

Original code:
PHP Code:
public DefineAttributesTab(clientitemidxslot)
{
    
//PrintToChat(client, "Entering Def attr tab, ent id: %d", itemidx);
    //PrintToChat(client, "  #dattrtab item carried: %d - item_buff: %d", itemidx, currentitem_idx[client][slot]);
    
if (currentitem_idx[client][slot] == 9999)
    {
        new 
aa2ia_i;

        
currentitem_idx[client][slot] = itemidx;
        new 
inumAttr TF2II_GetItemNumAttributesitemidx );
        for( 
0a2 0inumAttr && 42a++ )
        {
            
decl String:Buf[64];
            
a_i TF2II_GetItemAttributeIDitemidxa);
            
TF2II_GetAttribNamea_iBuf64);
        
//    if (!GetTrieValue(_upg_names, Buf, i))
        //    {
        //        i = _u_id
        //        upgradesNames[i] = Buf
        //        upgrades_costs[i] = 1
        //        SetTrieValue(_upg_names, Buf, _u_id++)
        //        upgrades_to_a_id[i] = a_i
        //    }
            
if (GetTrieValue(_upg_namesBufi))
            {
                
currentupgrades_idx[client][slot][a2] = i;

                
upgrades_ref_to_idx[client][slot][i] = a2;
                
currentupgrades_val[client][slot][a2] = TF2II_GetItemAttributeValueitemidx);
                
//PrintToChat(client, "init-attribute-[%s]%d [%d ; %f]",
            //    upgradesNames[currentupgrades_idx[client][slot][a2]],
            //    itemidx, i, currentupgrades_val[client][slot][a]);
                
a2++;
            }
        }
        
currentupgrades_number[client][slot] = a2;
    }
    else
    {
        if (
itemidx && itemidx != currentitem_idx[client][slot])
        {
            
ResetClientUpgrade_slot(clientslot);
            new 
aa2ia_i;

            
currentitem_idx[client][slot] = itemidx;
            new 
inumAttr TF2II_GetItemNumAttributesitemidx );
            for( 
0a2 0inumAttr && 42a++ )
            {
                
decl String:Buf[64];
                
a_i TF2II_GetItemAttributeIDitemidxa);
                
TF2II_GetAttribNamea_iBuf64);
        
//    if (!GetTrieValue(_upg_names, Buf, i))
        //    {
        //        i = _u_id
        //        upgradesNames[i] = Buf
        //        upgrades_costs[i] = 1
        //        SetTrieValue(_upg_names, Buf, _u_id++)
        //        upgrades_to_a_id[i] = a_i
        //    }
                
if (GetTrieValue(_upg_namesBufi))
                {
                    
currentupgrades_idx[client][slot][a2] = i;

                    
upgrades_ref_to_idx[client][slot][i] = a2;
                    
currentupgrades_val[client][slot][a2] = TF2II_GetItemAttributeValueitemidx);
                    
//PrintToChat(client, "init-attribute-%d [%d ; %f]", itemidx, i, currentupgrades_val[client][slot][a]);
                    
a2++;
                }
            }
            
currentupgrades_number[client][slot] = a2;
        }
    }
    
//PrintToChat(client, "..finish #dattrtab ");

This is as far as I got before I was stumped:
PHP Code:
public DefineAttributesTab(clientitemidxslot)
{
    if (
currentitem_idx[client][slot] == 9999)
    {
        new 
aa2ia_i;

        
currentitem_idx[client][slot] = itemidx;
        new 
inumAttr 0;
        new 
Handle:hAttributes TF2Econ_GetItemStaticAttributes(itemidx);
        if(
hAttributes == INVALID_HANDLE)
        {
            
inumAttr 0;
        }
        else
        {
            
inumAttr RoundToFloorfloatGetArraySizehAttributes ) ) / 2.0 );
        }
        for( 
0a2 0inumAttr && 42a++ )
        {
            
decl String:Buf[64];
            
a_i TF2II_GetItemAttributeIDitemidxa);
            
TF2Econ_GetAttributeNamea_iBuf64);
            if (
GetTrieValue(_upg_namesBufi))
            {
                
currentupgrades_idx[client][slot][a2] = i;

                
upgrades_ref_to_idx[client][slot][i] = a2;
                
currentupgrades_val[client][slot][a2] = TF2II_GetItemAttributeValueitemidx);
                
a2++;
            }
        }
        
delete hAttributes;
        
currentupgrades_number[client][slot] = a2;
    }
    else
    {
        if (
itemidx && itemidx != currentitem_idx[client][slot])
        {
            
ResetClientUpgrade_slot(clientslot);
            new 
aa2ia_i;

            
currentitem_idx[client][slot] = itemidx;
            new 
inumAttr 0;
            new 
Handle:hAttributes TF2Econ_GetItemStaticAttributes(itemidx);
            if(
hAttributes == INVALID_HANDLE)
            {
                
inumAttr 0;
            }
            else
            {
                
inumAttr RoundToFloorfloatGetArraySizehAttributes ) ) / 2.0 );
            }
            for( 
0a2 0inumAttr && 42a++ )
            {
                
decl String:Buf[64];
                
a_i TF2II_GetItemAttributeIDitemidxa);
                
TF2Econ_GetAttributeNamea_iBuf64);
                if (
GetTrieValue(_upg_namesBufi))
                {
                    
currentupgrades_idx[client][slot][a2] = i;

                    
upgrades_ref_to_idx[client][slot][i] = a2;
                    
currentupgrades_val[client][slot][a2] = TF2II_GetItemAttributeValueitemidx);
                    
a2++;
                }
            }
            
delete hAttributes;
            
currentupgrades_number[client][slot] = a2;
        }
    }

Information from tf_econ_data_compat.sp
PHP Code:
    //TF2II_GetItemNumAttributes() can be done by getting the length of the ArrayList returned from TF2Econ_GetItemStaticAttributes().
    
CreateNative("TF2II_GetItemNumAttributes"Native_TF2II_GetItemNumAttributes);
    
    
//TF2II_GetItemAttributeName() can be done by getting the attribute ID from the ArrayList returned from TF2Econ_GetItemStaticAttributes(), calling TF2Econ_GetAttributeName() to get the name.
    
CreateNative("TF2II_GetItemAttributeName"Native_NotImplemented);
    
    
//TF2II_GetItemAttributeID() can be done by getting the attribute ID from the ArrayList returned from TF2Econ_GetItemStaticAttributes().
    
CreateNative("TF2II_GetItemAttributeID"Native_TF2II_GetItemAttributeID);
    
    
//TF2II_GetItemAttributeValue() can be done by getting the attribute value from TF2Econ_GetItemStaticAttributes(). This returns a raw 32-bit value; if the attribute is a string / vector you'll probably be better off calling TF2Econ_GetItemDefinitionString(defindex, "static_attrs/${attr}", ...) with the attribute name.
    
CreateNative("TF2II_GetItemAttributeValue"Native_TF2II_GetItemAttributeValue); 
Can someone illustrate the proper usage of TF2Econ_GetItemStaticAttributes to get an attribute id and a value?

Last edited by PC Gamer; 12-24-2021 at 07:58.
PC Gamer is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 12-24-2021 , 06:20   Re: [TF2] Converting to Econ Data
Reply With Quote #2

I don't feel like parsing the source code for what you're trying to change, but regardless -

TF2Econ_GetItemStaticAttributes returns an ArrayList with the attribute definition index in the first block and the raw attribute value in the second; that is what the documentation means about the attribute defindex and [attribute] value pairs. The raw attribute value is whatever the game stores (it's the same value you'd get from TF2Attrib_GetValue, so an integer / float / union / container pointer type).

The implementation of the compatibility shim natives illustrate this. When you're porting, you can of course reuse the same ArrayList instance.
__________________
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)
nosoop is offline
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 12-24-2021 , 07:58   Re: [TF2] Converting to Econ Data
Reply With Quote #3

That is exactly what I needed. Thanks nosoop!
PC Gamer 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 22:52.


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