AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Zombi Class problem(index out of bounds) (https://forums.alliedmods.net/showthread.php?t=252136)

Krtola 11-26-2014 15:01

Zombi Class problem(index out of bounds)
 
I use this class but give me this error:

Run time error 4: index out of bounds
Event_Damage (line 66)

PHP Code:

#include < amxmodx >
#include < fakemeta >
#include < biohazard >
#include < engine >
#include < hamsandwich >

#define D_ZOMBIE_NAME "Paralyzer class"
#define D_ZOMBIE_DESC "auto-paralyze and 2x jumps"
#define D_PLAYER_MODEL "paralizer_bio"
#define D_CLAWS "models/v_paralizer_bio.mdl"
#define PMODEL "models/player/paralizer_bio/paralizer_bio.mdl"

new zClassIdDisarmTimeDisarmChanceScreenFadeEffectsSpR_Paralyzed
new boolCantFire33 ] = false;

new 
_gJumpCount[33]
new 
cvar_multi_jump_amount

public plugin_init() 
{
    
register_plugin("ZP CLASS : Paralizer Zombie""1.1""BboY GruN")
    
    
register_event("Damage""Event_Damage""b""2!0""3=0""4!0")

        
RegisterHam(Ham_Player_Jump"player""fw_PlayerJump"0)
    
    
DisarmChance register_cvar("chance_to_disarm""4" )
    
    
DisarmTime register_cvar("disarm_Time""3.0" // How much time the Human will stay disarm

        
cvar_multi_jump_amount register_cvar("zp_multi_jump_amount""1")
    
    
ScreenFadeEffects =     get_user_msgid"ScreenFade" )

        
zClassId register_class(D_ZOMBIE_NAMED_ZOMBIE_DESC)
 
        if(
zClassId != -1)
        {
                
set_class_data(zClassIdDATA_HEALTH370.0)
                
set_class_data(zClassIdDATA_SPEED266.0)
                
set_class_data(zClassIdDATA_GRAVITY0.75)
                
set_class_data(zClassIdDATA_HITSPEED0.69)
                
set_class_pmodel(zClassIdD_PLAYER_MODEL)
                
set_class_wmodel(zClassIdD_CLAWS)
                }
}

public 
plugin_precache( )
{
    
SpR_Paralyzed precache_model"sprites/paralyzed.spr" )
        
precache_model(PMODEL)
    
precache_model(D_CLAWS)
}

public 
Event_Damagevictim )
{
    new 
id
    id 
get_user_attackervictim )
    if( 
get_user_classvictim ) != zClassId 
    
|| !is_user_zombievictim ) )
        return 
PLUGIN_CONTINUE;
    
    new 
Rand random_num1100 )
    if( 
Rand && Rand <= get_pcvar_numDisarmChance ) ) 
    {
        
CantFireid ] = true
        Effects
id )
        
set_taskget_pcvar_floatDisarmTime ), "StopDisarmCc"id )
    }
    
    return 
PLUGIN_CONTINUE;
}

public 
client_PreThinkPlayer )
{    
    if( !
CantFirePlayer ] )
        return 
PLUGIN_CONTINUE;
    
entity_set_intPlayerEV_INT_buttonentity_get_intPlayerEV_INT_button ) & ~IN_ATTACK // Player will scared :D
    
return PLUGIN_CONTINUE;
}

public 
Effectsid )
{
    
message_beginMSG_ONE_UNRELIABLEScreenFadeEffects,.player id )
    
write_short( ( 1<<10 ) )
    
write_short)
    
write_short0x0000 )
    
write_byte255 // Red color 
    
write_byte// G
    
write_byte// B
    
write_byte255 )
    
message_end( )
    
    new 
FloatHumanOrigin]
    
entity_get_vectoridEV_VEC_originHumanOrigin )
    
engfuncEngFunc_MessageBeginMSG_PVSSVC_TEMPENTITYHumanOrigin0)
    
write_byteTE_SPRITETRAIL )    
    
engfuncEngFunc_WriteCoordHumanOrigin] )
    
engfuncEngFunc_WriteCoordHumanOrigin] )
    
engfuncEngFunc_WriteCoordHumanOrigin] )
    
engfuncEngFunc_WriteCoordHumanOrigin] )
    
engfuncEngFunc_WriteCoordHumanOrigin] )
    
engfuncEngFunc_WriteCoordHumanOrigin] + 30 )
    
write_shortSpR_Paralyzed 
    
write_byte
    
write_byte30 )
    
write_byte10 
    
write_byte45 )
    
write_byte40 )
    
message_end( )
}

public 
StopDisarmCcid )
{
    
CantFireid ] = false
}

