Raised This Month: $ Target: $400
 0% 

[HELP] Index out of bounds


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Depresie
Veteran Member
Join Date: Nov 2013
Old 01-12-2016 , 12:23   [HELP] Index out of bounds
Reply With Quote #1

so im trying to create am ambience + round countdown plugin in one.. everything works fine, except i get index out of bounds error on line 129

PHP Code:
#include <amxmodx> #include <csx>
 #include <amxmisc>
 #include <zp50_gamemodes>
 

 #define PLUGIN "[ZP] Ambience Sounds"
 #define VERSION "1.0"
 #define AUTHOR "ADN"
 

 #define TASK_COUNTER 12345
 #define TASK_AMBIENCE 12346
 #define TASK_SOUNDS 12347
 

 #define MAX_SPEAK 10
 #define MAX_SOUNDS 8
 

 #define SoundAmbience "adnx_sound/adnx_ambience.wav"
 #define SoundAnnounce "adnx_sound/adnx_countdown_announce.wav"
 #define SoundPrepare "adnx_sound/adnx_countdown_prepare.wav"
 

 
new speak[MAX_SPEAK][] = 
 {
     
"adnx_sound/adnx_countdown_1.wav"
     
"adnx_sound/adnx_countdown_2.wav"
     
"adnx_sound/adnx_countdown_3.wav",
     
"adnx_sound/adnx_countdown_4.wav"
     
"adnx_sound/adnx_countdown_5.wav"
     
"adnx_sound/adnx_countdown_6.wav"
     
"adnx_sound/adnx_countdown_7.wav",
     
"adnx_sound/adnx_countdown_8.wav"
     
"adnx_sound/adnx_countdown_9.wav",
     
"adnx_sound/adnx_countdown_10.wav"
 
}
 

 new 
sounds[MAX_SOUNDS][] =
 {
     
"adnx_sound/adnx_ambience_sound1.wav"
     
"adnx_sound/adnx_ambience_sound2.wav"
     
"adnx_sound/adnx_ambience_sound3.wav",
     
"adnx_sound/adnx_ambience_sound4.wav",
     
"adnx_sound/adnx_ambience_sound5.wav",
     
"adnx_sound/adnx_ambience_sound6.wav",
     
"adnx_sound/adnx_ambience_sound7.wav",
     
"adnx_sound/adnx_ambience_sound8.wav",
 }
 

 new 
g_timerg_msgsync
 

 
public plugin_init() 
 {
     
register_plugin(PLUGINVERSIONAUTHOR)
     
     
register_event("HLTV""event_round_start""a""1=0""2=0")
     
     
g_msgsync CreateHudSyncObj()
 }
 

 public 
plugin_precache() 
 {
     for(new 
0sizeof(speak); x++) 
     {
         
precache_sound(speak[x])
     }
     for(new 
0sizeof(sounds); x++) 
     {
         
precache_sound(sounds[x])
     }
     
precache_sound(SoundAmbience)
     
precache_sound(SoundAnnounce)
     
precache_sound(SoundPrepare)
 

 

     
     return 
PLUGIN_CONTINUE
 
}
 

 public 
event_round_start()
 {
     
g_timer get_cvar_num("zp_gamemode_delay")
     
     
set_task(0.1"Countdown"TASK_COUNTER)
     
set_task(0.1"AmbienceBackground"TASK_AMBIENCE)
     
set_task(0.1"AmbienceSounds"TASK_SOUNDS)
     
     return 
PLUGIN_CONTINUE
 
}
 

 public 
zp_fw_gamemodes_start()
 {
     
set_task(5.0"AmbienceSounds"TASK_SOUNDS)
 }
 

 public 
