Raised This Month: $ Target: $400
 0% 

Another IOB (index out of bounds)


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
FLR
Junior Member
Join Date: Jun 2008
Old 07-23-2008 , 13:36   Another IOB (index out of bounds)
Reply With Quote #1

Hello.
I recently added some new things to my plugin.
But after I compiled it and was going to test if the new things worked, I got a weird index out of bounds. Ive been trying to find this problems for hours now.

Still can't figure out whats wrong.
I didnt even change the player_rewards[][], and now it gives me an IOB.
The error is, where debug says, on line 319 in the FM_touch, its the
"if(equali(classname,classnames[i]) && player_rewards[i][id])"

Please, if you do find the problem, would you please describe why?
Thanks in advance.

PHP Code:

#define VERSION    "0.9b02"
#define DELAYID    21543
#define MKSID     45625

#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <fun>
#include <fakemeta>
#include <fakemeta_util>
#include <engine>

#define NUM_PUPS    5
#define MAX_PUPS    50 // the maximum number of powerups allowed on a map
#define NUM_MDLS    5 

#pragma semicolon 1;


new const models[NUM_MDLS][33] = //To add more models edit the NUM_MDLS!
{
    
"models/hns_powerup_teleport.mdl",
    
"models/hns_powerup_gravity.mdl",
    
"models/hns_powerup_speed.mdl",
    
"models/hns_powerup_gainhp.mdl",
    
"models/hns_powerup_autoheal.mdl"
};

new const 
classnames[NUM_PUPS][33] = //To add more powerups edit the NUM_PUPS!
{
    
"FLR_HNSP_Teleport",
    
"FLR_HNSP_Gravity",
    
"FLR_HNSP_Speed",
    
"FLR_HNSP_GainHP",
    
"FLR_HNSP_Autoheal"    
};

new const 
powerupNames[NUM_PUPS][16] = 
{
    
"Teleport",
    
"Gravity",
    
"Speed",
    
""// this is empty becuase there is noting to countdown on the gainhp 
    
"Autoheal"
};



/* // for further developement, if i/you want to add some info to see which powerup your looking at etc.
new const pupinfo[NUM_PUPS][256] = 
{
    "Teleport Powerup: Blinks you where you aim.",
    "Gravity Powerup: Gives you lower gravity equal to 1/2 of the normal gravity.",
    "Speed Powerup: Gives you 320 maxspeed, RUN BITCH, RUN!",
    "Gain HP Powerup: Gives you +50 HP if your health isnt above 205, then you gain 255, cuz thats the limit.",
    "Autoheal Powerup: Gives you autoheal for 30 seconds."
    
};
*/
new const pupglow[NUM_PUPS][3] =
{
    {
200,     200,     255},
    {
30,     150,     150},
    {
0,     230,     25},
    {
255,     0,     0},
    {
120,     65,     65}
};


/* This is for the blink ability.  Credits to: scoutPractice,jtp10181 and BlueRaja */
// Ive now edited this blink code, so now im only using a small part of it. dunno if i can give creds for it now.

new bool:teleported[33]; // if user is teleported, set to true. disables teleporting until he picks up a new powerup
            // Affected functions: teleportToAim
new Float:blinkSpot[33][3];
new 
Float:origBlinkSpot[33][3];

/* ------------------------------------------------------------------------------ */

new szConfigfile[200];

new 
type[MAX_PUPS];
new 
ents[MAX_PUPS];
new 
eline[MAX_PUPS];
new 
count_pups;

new 
help_count 30// just for now, when its still a beta, the interval for showing the helpmsg

new plrHavePup[33]; // 1 if a player already have a powerup| Affected functions:FM_touch, handle_reward, remove_reward
new iCoolDown[33]; // the cooldown of picking up another powerup.

new player_rewards[NUM_PUPS][33]; // affected functions: Too many :P

new Float:origins[MAX_PUPS][3];

// Cvar variables
new iEnabled
new 
iLast;
new 
iOnlyOnePup
new 
iHealamount;
new 
iHealduration;
new 
iHpPerSec;

