AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Run time error 3: stack error (https://forums.alliedmods.net/showthread.php?t=329753)

BeNq! 01-06-2021 05:42

Run time error 3: stack error
 
Hello,

I have a problem. Due to the fact that the buffer is 9999, an error occurs. How do I correct this from get_statsnum () then?

Code:

public clcmd_csgo_top15( id )
{               
        new iStatsTotal = get_statsnum();
        new gTopSort[ 9999 ][ 2 ];
       
        new iStats[ 8 ];
        new iBodyHits[ 8 ];
        new szName[ MAX_NAME_LENGTH ];

        for ( new i = 0 ; i < iStatsTotal ; i++ )
        {
                get_stats( i, iStats, iBodyHits, szName, charsmax( szName ) );
       
                gTopSort[ i ][ 0 ] = i;
                gTopSort[ i ][ 1 ] = iStats[ 0 ];
        }
   
        SortCustom2D( gTopSort, iStatsTotal, "Sort_TOP15" );
       
        new szMotd[ MAX_MOTD_LENGTH ], iLen;
       
        iLen = formatex( szMotd, charsmax( szMotd ), "<head><meta charset=UTF-8>\
        <style>body{background: #000}table, th, td{border: 1px solid black;border-collapse: collapse;}</style></head>\
        <body><table width=100%% cellpadding=2 cellspacing=0 border=1>\
        <tr align=center style=color:#00c4ff><th width=20%%>#<th width=60%%>Player<th width=20%%>Kills</tr>");
               
        for( new x = 0; x < 15; x++ )
        {
                get_stats( gTopSort[ x ][ 0 ], iStats, iBodyHits, szName, charsmax( szName ) );
                               
                iLen += formatex( szMotd[ iLen ], ( sizeof szMotd - 1 ) - iLen, "<tr align=center style=^"color:#fff^"><td>%d<td>%s<td>%s", x + 1, szName, gTopSort[ x ][ 1 ] );
        }
       
        iLen += formatex( szMotd[iLen], ( sizeof szMotd - 1 ) - iLen, "</body></font></pre>" );
        show_motd( id, szMotd, "TOP 15" );
}


Black Rose 01-06-2021 08:14

Re: Run time error 3: stack error
 
Code:
static gTopSort[ 9999 ][ 2 ];

Since everything is regulated by iStatsTotal you shouldn't have to clean it each cycle (static is more or less a global variable and retains it's value when execution is exiting the scope)

Natsheh 01-06-2021 20:28

Re: Run time error 3: stack error
 
You don't need to use an array that big, use instead the dynamic array system.

Also I don't think you need any sorting, show sort_TOP15


All times are GMT -4. The time now is 10:07.

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