Raised This Month: $51 Target: $400
 12% 

Array index is out of bounds


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Dkmuniz
Senior Member
Join Date: Jun 2013
Old 01-23-2015 , 18:49   Array index is out of bounds
Reply With Quote #1

Hi my plugin give this log error :
Code:
L 01/23/2015 - 21:21:18: [SM] Plugin encountered error 15: Array index is out of bounds
L 01/23/2015 - 21:21:18: [SM] Displaying call stack trace for plugin "zbrincar_admin.smx":
L 01/23/2015 - 21:21:18: [SM]   [0]  Line 1292, zbrincar_admin.sp::OnTakeDamage()
My take damage:

PHP Code:
public Action:OnTakeDamage(victim, &attacker, &inflictor, &Float:damage, &damagetype)
{
    if(
bBox == true)
    {
        if(
IsValidClient(attacker) && IsValidClient(victimtrue))
        {
            if(
attacker != victim && GetClientTeam(attacker) == && GetClientTeam(victim) == 3)
            {
                
damage 0.0;
                
                return 
Plugin_Changed;
            }
            else if(
attacker != victim && GetClientTeam(attacker) == && GetClientTeam(victim) == 3)
            {
                
damage 0.0;
                
                return 
Plugin_Changed;
            }
            else if(
attacker != victim && GetClientTeam(attacker) == && GetClientTeam(victim) == 2)
            {
                
damage 0.0;
                
                return 
Plugin_Changed;
            }
        }
    }
    
    else if(
bBoxDesarmado == true)
    {
        if(
IsValidClient(attacker) && IsValidClient(victimtrue))
        {
            if(
attacker != victim && GetClientTeam(attacker) == && GetClientTeam(victim) == 3)
            {
                
damage 0.0;
                
                return 
Plugin_Changed;
            }
            else if(
attacker != victim && GetClientTeam(attacker) == && GetClientTeam(victim) == 3)
            {
                
damage 0.0;
                
                return 
Plugin_Changed;
            }
            else if(
attacker != victim && GetClientTeam(attacker) == && GetClientTeam(victim) == 2)
            {
                
damage 0.0;
                
                return 
Plugin_Changed;
            }
        }
    }
    
    else if(
bTubarao == true)
    {
        new 
MoveType:movetype GetEntityMoveType(victim); 
        if (
movetype == MOVETYPE_NOCLIP)
        {
            
hurts[victim]++;
            if(
hurts[victim] >= HURTSDEAD)
            
ForcePlayerSuicide(victim);
            
//SDKHooks_TakeDamage(victim, inflictor, attacker, damage, damagetype, weapon, damageForce, damagePosition);
        
}
    }
    
    else if(
vampiro[attacker])
    {
        new 
receber RoundToFloor(damage 0.5);
        
receber += GetClientHealth(attacker);
        
SetEntityHealth(attackerreceber);
    }
    
    return 
Plugin_Changed;

Help please ?
Dkmuniz is offline
GooseMonkey
Junior Member
Join Date: Aug 2013
Old 01-23-2015 , 19:02   Re: Array index is out of bounds
Reply With Quote #2

Which line is 1292?
GooseMonkey is offline
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 01-23-2015 , 20:42   Re: Array index is out of bounds
Reply With Quote #3

Assuming it is what I think it is, this is why I dislike IsValidClient stocks...

e.g. Their IsValidClient requires that attacker and victim be <= MaxClients so that hurts[victim] or vampiro[attacker] doesn't error later.
__________________

Last edited by 11530; 01-23-2015 at 20:45.
11530 is offline
nergal
Veteran Member
Join Date: Apr 2012
Old 01-23-2015 , 21:10   Re: Array index is out of bounds
Reply With Quote #4

do victim-1 on hurts unless hurts is MAXPLAYERS+1

If that's the case, idk
__________________
nergal is offline
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 01-23-2015 , 21:28   Re: Array index is out of bounds
Reply With Quote #5

Quote:
Originally Posted by 11530 View Post
Assuming it is what I think it is, this is why I dislike IsValidClient stocks...

e.g. Their IsValidClient requires that attacker and victim be <= MaxClients so that hurts[victim] or vampiro[attacker] doesn't error later.
I would rather prefer that it be a native function instead, since it's so commonly used.

That, or at least allow try/catch statements in sourcepawn (which Voided said on a thread of mine that it's pending to come in a future sourcepawn version).

Invalid client exceptions are one of the biggest pains in the ass with sourcemod that are annoying to circumvent.
Potato Uno is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 01-23-2015 , 21:34   Re: Array index is out of bounds
Reply With Quote #6

Quote:
Originally Posted by Potato Uno View Post
I would rather prefer that it be a native function instead, since it's so commonly used.
What constitutes a "valid client" differs depending on the plugin, the function, etc.

I made this stock for use in all my plugins a while ago, but even this will have places where something more specific is needed.
__________________
ddhoward is offline
Dkmuniz
Senior Member
Join Date: Jun 2013
Old 01-23-2015 , 21:36   Re: Array index is out of bounds
Reply With Quote #7

Use this stock:
PHP Code:
stock bool:IsValidClient(clientbool:alive false)
{
    if(
client >= && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client) && (alive == false || IsPlayerAlive(client)))
    {
        return 
true;
    }
    
    return 
false;

For fix it is ? Without IsValidClient

PHP Code:
public Action:OnTakeDamage(victim, &attacker, &inflictor, &Float:damage, &damagetype

    if(
bBox == true
    { 
        if(
attacker != victim && GetClientTeam(attacker) == && GetClientTeam(victim) == 3
        { 
            
damage 0.0
             
            return 
Plugin_Changed
        } 
        else if(
attacker != victim && GetClientTeam(attacker) == && GetClientTeam(victim) == 3
        { 
            
damage 0.0
             
            return 
Plugin_Changed
        } 
        else if(
attacker != victim && GetClientTeam(attacker) == && GetClientTeam(victim) == 2
        { 
            
damage 0.0
             
            return 
Plugin_Changed
        }
    } 
     
    else if(
bBoxDesarmado == true
    { 
            if(
attacker != victim && GetClientTeam(attacker) == && GetClientTeam(victim) == 3
            { 
                
damage 0.0
                 
                return 
Plugin_Changed
            } 
            else if(
attacker != victim && GetClientTeam(attacker) == && GetClientTeam(victim) == 3
            { 
                
damage 0.0
                 
                return 
Plugin_Changed
            } 
            else if(
attacker != victim && GetClientTeam(attacker) == && GetClientTeam(victim) == 2
            { 
                
damage 0.0
                 
                return 
Plugin_Changed
            } 
    } 
     
    else if(
bTubarao == true
    { 
        new 
MoveType:movetype GetEntityMoveType(victim);  
        if (
movetype == MOVETYPE_NOCLIP
        { 
            
hurts[victim]++; 
            if(
hurts[victim] >= HURTSDEAD
            
ForcePlayerSuicide(victim); 
            
//SDKHooks_TakeDamage(victim, inflictor, attacker, damage, damagetype, weapon, damageForce, damagePosition); 
        

    } 
     
    else if(
vampiro[attacker]) 
    { 
        new 
receber RoundToFloor(damage 0.5); 
        
receber += GetClientHealth(attacker); 
        
SetEntityHealth(attackerreceber); 
    } 
     
    return 
Plugin_Changed


Last edited by Dkmuniz; 01-23-2015 at 21:36.
Dkmuniz is offline
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 01-23-2015 , 21:51   Re: Array index is out of bounds
Reply With Quote #8

Quote:
Originally Posted by ddhoward View Post
What constitutes a "valid client" differs depending on the plugin, the function, etc.

I made this stock for use in all my plugins a while ago, but even this will have places where something more specific is needed.
A native that makes sure that the "client [BLAH] is not valid" exception (returns true if the exception isn't thrown, false otherwise) isn't thrown doesn't sound like it would "differ" from plugin to plugin. I don't think any plugin would want exceptions in their code.

But again, try/catch statements would also solve the problem if they existed in the first place.

/irrelevant derailing that doesn't help the OP

Last edited by Potato Uno; 01-23-2015 at 21:52.
Potato Uno is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 01-23-2015 , 22:07   Re: Array index is out of bounds
Reply With Quote #9

Quote:
Originally Posted by Potato Uno View Post
doesn't sound like it would "differ" from plugin to plugin
Define "valid client" in a way that would always and constantly be accurate no matter what plugin is being created.

Some plugins require that the player be alive to be considered "valid" for a given operation. Others require only that the index pass an IsClientInGame check. Others require that the player be spectating. Etc.
__________________
ddhoward is offline
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 01-24-2015 , 07:40   Re: Array index is out of bounds
Reply With Quote #10

@Dkmuniz Please also post your declarations for the global hurts[] and vampiro[]
__________________
11530 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:25.


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