Raised This Month: $ Target: $400
 0% 

GetArrayString - InvalidIndex 1 ;/


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Kamil445
Member
Join Date: Dec 2013
Old 09-18-2016 , 12:05   GetArrayString - InvalidIndex 1 ;/
Reply With Quote #1

hi i have this problem:

Code:
L 09/18/2016 - 18:02:42: [SM] Exception reported: Invalid index 1 (count: 1)
L 09/18/2016 - 18:02:42: [SM] Blaming: buildinghats.smx()
L 09/18/2016 - 18:02:42: [SM] Call stack trace:
L 09/18/2016 - 18:02:42: [SM]   [0] GetArrayString
L 09/18/2016 - 18:02:42: [SM]   [1] Line 534, buildinghats.sp::Event_PlayerBuiltObject()
and

Code:
L 09/18/2016 - 18:02:27: [SM] Exception reported: Invalid index 1 (count: 1)
L 09/18/2016 - 18:02:27: [SM] Blaming: buildinghats.smx()
L 09/18/2016 - 18:02:27: [SM] Call stack trace:
L 09/18/2016 - 18:02:27: [SM]   [0] GetArrayString
L 09/18/2016 - 18:02:27: [SM]   [1] Line 491, buildinghats.sp::Timer_ReHat()
how to fix that ?

Code:
ublic Action:Timer_ReHat(Handle:timer, any:iBuilding)
{
    if(!g_bCvarEnabled) 
        return Plugin_Continue;

    if(iBuilding > MaxClients && IsValidEntity(iBuilding))
    {
        decl String:strPath[PLATFORM_MAX_PATH], String:strOffz[16], String:strScale[16], String:strAnima[128];
        new row = (GetArraySize(hHatInfo) / 4) - 1;
        new index = (GetRandomInt(0, row)) * 4;

        GetArrayString(hHatInfo, index+1, strPath, sizeof(strPath));   // LINE 491 <<<--------------------------
        GetArrayString(hHatInfo, index+2, strOffz, sizeof(strOffz));
        GetArrayString(hHatInfo, index+3, strScale, sizeof(strScale));
        GetArrayString(hHatInfo, index+4, strAnima, sizeof(strAnima));
        
        new TFObjectType:objectT = TFObjectType:TF2_GetObjectType(iBuilding)
        
        if(objectT == TFObject_Sentry)
            ParentHatEntity(iBuilding, strPath, StringToFloat(strOffz), StringToFloat(strScale), TFObject_Sentry, strAnima);
        else if(objectT == TFObject_Dispenser)
            ParentHatEntity(iBuilding, strPath, StringToFloat(strOffz), StringToFloat(strScale), TFObject_Dispenser, strAnima);
    }
    
    return Plugin_Handled;
}
Code:
public Action:Event_PlayerBuiltObject(Handle:event, const String:name[], bool:dontBroadcast)
{
    if(!g_bCvarEnabled) 
        return Plugin_Continue;
        
    new client = GetClientOfUserId(GetEventInt(event, "userid"));
    new TFObjectType:objectT = TFObjectType:GetEventInt(event, "object");
    
    if(client >= 1 && client <= MaxClients && IsClientInGame(client) && g_bWantsTheH[client])
    {
        if(!CheckCommandAccess(client, "sm_buildinghats_access", 0))
            return Plugin_Handled;
        
        new iBuilding = GetEventInt(event, "index");
        if(iBuilding > MaxClients && IsValidEntity(iBuilding))
        {
            if(!GetEntProp(iBuilding, Prop_Send, "m_bCarryDeploy"))
            {
                g_ModelIndex[iBuilding]  = INVALID_STRING_INDEX;
                g_flZOffset[iBuilding]   = 0.0;
                g_flModelScale[iBuilding]= 0.0;
                Format(g_strParticle[iBuilding], sizeof(g_strParticle), "");
                
                decl String:strPath[PLATFORM_MAX_PATH], String:strOffz[16], String:strScale[16], String:strAnima[128];
                new row = (GetArraySize(hHatInfo) / 4) - 1;
                new index = (GetRandomInt(0, row)) * 4;

                GetArrayString(hHatInfo, index+1, strPath, sizeof(strPath)); // LINE 534 <<<-------------------------
                GetArrayString(hHatInfo, index+2, strOffz, sizeof(strOffz));
                GetArrayString(hHatInfo, index+3, strScale, sizeof(strScale));
                GetArrayString(hHatInfo, index+4, strAnima, sizeof(strAnima));
            
                if(objectT == TFObject_Sentry)
                {
                    if(GetEntProp(iBuilding, Prop_Send, "m_bMiniBuilding"))
                    {
                        SetVariantInt(2);
                        AcceptEntityInput(iBuilding, "SetBodyGroup");
                        CreateTimer(3.0, Timer_TurnTheLightsOff, iBuilding);
                    }

                    ParentHatEntity(iBuilding, strPath, StringToFloat(strOffz), StringToFloat(strScale), TFObject_Sentry, strAnima);
                //    PrintToChatAll("%s", strPath);
                }
                else if(objectT == TFObject_Dispenser)
                {
                    ParentHatEntity(iBuilding, strPath, StringToFloat(strOffz), StringToFloat(strScale), TFObject_Dispenser, strAnima);
                //    PrintToChatAll("%s", strPath);
                }
            }
        }
    }
    
    return Plugin_Handled;
}
Thanks for help ))