// End of cvar vars

new Float:fRespawn 10.0// edit this for longer or shorter respawn time for the powerups

public plugin_init()
{
    
register_plugin        ("HnS Powerup",VERSION,"FLR");

    
register_concmd        ("hnsp_create","cmd_create",ADMIN_KICK,"<type>");
    
register_concmd        ("hnsp_remove","cmd_remove",ADMIN_KICK,"Removes nearest Powerup spawn to you.");
    
register_concmd        ("hnsp_removeall","cmd_removeall",ADMIN_KICK,"Removes all the powerups on the map");

    
iLast =             register_cvar("hnsp_last","20");
    
iEnabled =         register_cvar("hnsp_enabled","1");
    
iOnlyOnePup =         register_cvar("hnsp_onlyonepup""1");
    
iHealamount =         register_cvar("hnsp_healamount""50");
    
iHealduration =         register_cvar("hnsp_healduration""15");
    
iHpPerSec =         register_cvar("hnsp_hpsec","2");
    
    
register_event        ("CurWeapon","CurWeapon","be");
    
register_logevent    ("new_round",2,    "1=Round_Start");
    
    
register_clcmd        ("hnsp_blink""teleportToAim");

    
register_forward    (FM_Touch"FM_touch");
    

    new 
szMap[32];
    
get_mapname(szMap,31);

    new 
szConfigsdir[200];
    
get_configsdir(szConfigsdir,199);

    
format(szConfigsdir,199,"%s/HnSP",szConfigsdir);
    
format(szConfigfile,199,"%s/%s.ini",szConfigsdir,szMap);
    
    if(!
dir_exists(szConfigsdir))
    { 
        
mkdir(szConfigsdir);
    }

    
load_powerups();

    
set_task(1.0,"ability_think",0,"",0,"b");
    
}

///////////////////////////////////////////////////////////////////////////
// Remove powerups
///////////////////////////////////////////////////////////////////////////

// cmd_remove is almost all from the GHW sma, but the cmd_removeall and cmd_checknremove is done by me.
public cmd_remove(id,level,cid)
{
    if(!
cmd_access(id,level,cid,1))
    {
        return 
PLUGIN_HANDLED;
    }

    new 
bool:removed false;
    
    new 
Float:vOrigin[3], classname[32];
    
    
pev(id,pev_origin,vOrigin);
    
    new 
ent engfunc(EngFunc_FindEntityInSphere,get_maxplayers(),vOrigin,100.0);
    
    while(
ent)
    {
        
pev(entpev_classnameclassname,31);
        
        for(new 
0NUM_PUPSi++)
        {
            if( 
equali(classnameclassnames[i]) )
            {
                for(new 
0count_pupsj++)
                {
                    if(
ent == ents[j])
                    {
                        if(
type[j] >= 0)
                        {
                            
client_print(idprint_chat,"[HNSP] HnS Powerup %s Removed."classname);
                        }
                        else
                        {
                            
client_print(idprint_chat,"[HNSP] HnS Powerup FLR_HNSP_Random Removed.");
                        }
                        
                        
type[j]  =  -2;
                        
                        
write_fileszConfigfile""eline[j] );
                        
                        break;
                    }
                }
                
                
engfunc(EngFunc_RemoveEntity,ent);
                
                
removed true;
                
                break;
            }
        }
        
        
ent  =  engfunc(EngFunc_FindEntityInSphereentvOrigin100.0);
    }

    if(!
removed)
    {
        
client_print(idprint_chat,"[HNSP] No Powerup found near you.");
    }

    return 
PLUGIN_HANDLED;
}


public 
cmd_removeall(id,level,cid)
{
    
//make sure player has access to this command
    
if (cmd_access(id,level,cid,1))
    {
        for(new 
0count_pupsf++)
        {
            
cmd_checknRemove(f);
        }
        
        new 
szName[32];
        
get_user_name(idszName32);
        
        
client_print(0print_chat"[HNSP] (%s) deleted all the powerups from the map. Total powerups: %d"szNamecount_pups);
    }
}

