AlliedModders

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

Mini_Midget 02-11-2007 23:43

Run time error 4: index out of bounds
 
Giving me a run time error
Code:

L 02/06/2007 - 02:13:02: [AMXX] Displaying debug trace (plugin "zombie_swarm.amxx")
L 02/06/2007 - 02:13:02: [AMXX] Run time error 4: index out of bounds
L 02/06/2007 - 02:13:02: [AMXX]    [0] zombie_swarm.sma::event_damage_camera (line 356)
L 02/06/2007 - 02:13:02: [AMXX] Displaying debug trace (plugin "zombie_swarm.amxx")
L 02/06/2007 - 02:13:02: [AMXX] Run time error 4: index out of bounds
L 02/06/2007 - 02:13:02: [AMXX]    [0] zombie_swarm.sma::event_damage_lifesteal (line 386)

PHP Code:

public event_damage_camera(id)
{
    if (!
is_user_alive(id) || !is_user_connected(id)) 
        return 
PLUGIN_CONTINUE
    
    
new damage read_data(2)
    new 
AttakerWeaponAttakerPartHit
    
new attacker get_user_attacker(idAttakerWeaponAttakerPartHit)
    
    if( 
g_zombie[attacker] ) //<--- This line
    
{
        if(
AttakerWeapon == CSW_KNIFE && damage >= 55)    
        {
            new 
Float:Random_Float[3]
            for(new 
03i++) Random_Float[i] = random_float(100.0125.0)
            
Punch_View(idRandom_Float)
        }
    }    
    return 
PLUGIN_CONTINUE
}

stock Punch_View(idFloat:ViewAngle[3])
{
    
entity_set_vector(idEV_VEC_punchangleViewAngle)
}

public 
event_damage_lifesteal(id) {
    
    new 
damage read_data(2)
    new 
attacker get_user_attacker(id)
    
    if ( ! 
is_user_alive(id) || ! is_user_connected(id) )
        return 
PLUGIN_CONTINUE
    
    
new current_hp get_user_health(attacker)
    new 
max_hp get_pcvar_num(zomb_hp)
    
    
current_hp += damage
    
    
if ( g_zombie[attacker] ) { //<--- This line
        
if ( current_hp >= max_hp )
            
set_user_health(attackermax_hp)
        else
            
set_user_health(attackercurrent_hp)
    }
    return 
PLUGIN_CONTINUE



Also, is it possible to only use one function for the both of these things to make it a bit cleaner?

jim_yang 02-11-2007 23:49

Re: Run time error 4: index out of bounds
 
you should check the index of the attacker which get_user_attacker returned.
because if an entity attack the user, also trigger the damage event, and the entity's index may out of your array's bounds

Mini_Midget 02-12-2007 00:54

Re: Run time error 4: index out of bounds
 
I have checked it but its in the plugin_init
PHP Code:

    register_event("Damage""event_damage_camera""be""2!0","3=0","4!0")
    
register_event("Damage""event_damage_lifesteal""be""2!0","3=0","4!0"


jim_yang 02-12-2007 01:04

Re: Run time error 4: index out of bounds
 
that can't handle all the situation.

Mini_Midget 02-12-2007 01:13

Re: Run time error 4: index out of bounds
 
oh..
Then how do I check the index (attacker) if its an entity or not not via plugin_init?

jim_yang 02-12-2007 01:16

Re: Run time error 4: index out of bounds
 
if (attacker > sizeof g_zombie) return

i wonder what is your g_zombie like


All times are GMT -4. The time now is 00:36.

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