AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Array index is out of bounds (https://forums.alliedmods.net/showthread.php?t=256061)

Dkmuniz 01-23-2015 18:49

Array index is out of bounds
 
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 ?

GooseMonkey 01-23-2015 19:02

Re: Array index is out of bounds
 
Which line is 1292?

11530 01-23-2015 20:42

Re: Array index is out of bounds
 
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.

nergal 01-23-2015 21:10

Re: Array index is out of bounds
 
do victim-1 on hurts unless hurts is MAXPLAYERS+1

If that's the case, idk

Potato Uno 01-23-2015 21:28

Re: Array index is out of bounds
 
Quote:

Originally Posted by 11530 (Post 2253014)
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.

ddhoward 01-23-2015 21:34

Re: Array index is out of bounds
 
Quote:

Originally Posted by Potato Uno (Post 2253024)
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.

Dkmuniz 01-23-2015 21:36

Re: Array index is out of bounds
 
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



Potato Uno 01-23-2015 21:51

Re: Array index is out of bounds
 
Quote:

Originally Posted by ddhoward (Post 2253026)
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

ddhoward 01-23-2015 22:07

Re: Array index is out of bounds
 
Quote:

Originally Posted by Potato Uno (Post 2253034)
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.

11530 01-24-2015 07:40

Re: Array index is out of bounds
 
@Dkmuniz Please also post your declarations for the global hurts[] and vampiro[]


All times are GMT -4. The time now is 12:52.

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