Raised This Month: $ Target: $400
 0% 

[SOLVED] Error: Index out of bounds (function get_players)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
mabaclu
Senior Member
Join Date: Jun 2010
Location: Portugal
Old 03-18-2011 , 07:24   [SOLVED] Error: Index out of bounds (function get_players)
Reply With Quote #1

Hi, I'm having the following error:
Quote:
L 03/18/2011 - 11:14:52: [AMXX] Displaying debug trace (plugin "jailbreak_leet.amxx")
L 03/18/2011 - 11:14:52: [AMXX] Run time error 4: index out of bounds
L 03/18/2011 - 11:14:52: [AMXX] [0] jailbreak_leet.sma::hook_death (line 228)
L 03/18/2011 - 11:17:18: [AMXX] Displaying debug trace (plugin "jailbreak_leet.amxx")
L 03/18/2011 - 11:17:18: [AMXX] Run time error 4: index out of bounds
L 03/18/2011 - 11:17:18: [AMXX] [0] jailbreak_leet.sma::logevent_round_start (line 173)
PHP Code:
new bool:g_player_is_leader[33]; 
PHP Code:
register_event("DeathMsg""hook_death""a"); 
PHP Code:
register_logevent("logevent_round_start"2"1=Round_Start"); 
PHP Code:
public logevent_round_start()
{
    new 
iPlayers[32];
    new 
iNum;
    
get_players(iPlayers,iNum,"ace","CT");
    
g_player_is_leader[iPlayers[random(iNum 1)]] = true// !!! Index out of bounds here !!! (line 173)

hook_death has got the same code and the same error so I won't post it here.
Please tell me what's wrong with my code, when there is 1 CT the function logevent_round_start() doesn't run and when there are 2 CTs it chooses the CT with the first ID.
Basically I need it to choose a random CT and set g_player_is_leader[ id of the chosen CT ] to true.
__________________

Last edited by mabaclu; 03-18-2011 at 08:15. Reason: Added [SOLVED] in title
mabaclu is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 03-18-2011 , 07:41   Re: Error: Index out of bounds (function get_players)
Reply With Quote #2

1. Check if there are any players before doing that.

2. You use random incorrectly. random() goes from 0 to (x-1) where x is the value you pass.
Therefore, either do random(iNum) or random_num(0, iNum-1)
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
mabaclu
Senior Member
Join Date: Jun 2010
Location: Portugal
Old 03-18-2011 , 08:14   Re: Error: Index out of bounds (function get_players)
Reply With Quote #3

It's working now, thanks!
__________________
mabaclu 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 14:39.


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