cmd_checknRemove(f)
{
    new 
ent;
    
ent find_ent_by_class(-1,classnames[type[f]]);
    
    if(
pev_valid(ent))
    {
        
remove_entity(ent);
        
write_fileszConfigfile""eline[f] );
    }
    
}
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////
// Pick up a powerup
///////////////////////////////////////////////////////////////////////////
public FM_touch(id,ent)
{
    static 
classname[32];
    
    
pev(ent,pev_classname,classname,31);
    
    for(new 
i=0;iNUM_PUPS;i++)
    {
        if(
equali(classname,classnames[i]) && player_rewards[i][id])
        {
            
entity_set_int(ent,EV_INT_solid,SOLID_NOT);
            
set_task(1.0"makeSolid",MKSID+ent""0""0);
            
        }
        else if(
equali(classname,classnames[i]) && !player_rewards[i][id])
        {
            if(
plrHavePup[id] && iOnlyOnePup && !equali(classnameclassnames[3]))
            {
                return;
            }
            
            
remove_entity(ent);
            
//engfunc(EngFunc_RemoveEntity,ent);
            
            
plrHavePup[id] = 1;
            
            
emit_sound(idCHAN_WEAPON"items/gunpickup1.wav"0.5ATTN_NORM0PITCH_NORM);
            
            
handle_reward(id,i);
                
            
set_task(fRespawn,"new_round",i+50);
        }        
    }
}

public 
makeSolid(ent)
{
    
ent -= MKSID;
    
    if(
pev_valid(ent))
    {
        
entity_set_int(ent,EV_INT_solid,SOLID_BBOX);
        
//set_pev(ent,pev_solid,SOLID_BBOX);
    
}
}

/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////
/* This is where the blink code begins */
//////////////////////////////////////////////////////////////////////
public teleportToAim(id)
{
    if(
player_rewards[0][id] && teleported[id]== false)
    {
        
fm_get_aim_origin(idblinkSpot[id]);
        
        
origBlinkSpot[id][0] = blinkSpot[id][0];
        
origBlinkSpot[id][1] = blinkSpot[id][1];
        
origBlinkSpot[id][2] = blinkSpot[id][2];

        
blinkSpot[id][0] += 30;
        
blinkSpot[id][1] += 30;
        
blinkSpot[id][2] += 65;
        
        
set_pev(id,pev_origin,blinkSpot[id]);
        
//engfunc(EngFunc_SetOrigin, id, blinkSpot[id]);

        
remove_reward(id,0);

    }
    
    return 
PLUGIN_CONTINUE;
}

//////////////////////////////////////////////////////////////////////
/* This is where the blink code ends */
//////////////////////////////////////////////////////////////////////

public CurWeapon(id)
{
    if(
player_rewards[2][id])
    {
        
set_pev(id,pev_maxspeed,320.0);
    }
    else if(
player_rewards[1][id])
    {
        
set_pev(id,pev_gravity,0.5);
    }
}

/////////////////////////////////////////////////////////////////////////////////
//Handles rewards
/////////////////////////////////////////////////////////////////////////////////
public remove_reward(id,type)
{
    
plrHavePup[id] = 0;
    
    switch(
type)
    {
        case 
0:
        {    
teleported[id] = true;
            
player_rewards[type][id] = 0;
            
client_print(id,print_chat,"[HNSP] You have been teleported, you cant do it again if you dont pick up another teleport powerup.");
        }
        case 
1:
        {
            
set_pev(id,pev_gravity,1.0);
            
client_print(id,print_chat,"[HNSP You no longer have Low gravity.");
        }
        case 
2:
        {
            
set_pev(id,pev_maxspeed,250.0);
            
client_print(id,print_chat,"[HNSP] You no longer have Superspeed.");
        }
        
        case 
4:
        {
            
client_print(id,print_chat,"[HNSP] You no longer have Autoheal.");
        }
    }
}

