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

Run time error 4: index out of bounds


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
JuanitoAlimana
Senior Member
Join Date: Aug 2021
Old 05-19-2023 , 02:43   Run time error 4: index out of bounds
Reply With Quote #1

This is a soccer jam plugin. I keep getting this error after a player scores a goal.

[AMXX] Displaying debug trace (plugin "Sj-Pro.amxx", version "6.0b")
[AMXX] Run time error 4: index out of bounds
[AMXX] [0] Sj-Pro.sma::touchNet (line 1891)

1886
PHP Code:
public touchNet(ballgoalpost)
1887   {
1888            remove_task(55555)
1889
1890            
new team get_user_team(ballowner)
1891     new golent GoalEnt[team
What should I modify?
JuanitoAlimana is offline
Fuck For Fun
Veteran Member
Join Date: Nov 2013
Old 05-19-2023 , 03:59   Re: Run time error 4: index out of bounds
Reply With Quote #2

please remove the numbers lines to each
Quote:
here
and add full public touchNet
Fuck For Fun is offline
Send a message via Skype™ to Fuck For Fun
JuanitoAlimana
Senior Member
Join Date: Aug 2021
Old 05-19-2023 , 04:19   Re: Run time error 4: index out of bounds
Reply With Quote #3

PHP Code:
public touchNet(ballgoalpost)
{
    
remove_task(55555)

    new 
team get_user_team(ballowner)
    new 
golent GoalEnt[team]
    if (
goalpost != golent && ballowner 0
    {
        new 
aname[64]
        new 
Float:netOrig[3]
        new 
netOrig2[3]

        
entity_get_vector(ballEV_VEC_origin,netOrig)

        new 
l
        
for(l=0;l<3;l++)
        
netOrig2[l] = floatround(netOrig[l])
        
flameWave(netOrig2)
        
get_user_name(ballowner,aname,63)
        new 
frags get_user_frags(ballowner)
        
entity_set_float(ballownerEV_FL_fragsfloat(frags 10))

        
play_wav(0SoundDirect[16])

        new 
assisters[4] = { 000}
        new 
iassisters 0
        
new ilastplayer iassistteam ]

        if ( 
ilastplayer == )
            
ilastplayer 15
        
else
            
ilastplayer--

        if ( 
assistilastplayer ] != 
        {
            new 
ixbool:canaddplayerid
            
for(i=0i<16i++) 
            {
                
// Stop if we've already found 4 assisters
                
if ( iassisters == MAX_ASSISTERS )
                    break
                
playerid assist]
                
// Skip if player is invalid
                
if ( playerid == )
                    continue
                
// Skip if kicker is counted as an assister
                
if ( playerid == assistilastplayer ] )
                    continue

                
canadd true
                
// Loop through each assister value
                
for(x=0x<3x++)
                    
// make sure we can add them
                    
if ( playerid == assisters] ) 
                    {
                        
canadd false
                        
break
                    }

                
// Skip if they've already been added
                
if ( canadd == false )
                    continue
                
// They didn't kick the ball last, and they haven't been added, add them
                
assistersiassisters++ ] = playerid
            
}
            
// This gives each person an assist, xp, and prints that out to them
            
new cpass
            
for(c=0c<iassistersc++) 
            {
                
pass assisters[c]
                
Event_Record(passASSIST, -1ConfigPro[3])
                
client_print(passprint_chat"[SJ] You won %i exp for the assist"ConfigPro[3])
                
                
///////////////////////////////////////////////
                    
                
if(sj_systemrank == && get_pcvar_num(CVAR_RANK))
                {
                    if(
UserPassword[pass])
                        
Pro_Asis[pass] += 1    
                    
if(VerificarPossUP(pass))
                        
log_amx("7 Rank ok")
                }
                    
                
///////////////////////////////////////////////                
                            
            
}
        }
        
iassist] = 0
        
/////////////////////ASSIST CODE HERE///////////

        
for(l=0l<3l++)
            
distorig[1][l] = floatround(netOrig[l])
        new 
distshot = (get_distance(distorig[0],distorig[1])/12)
        new 
gainedxp distshot ConfigPro[4]

        
format(temp1,63,"%s [%s] Scored a goal from %i feet!!",TeamNames[team],aname,distshot)

        if(
distshot MadeRecord[ballowner][DISTANCE])
            
Event_Record(ballownerDISTANCEdistshot0)// record distance, and make that distance exp

        
Event_Record(ballownerGOAL, -1gainedxp)    //zero xp for goal cause distance is what gives it.
        
        ///////////////////////////////////////////////
        
if(sj_systemrank == && get_pcvar_num(CVAR_RANK))        
        {
            if(
UserPassword[ballowner])
                
Pro_Goal[ballowner] += 1
            
if(VerificarPossUP(ballowner))
                
log_amx("8 Rank ok")
        }
        
///////////////////////////////////////////////        

        //Increase Score, and update cvar score
        