Countdown() 
 {
     if((
zp_gamemodes_get_current() == ZP_NO_GAME_MODE) && g_timer 0)
     {
         if(
g_timer == 20)
         {
             
client_cmd(0"spk %s"SoundAnnounce)
         }
         if(
g_timer == 12)
         {
             
client_cmd(0"spk %s"SoundPrepare)
         }
         
set_task(1.0"Countdown"TASK_COUNTER)
         
         if(
g_timer <= 10
         {
             
set_hudmessage(17900, -1.00.1520.021.00.010.110)
             
ShowSyncHudMsg(0g_msgsync"=================^n=======================^n==========================^n=========|  WARNING!!!  |=========^n=========|  BIOHAZZARD  |=========^n===========|  [%d]  |===========^n=========================^n================="g_timer)
             
client_cmd(0"spk %s"speak[g_timer -1])
             
         }
         --
g_timer
         
     
}
     return 
PLUGIN_CONTINUE
 
}
     
 public 
AmbienceBackground()
 {
     
set_task(20.0"AmbienceBackground"TASK_AMBIENCE)
     
client_cmd(0"spk %s"SoundAmbience)
 }
 

 public 
AmbienceSounds()
 {
     
set_task(random_float(10.030.0), "AmbienceSounds"TASK_SOUNDS)
     
client_cmd(0"spk %s"sounds[random_num(0MAX_SOUNDS)])
 }
         
 public 
zp_fw_gamemodes_end()
 {
     
remove_task(TASK_COUNTER)
     
remove_task(TASK_AMBIENCE)
     
remove_task(TASK_SOUNDS)
 } 
Attached Files
File Type: sma Get Plugin or Get Source (zp50_ambience_sounds.sma - 579 views - 3.1 KB)
__________________
Depresie is offline
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 01-12-2016 , 15:12   Re: [HELP] Index out of bounds
Reply With Quote #2

PHP Code:
new sounds[MAX_SOUNDS][] =
{
    
"adnx_sound/adnx_ambience_sound1.wav"
    
"adnx_sound/adnx_ambience_sound2.wav"
    
"adnx_sound/adnx_ambience_sound3.wav",
    
"adnx_sound/adnx_ambience_sound4.wav",
    
"adnx_sound/adnx_ambience_sound5.wav",
    
"adnx_sound/adnx_ambience_sound6.wav",
    
"adnx_sound/adnx_ambience_sound7.wav",
    
"adnx_sound/adnx_ambience_sound8.wav",

to

PHP Code:
new sounds[MAX_SOUNDS][] =
{
    
"adnx_sound/adnx_ambience_sound1.wav"
    
"adnx_sound/adnx_ambience_sound2.wav"
    
"adnx_sound/adnx_ambience_sound3.wav",
    
"adnx_sound/adnx_ambience_sound4.wav",
    
"adnx_sound/adnx_ambience_sound5.wav",
    
"adnx_sound/adnx_ambience_sound6.wav",
    
"adnx_sound/adnx_ambience_sound7.wav",
    
"adnx_sound/adnx_ambience_sound8.wav"

siriusmd99 is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 01-12-2016 , 16:01   Re: [HELP] Index out of bounds
Reply With Quote #3

ohh... damn... i dont know how i missed that.. i had 10 sounds and i guess i forgot the ","
it's funny, shouldn't it give an error at compilation in this case?

Later Edit: It looks like the compiler has major issues in this way, i found more cases like this.. i posted in the issues section
__________________

Last edited by Depresie; 01-12-2016 at 17:19.
Depresie is offline
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 01-13-2016 , 06:14   Re: [HELP] Index out of bounds
Reply With Quote #4

client_cmd(0, "spk %s", sounds[random_num(0, MAX_SOUNDS)])


To:

client_cmd(0, "spk %s", sounds[random_num(0, MAX_SOUNDS - 1)])

You have 8 sounds but array starts with 0 .
Sounds[0] = sound1
Sounds[7] = sound8

And sound[8] shall be null.

Last edited by siriusmd99; 01-13-2016 at 06:18.
siriusmd99 is offline
addons_zz
Veteran Member
Join Date: Aug 2015
Location: Dreams, zz
Old 01-13-2016 , 07:43   Re: [HELP] Index out of bounds
Reply With Quote #5

siriusmd99, hawk eyes.

Update:

Bugsy, hawk eyes. addons zz, duck eyes.
__________________
Plugin: Sublime Text - ITE , Galileo
Multi-Mod: Manager / Plugin / Server

Support me on Patreon, Ko-fi, Liberapay or Open Collective

Last edited by addons_zz; 01-13-2016 at 11:59. Reason: duck eyes
addons_zz is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-13-2016 , 08:36   Re: [HELP] Index out of bounds
Reply With Quote #6

Quote:
Originally Posted by siriusmd99 View Post
client_cmd(0, "spk %s", sounds[random_num(0, MAX_SOUNDS)])


To:

client_cmd(0, "spk %s", sounds[random_num(0, MAX_SOUNDS - 1)])

You have 8 sounds but array starts with 0 .
Sounds[0] = sound1
Sounds[7] = sound8

And sound[8] shall be null.
Just do random( MAX_SOUNDS ) , this automatically does 0 to num-1.

Sound[8] shall be index out of bounds, not null.
__________________
Bugsy is offline
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 01-13-2016 , 10:28   Re: [HELP] Index out of bounds
Reply With Quote #7

Quote:
Originally Posted by Bugsy View Post
Just do random( MAX_SOUNDS ) , this automatically does 0 to num-1.

Sound[8] shall be index out of bounds, not null.
Thanks , i had some bad experience with amxx, didn't know what's the difference between random and random_num.
siriusmd99 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 00:42.


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