public 
handle_reward(id,type)
{    
    switch(
type)
    {
        case 
0:
        {    
player_rewards[type][id] = get_pcvar_num(iLast);
            
teleported[id] = false;
            
            
client_print(id,print_chat,"[HNSP] You have gained a blink powerup. Use your bind to teleport, but hurry, you only have blink for (%i seconds)!"player_rewards[type][id]);
            
        }
        case 
1:
        {
            
player_rewards[type][id] = get_pcvar_num(iLast);
            
            
client_print(id,print_chat,"[HNSP] You gained Lower Gravity! (%i seconds)",player_rewards[type][id]);
            
            
set_pev(id,pev_gravity,0.5);
        }
        case 
2:
        {
            
set_pev(id,pev_maxspeed,320.0);
            
            
player_rewards[type][id] = get_pcvar_num(iLast);
            
            
client_print(idprint_chat,"[HNSP] You just gained 320 movementspeed! (%i seconds)"player_rewards[type][id]);
            
        }
        case 
3:
        {
            
//new health = get_user_health(id);
            
new health pev(id,pev_health);
            new 
health_add get_pcvar_num(iHealamount);
            
            if(
health >= 205)
            {
                
health 255;
            }
            else 
            {
                
health += health_add;
            }

            
//set_user_health(id,health);
            
set_pev(id,pev_health,health+0.0);
            
            
client_print(id,print_chat,"[HNSP] You gained %f health!"health_add);
        }
        
        case 
4:
        {
            
player_rewards[type][id] = get_pcvar_num(iHealduration);
            
client_print(id,print_chat,"[HNSP] You just gained Auto-Heal! (%i seconds)",player_rewards[type][id]);
        }
    }
}
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////
//create powerups
/////////////////////////////////////////////////////////////////////////////////
public cmd_create(id,level,cid)
{
    if(!
cmd_access(id,level,cid,2))
    {
        return 
PLUGIN_HANDLED;
    }

    if(
count_pups>=MAX_PUPS)
    {
        
console_print(id,"[HNSP] %d Powerups exist. Only %d allowed. Could not create new one.",count_pups,MAX_PUPS);
        return 
PLUGIN_HANDLED;
    }

    new 
arg1[32];
    
read_argv(id,arg1,31);
    
    
    if(
equali(arg1,"teleport")) 
    {
        
type[count_pups] = 0;
    }
    else if(
equali(arg1,"gravity")) 
    {
        
type[count_pups] = 1;
    }
    else if(
equali(arg1,"speed")) 
    {
        
type[count_pups] = 2;
    }
    else if(
equali(arg1,"gainhp")) 
    {
        
type[count_pups] = 3;
    }
    else if(
equali(arg1,"autoheal")) 
    {
        
type[count_pups] = 4;
    }
    else
    {
        
console_print(id,"[HNSP] Invalid Powerup type");
        return 
PLUGIN_HANDLED;
    }

    
pev(id,pev_origin,origins[count_pups]);

    new 
string[200];
    
    
format(string,199,"%f %f %f %d",origins[count_pups][0],origins[count_pups][1],origins[count_pups][2],type[count_pups]);
    
    
write_file(szConfigfile,string);
    
    
eline[count_pups] = file_size(szConfigfile,1) - 2;

    
count_pups++;

    
console_print(id,"[HNSP] Powerup created at your location.");

    return 
PLUGIN_HANDLED;
}

/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
public new_round()
{
    for(new 
0sizeof(plrHavePup); e++) // just to be sure nobody have a powerup on new round
    
{
        
plrHavePup[e] = 0;
        
iCoolDown[e] = 0;
    }
    
    for(new 
i=0;i<count_pups ;i++)
    {
        if((!
ents[i] || !pev_valid(ents[i])) && !task_exists(i+50))
        {
            
spawn_pup(i+50);
        }
    }

}


public 
client_disconnect(id)
{
    while(
task_exists(id))
    {
        
remove_task(id);
    }
    
    for(new 
0;NUM_PUPSi++) 
    {
        
player_rewards[i][id] = 0;
    }
}