public 
fw_PlayerJump(id
{
        if(!
is_user_alive(id) || !is_user_zombie(id))
    {
        return 
HAM_SUPERCEDE
    
}

    if(
is_user_alive(id) && get_user_class(id) == zClassId
    {
        new 
Flags pev(idpev_flags)
        
        if( 
Flags FL_WATERJUMP || pev(idpev_waterlevel) >= || !(get_pdata_int(id246) & IN_JUMP) )
        {
            return 
HAM_IGNORED
        
}
        if(
Flags FL_ONGROUND
        {
            
_gJumpCount[id] = 0
            
            
return HAM_IGNORED
        
}
        if(
get_pcvar_num(cvar_multi_jump_amount)) 
        {
            if( 
get_pdata_float(id251) < 500 && ++_gJumpCount[id] <= get_pcvar_num(cvar_multi_jump_amount)) 
            {
                new 
Float:fVelocity[3]
                
pev(idpev_velocityfVelocity)
                
fVelocity[2] = 268.328157
                set_pev
(idpev_velocityfVelocity)
                
                return 
HAM_HANDLED
            
}
        }
    }
    return 
HAM_IGNORED


Problem is there:
PHP Code:

public Event_Damagevictim )
{
    new 
id
    id 
get_user_attackervictim )
    if( 
get_user_classvictim ) != zClassId 
    
|| !is_user_zombievictim ) )
        return 
PLUGIN_CONTINUE;
    
    new 
Rand random_num1100 )
    if( 
Rand && Rand <= get_pcvar_numDisarmChance ) ) 
    {
        
CantFireid ] = true
        Effects
id )
        
set_taskget_pcvar_floatDisarmTime ), "StopDisarmCc"id )
    }
    
    return 
PLUGIN_CONTINUE;


and line 66 is
PHP Code:

CantFireid ] = true 

Can someone help me to solve this?

RateX 11-26-2014 16:14

Re: Zombi Class problem(index out of bounds)
 
Either check is_user_connected or 1<=id<=maxplayer

Krtola 11-26-2014 19:29

Re: Zombi Class problem(index out of bounds)
 
Something like this? ( do not know how to do it 1<=id<=maxplayer )

PHP Code:

public Event_Damagevictim )
{
    new 
id
    id 
get_user_attackervictim )
    if( 
get_user_classvictim ) != zClassId 
    
|| !is_user_zombievictim ) )
        return 
PLUGIN_CONTINUE;
    
    new 
Rand random_num1100 )
    if( 
Rand && Rand <= get_pcvar_numDisarmChance ) && is_user_connected(id) ) 
    {
        
CantFireid ] = true
        Effects
id )
        
set_taskget_pcvar_floatDisarmTime ), "StopDisarmCc"id )
    }
    
    return 
PLUGIN_CONTINUE;



RateX 11-26-2014 22:40

Re: Zombi Class problem(index out of bounds)
 
Yes, like that, though I prefer doing the check as soon as id is assigned to a value, so the plugin doesn't have to do unnecessary calculation, like:
PHP Code:

id get_user_attacker(victim)
if(
get_user_class(victim) != zClassId 
    
|| !is_user_zombie(victim
    || !
is_user_connected(id))
        return 
PLUGIN_CONTINUE 

And for the other method, here's how:
PHP Code:

g_maxplayer get_maxplayers()
if(!(
1<=id<=g_maxplayer))
        return 
PLUGIN_CONTINUE 


Krtola 11-27-2014 04:12

Re: Zombi Class problem(index out of bounds)
 
Ok,what I did:

PHP Code:

public Event_Damagevictim )
{
    new 
id
    id 
get_user_attackervictim )
    if( 
get_user_classvictim ) != zClassId 
    
|| !is_user_zombievictim 
        || !
is_user_connectedid ) )
        return 
PLUGIN_CONTINUE;

        if(!(
1<=id<=g_maxplayer))
        return 
PLUGIN_CONTINUE
    
    
new Rand random_num1100 )
    if( 
Rand && Rand <= get_pcvar_numDisarmChance ) ) 
    {
        
CantFireid ] = true
        Effects
id )
        
set_taskget_pcvar_floatDisarmTime ), "StopDisarmCc"id )
    }
    
    return 
PLUGIN_CONTINUE;


Do I need to write here in -public Event_Damage-?
PHP Code:

if(!(1<=id<=g_maxplayer))
        return 
PLUGIN_CONTINUE 


RateX 11-27-2014 04:24

Re: Zombi Class problem(index out of bounds)
 
Nope, as I said you can choose any of them, and having both is just a waste of resource.

Krtola 11-27-2014 04:39

Re: Zombi Class problem(index out of bounds)
 
Quote:

Originally Posted by RateX (Post 2228717)
Nope, as I said you can choose any of them, and having both is just a waste of resource.

Ok,I get it now.
Thank you ;)


All times are GMT -4. The time now is 17:32.

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