Last edited by Kamil445; 09-18-2016 at 12:06.
Kamil445 is offline
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 09-18-2016 , 12:41   Re: GetArrayString - InvalidIndex 1 ;/
Reply With Quote #2

Array indexing starts at 0, not at 1.

With an array with 1 element in it, you can only get that element using index 0.
Potato Uno is offline
Kamil445
Member
Join Date: Dec 2013
Old 09-18-2016 , 13:36   Re: GetArrayString - InvalidIndex 1 ;/
Reply With Quote #3

Thanks, so.. can you help me fix that i dont know how to ?
Kamil445 is offline
Spirit_12
Veteran Member
Join Date: Dec 2012
Location: Toronto, CA
Old 09-18-2016 , 16:06   Re: GetArrayString - InvalidIndex 1 ;/
Reply With Quote #4

What Potato Uno is trying to say is that an array index starts from 0 and not 1.

PHP Code:
GetArrayString(hHatInfoindex+1strPathsizeof(strPath));   // LINE 491 <<<--------- 
Hence this code will become:


PHP Code:
GetArrayString(hHatInfoindex+0strPathsizeof(strPath));   // LINE 491 <<<--------- 
Your array will have index from 0 to 3, as opposed to 1 to 4.

Same for the line 534.
__________________
Spirit_12 is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 09-18-2016 , 16:50   Re: GetArrayString - InvalidIndex 1 ;/
Reply With Quote #5

However, the code looks like it wants four separate indices when the size of the ArrayList is only 1, so there's a different issue going on here.

It looks like you forgot to create a configs/buildinghats.cfg file for the plugin at in this thread.
__________________
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; 09-18-2016 at 16:52.
nosoop is offline
Kamil445
Member
Join Date: Dec 2013
Old 09-19-2016 , 06:08   Re: GetArrayString - InvalidIndex 1 ;/
Reply With Quote #6

Quote:
Originally Posted by nosoop View Post
However, the code looks like it wants four separate indices when the size of the ArrayList is only 1, so there's a different issue going on here.

It looks like you forgot to create a configs/buildinghats.cfg file for the plugin at in this thread.
You're right.. I have cfg file in "cfg/sourcemod/" now in "/sourcemod/configs/" and working perfect!

Thank you!, I'm so stupid :/
Kamil445 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 19:31.


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