public 
plugin_precache()
{
    
precache_sound("items/gunpickup1.wav");
    
    for(new 
i=0;NUM_PUPS;i++)
    {
        
precache_model(models[i]);
    }
}

/////////////////////////////////////////////////////////////////////////////////
//Spawn pups on new round && load origins on mapload
/////////////////////////////////////////////////////////////////////////////////
public spawn_pup(num)
{
    new 
Float:Color[3];
    
    
num -= 50;
    
    if(
get_pcvar_num(iEnabled) && type[num] != -)
    {
        
ents[num] = engfunc(EngFunc_CreateNamedEntity,engfunc(EngFunc_AllocString,"info_target"));

        if(
type[num]!=-1)
        {
            
set_pev(ents[num],pev_classname,classnames[type[num]]);
            
//engfunc(EngFunc_SetModel,ents[num],models[type[0]]);
            
engfunc(EngFunc_SetModel,ents[num],models[type[num]]);
        }
        
/* // this is from the original GHW version, this is not to any use in this one, if you dont make it useful:)
        else
        {
            new num2 = random_num(0,NUM_PUPS-1);
            set_pev(ents[num],pev_classname,classnames[num2]);
            //engfunc(EngFunc_SetModel,ents[num],models[num2]);
            engfunc(EngFunc_SetModel,ents[num],models[0]);
        }
        */
        
        
if(type[num] !=-1)
        {
            
Color[0] = float(pupglow[type[num]][0]);
            
Color[1] = float(pupglow[type[num]][1]);
            
Color[2] = float(pupglow[type[num]][2]);
        }
        
        
dllfunc(DLLFunc_Spawnents[num]);
        
        
entity_set_int(ents[num], EV_INT_renderfxkRenderFxGlowShell);
        
entity_set_float(ents[num], EV_FL_renderamt200.0);
        
entity_set_int(ents[num], EV_INT_rendermodekRenderTransAlpha);

        
entity_set_vector(ents[num], EV_VEC_rendercolor,Color);
        
        
////////////////Engine/////////////////
        
new Float:MaxBox[3] = {1.0,1.0,1.0} ;
        
//new Float:MinBox[3] = {-4.0,-4.0,-4.0}        
        //entity_set_vector(ents[num], EV_VEC_mins, MinBox);
        
entity_set_vector(ents[num], EV_VEC_maxsMaxBox);
    
        
entity_set_origin(ents[num],origins[num]);
        
entity_set_int(ents[num], EV_INT_effects32);
        
entity_set_int(ents[num], EV_INT_solidSOLID_BBOX);
        
        
entity_set_int(ents[num], EV_INT_movetypeMOVETYPE_FLY);
        
///////////////////////////////////////
        
        
        /*/////////////Fakemeta/////////////////
        set_pev(ents[num],pev_mins,Float:{-8.0,-8.0,0.0});
        set_pev(ents[num],pev_maxs,Float:{8.0,8.0,8.0});
        set_pev(ents[num],pev_size,Float:{-8.0,-8.0,0.0,8.0,8.0,8.0});
        
        engfunc(EngFunc_SetSize,ents[num],Float:{-16.0,-16.0,0.0},Float:{16.0,16.0,16.0});

        set_pev(ents[num],pev_solid,SOLID_BBOX);
        set_pev(ents[num],pev_movetype,MOVETYPE_FLY);


        set_pev(ents[num],pev_origin,origins[num]);
        *///////////////////////////////////////
    
}
}

public 
load_powerups()
{
    if(
file_exists(szConfigfile))
    {
        new 
Fsize file_size(szConfigfile,1);
        new 
read[64], trash;
        new 
left[64];
        
        for(new 
i=-1;i<Fsize;i++)
        {
            
read_file(szConfigfile,i,read,63,trash);
            
            if(
read[0] != ';' &&  count_pups MAX_PUPS  &&  strlenread ) > 10)
            {
                
strbreak(read,left,63,read,63);
                
origins[count_pups][0] = str_to_float(left);
                
                
strbreak(read,left,63,read,63);
                
origins[count_pups][1] = str_to_float(left);
                
                
strbreak(read,left,63,read,63);
                
origins[count_pups][2] = str_to_float(left);
                
                
type[count_pups] = str_to_num(read);
                
eline[count_pups] = i;
                
                
count_pups++;
            }
        }
    }
}
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////

