AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [SOLVED] Error: Index out of bounds (function get_players) (https://forums.alliedmods.net/showthread.php?t=153071)

mabaclu 03-18-2011 07:24

[SOLVED] Error: Index out of bounds (function get_players)
 
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.

Exolent[jNr] 03-18-2011 07:41

Re: Error: Index out of bounds (function get_players)
 
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)

mabaclu 03-18-2011 08:14

Re: Error: Index out of bounds (function get_players)
 
It's working now, thanks!


All times are GMT -4. The time now is 14:39.

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