score[team]++
        switch(
team
        {
            case 
1set_cvar_num("score_ct",score[team])
            case 
2set_cvar_num("score_t",score[team])
        }
        
        
server_cmd("setear_score %d %d"score[1], score[2])
        
client_print(ballownerprint_chat"[SJ] You won %i exp for scoring a goal from %i feet"gainedxp,distshot)
        
Gol_Sprite(ballowner)

        new 
oteam = (team == 1)
        
increaseTeamXP(team75)
        
increaseTeamXP(oteam50)
        
moveBall(0)

        new 
x
        
for(x=1x<=maxplayersx++) {
            if(
is_user_connected(x))
            {
                
Event_Record(xGOALYGoalyPoints[x], 0)
                new 
kills get_user_frags(x)
                new 
deaths cs_get_user_deaths(x)
                
setScoreInfo(x)
                if( 
deaths 0)
                    
PlayerDeaths[x] = deaths
                
if( kills 0)
                    
PlayerKills[x] = kills
            
}
        }


        if(
score[team] < get_pcvar_num(CVAR_SCORE)) {
            new 
random_num(0,5)
            
play_wav(0SoundDirect[r]);        
        
        }
        else 
        {
            
winner team
            format
(scoreboard,1024,"-+- TEAM %s -+-^nWON!!!",TeamNames[team])
            
set_task(1.0,"showhud_winner",0,"",0,"a",3)
            
play_wav(0SoundDirect[20])
        
            
ActiveJoinTeam 0
        
            sj_systemrank 
0
            BorrarSistemExp
()
        }
        
server_cmd("sv_restart 4")
        

    } 
JuanitoAlimana is offline
Fuck For Fun
Veteran Member
Join Date: Nov 2013
Old 05-19-2023 , 06:14   Re: Run time error 4: index out of bounds
Reply With Quote #4

I see that the issue lies in the line new team = get_user_team(ballowner). It appears that the variable ballowner is not defined or set before this line, which leads to the "index out of bounds" error in the touchNet function.
Fuck For Fun is offline
Send a message via Skype™ to Fuck For Fun
lexzor
Veteran Member
Join Date: Nov 2020
Old 05-19-2023 , 07:44   Re: Run time error 4: index out of bounds
Reply With Quote #5

here is the problem

PHP Code:
new team get_user_team(ballowner)
    new 
golent GoalEnt[team
get_user_team return 1 for TERO and 2 for CT, if ballowner is not a valid client index, the team native will return -1 (https://www.amxmodx.org/api/amxmodx/get_user_team)

so
PHP Code:
GoalEnt[team
will return an index out of bounds error.

i don't see where ballowner is defined or where it's value is changed.

post full code

Last edited by lexzor; 05-19-2023 at 07:45.
lexzor is offline
JuanitoAlimana
Senior Member
Join Date: Aug 2021
Old 05-19-2023 , 22:43   Re: Run time error 4: index out of bounds
Reply With Quote #6

Sj-Pro.sma
JuanitoAlimana is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-20-2023 , 19:23   Re: Run time error 4: index out of bounds
Reply With Quote #7

I suspect that there is a more fundamental flaw in the code because that entire function is dependent on the "ball owner" being valid. You say it happens "every time" but is that literally true? I could see this happen if the last person to touch the ball disconnects before the goal is scored but I find it unlikely that that would happen "every time".

I have attached a version that adds logs to when the variable is set to zero to try and find out why it's being set to zero before a goal is scored.

_______________________

With respect to calling out the line in a code snippet, you can put your code in [PAWN][/PAWN] with "@@" on the line that you want to call out. So, this:


[PAWN]
public touchNet(ball, goalpost)
{
remove_task(55555)

new team = get_user_team(ballowner)
@@ new golent = GoalEnt[team]
[/PAWN]


turns into this:

Code:
public touchNet(ball, goalpost) {     remove_task(55555)     new team = get_user_team(ballowner)
    new golent = GoalEnt[team]

Or, if you use the PHP code box, simply add a syntax-valid comment:

PHP Code:
public touchNet(ballgoalpost)
{
    
remove_task(55555)

    new 
team get_user_team(ballowner)
    new 
golent GoalEnt[team// Line 1891 
Attached Files
File Type: sma Get Plugin or Get Source (Sj-Pro-debug.sma - 109 views - 200.9 KB)
__________________

Last edited by fysiks; 05-21-2023 at 19:41.
fysiks is offline
JuanitoAlimana
Senior Member
Join Date: Aug 2021
Old 05-20-2023 , 19:54   Re: Run time error 4: index out of bounds
Reply With Quote #8

Thank you very much, I will post in that way from now on!

I will try the plugin and I will come back with any news.
JuanitoAlimana is offline
JuanitoAlimana
Senior Member
Join Date: Aug 2021
Old 05-21-2023 , 05:45   Re: Run time error 4: index out of bounds
Reply With Quote #9

Plugin works fine, no index out of bounds error.
Server console shows these 3 messages several times in a random order:
L 05/21/2023 - 05:26:00: [Sj-Pro-debug.amxx] ballowner set to zero in touchPlayer()
L 05/21/2023 - 05:26:07: [Sj-Pro-debug.amxx] ballowner set to zero in moveBall()
L 05/21/2023 - 05:429: [Sj-Pro-debug.amxx] ballowner set to zero in client_disconnected()
JuanitoAlimana is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 05-21-2023 , 12:30   Re: Run time error 4: index out of bounds
Reply With Quote #10

Your problem is here

GoalEnt[team]

In the variable team since the ball touch function is called depending on the player fps, its high likely to get an invalid team at some time to fix the problem simply add a check

PHP Code:

new golentteam;

if(
ballowner 0team get_user_team(ballowner);
if(
team >= && team sizeof GoalEntgolent GoalEnt[team]; 
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 05-21-2023 at 12:31.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Reply


Thread Tools
Display Modes

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 05:22.


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