AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [AMXX] Run time error 4: index out of bounds (https://forums.alliedmods.net/showthread.php?t=276046)

Michell 12-13-2015 15:19

[AMXX] Run time error 4: index out of bounds
 
PHP Code:

public MakeMsg(){
    new 
iTeamiTempidszName[33], szTemp[100];
    
    for( new 
06i++ ){
        if(
iPlayers] < 1)
            continue;
        
        
iTempid iPlayers];
        
        
iTeam fm_cs_get_user_teamiTempid );
        
        
get_user_name(iTempidszNamecharsmax(szName));
        
        
formatex(szTempsizeof(szTemp), "%s - %d Kills^n"szNameg_killsiTempid ]);
        
add(HudMsg[iTeam],511,szTemp);
    }



Bugsy 12-13-2015 15:33

Re: [AMXX] Run time error 4: index out of bounds
 
Show how iPlayers is defined and getting filled with player id's

You should use charsmax() and not sizeof() in formatex().

Michell 12-13-2015 15:43

Re: [AMXX] Run time error 4: index out of bounds
 
PHP Code:

new playersg_kills[33], HudMsg[3][ 512 ], iPlayers] ; 


Bugsy 12-13-2015 15:46

Re: [AMXX] Run time error 4: index out of bounds
 
Quote:

Originally Posted by Michell (Post 2372159)
PHP Code:

new playersg_kills[33], HudMsg[3][ 512 ], iPlayers] ; 


Quote:

Originally Posted by Bugsy (Post 2372154)
Show how iPlayers is defined and getting filled with player id's


Michell 12-13-2015 15:50

Re: [AMXX] Run time error 4: index out of bounds
 
like this ?

PHP Code:

public MakeMsg(){
    new 
iTeamiTempidszName[33], szTemp[100];
    
    for( new 
06i++ ){
        if(
iPlayers] < 1)
            continue;
        
        
iTempid iPlayers];
        
        
iTeam fm_cs_get_user_teamiTempid );
        
        
get_user_name(iTempidszNamecharsmax(szName));
        
        
formatex(szTempcharsmax(szTemp), "%s - %d Kills^n"szNameg_killsiTempid ]);
        
add(HudMsg[iTeam],511,szTemp);
    }



Bugsy 12-13-2015 15:54

Re: [AMXX] Run time error 4: index out of bounds
 
Based on that code, the whole iPlayers[] array will be 0's. You are not showing how it is populated with player id's.

What you should do, is define iPlayers[ 32 ], and use get_players() to fill it.

http://www.amxmodx.org/api/amxmodx/get_players


All times are GMT -4. The time now is 18:14.

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