AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [SOLVED] get_players error "index out of bound" (https://forums.alliedmods.net/showthread.php?t=184134)

yokomo 05-01-2012 09:38

[SOLVED] get_players error "index out of bound"
 
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;



Backstabnoob 05-01-2012 09:59

Re: [Help] get_players error "index out of bound"
 
My guess is it should be
PHP Code:

iRandomPlayer iPlayers[random(iNum 1)] 


Exolent[jNr] 05-01-2012 10:04

Re: [Help] get_players error "index out of bound"
 
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 (Post 1699899)
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.

yokomo 05-01-2012 11:08

Re: [SOLVED] get_players error "index out of bound"
 
Exolent[jNr]
Nice, this code fix that error:
PHP Code:

if(!iNum) return PLUGIN_HANDLED

No more index out of bounds.
Thanks Exolent[jNr]


All times are GMT -4. The time now is 07:45.

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