public ability_think(id)
{
    new 
players[32], num;
    new 
iCnum[32],remaining;
    
    
get_players(players,num,"ah");
    
    for(new 
i=0;i<= num;i++)
    {
        for(new 
0;NUM_PUPSj++)
        {
            if(
player_rewards[j][players[i]])
            {
                
                if(
player_rewards[j][players[i]] || teleported[i] == false)
                {
                    
set_hudmessage(02550, -1.00.01,_,_,0.99,0.2,0.2,4);
                    
show_hudmessage(i"%s: %i",powerupNames[j],player_rewards[j][players[i]]);
                }
                
                if(
player_rewards[4][players[i]])
                {
                    
//new health = get_user_health(players[i]);
                    
new health pev(players[i],pev_health);
                    new 
hpgain get_pcvar_num(iHpPerSec);
        
                    if(
health >= 223
                    {
                        
health 255;
                    }
                    else 
                    {
                        
health += hpgain;
                    }
                    
                    
//set_user_health(players[i],health);
                    
set_pev(players[i],pev_health,health+0.0);
                }
                
                
player_rewards[j][players[i]] -= 1// this is the "countdown" for the abilities  -1 per sec

                
remaining player_rewards[j][players[i]];
                
                if(
remaining <= && remaining && !(player_rewards[0][players[i]]))
                {    
                    
                    
set_hudmessage(100200100, -1.0, -1.0,0,0.0,0.9);
                    
show_hudmessage(i"%i Seconds left of your %s powerup"remainingpowerupNames[j]);
                    
                    
num_to_word(remainingiCnum32);
                    
client_cmd(0,"speak ^"vox/%s^""iCnum);
                }
                
                if(
help_count 0)
                {
                    
help_count--;
                }
                else
                {
                    
display_help(i);
                    
help_count 30;
                }
                
                if(
player_rewards[j][players[i]] <= 0)
                {
                    
remove_reward(players[i],j);
                    
player_rewards[j][players[i]] = 0;
                
                }
            
            }
        
        }
        
    }
}

public 
display_help(id)
{
    new 
helpmsg[128] = "OBSERVE! To be able to use the blink ability, you have to bind hnsp_blink to a button.";

    
set_hudmessage(02550, -1.00.01,_,_,8.0,0.2,0.2,4);
    
show_hudmessage(idhelpmsg);
}

///Random stuff, may be added to some shit in the future. like status of survived rounds or kills
// note that this is just cpy/pasted
/*public player_sprite( id, szSpriteName[] ) 
{     
    // make player invisible     
    entity_set_int( id, EV_INT_rendermode, kRenderTransTexture );     
    entity_set_float( id, EV_FL_renderamt, 0.0 );     
    
    // create sprite     
    new iPlayerSprite = create_entity( "info_target" );     
    entity_set_string( iPlayerSprite, EV_SZ_classname, "PLAYER_SPRITE" );     
    entity_set_model( iPlayerSprite, szSpriteName );     
    
    new Float:fOrigin[3];     
    entity_get_vector( id, EV_VEC_origin, fOrigin );     
    entity_set_origin( iPlayerSprite, fOrigin );     
    
    // set to follow player    
    entity_set_int( iPlayerSprite, EV_INT_movetype, MOVETYPE_FOLLOW );     
    entity_set_int( iPlayerSprite, EV_INT_solid, SOLID_NOT );    
    entity_set_edict( iPlayerSprite, EV_ENT_aiment, id );     

    return PLUGIN_HANDLED; 
} */ 
FLR is offline
 



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:38.


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