Raised This Month: $ Target: $400
 0% 

[SOLVED] get_players error "index out of bound"


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
yokomo
Surprise Ascot!
Join Date: May 2010
Location: Malaysia
Old 05-01-2012 , 09:38   [SOLVED] get_players error "index out of bound"
Reply With Quote #1

How do i fix this error?
Code:
L 05/01/2012 - 18:14:29: Start of error session.
L 05/01/2012 - 18:14:29: Info (map "de_dust2") (file "addons/amxmodx/logs/error_20120501.log")
L 05/01/2012 - 18:14:29: [AMXX] Displaying debug trace (plugin "DeathTeleport.amxx")
L 05/01/2012 - 18:14:29: [AMXX] Run time error 4: index out of bounds 
L 05/01/2012 - 18:14:29: [AMXX]    [0] DeathTeleport.sma::StartTeleport (line 36)
PHP Code:
public StartTeleport(id)
{
    if(!
is_user_alive(id)) return PLUGIN_HANDLED;
    
    new 
iPlayers[32], iNumiRandomPlayerFloat:origin[3]
    switch(
fm_cs_get_user_team(id))
    {
        case 
TEAM_CTget_players(iPlayersiNum"ae""TERRORIST");
        case 
TEAM_TERRORISTget_players(iPlayersiNum"ae""CT");
    }
    
    
iRandomPlayer iPlayers[random(iNum)] //line 36 is here
    
if(!iRandomPlayer) return PLUGIN_HANDLED;
    
    
pev(iRandomPlayerpev_originorigin)
    
origin[2] += 80.0
    set_pev
(idpev_originorigin)
    
set_task(0.2"DelayCheckStuck"id+TASK_CHECK)
    
    return 
PLUGIN_HANDLED;

__________________
Team-MMG CS1.6 Servers:
✅ MultiMod -- 103.179.44.152:27016
✅ Zombie Plague -- 103.179.44.152:27015
✅ Zombie Escape -- 103.179.44.152:27017
✅ Klassik Kombat -- 103.179.44.152:27018
✅ Boss-Battle -- 103.179.44.152:27019

Last edited by yokomo; 05-01-2012 at 11:10. Reason: Error has been fixed by Exolent[jNr]
yokomo is offline
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 05-01-2012 , 09:59   Re: [Help] get_players error "index out of bound"
Reply With Quote #2

My guess is it should be
PHP Code:
iRandomPlayer iPlayers[random(iNum 1)] 
Backstabnoob is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 05-01-2012 , 10:04   Re: [Help] get_players error "index out of bound"
Reply With Quote #3

You should check if there are actually players to choose from, not if the player is valid.

Code:
if(!iNum) return PLUGIN_HANDLED; iRandomPlayer = iPlayers[random(iNum)];

Quote:
Originally Posted by Backstabnoob View Post
My guess is it should be
PHP Code:
iRandomPlayer iPlayers[random(iNum 1)] 
No, that's not right. random() returns a number from 0 to N-1, so random(3) returns a value 0-2.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
yokomo
Surprise Ascot!
Join Date: May 2010
Location: Malaysia
Old 05-01-2012 , 11:08   Re: [SOLVED] get_players error "index out of bound"
Reply With Quote #4

Exolent[jNr]
Nice, this code fix that error:
PHP Code:
if(!iNum) return PLUGIN_HANDLED
No more index out of bounds.
Thanks Exolent[jNr]
__________________
Team-MMG CS1.6 Servers:
✅ MultiMod -- 103.179.44.152:27016
✅ Zombie Plague -- 103.179.44.152:27015
✅ Zombie Escape -- 103.179.44.152:27017
✅ Klassik Kombat -- 103.179.44.152:27018
✅ Boss-Battle -- 103.179.44.152:27019
yokomo is offline
Reply


Thread Tools
Display Modes

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 07:45.


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