AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Run time error 4: index out of bounds (https://forums.alliedmods.net/showthread.php?t=207856)

danonix 02-07-2013 14:05

Run time error 4: index out of bounds
 
Hello guys,

Can You help me with .sma, and tell me what I have done wrong? Because I've got error:
Code:

Run time error 4: index out of bounds
Errors:
Code:

L 02/07/2013 - 19:14:49: [AMXX]    [0] colorchat.inc::ColorChat (line 74)
L 02/07/2013 - 19:14:49: [AMXX]    [1] timeleft.sma::msg (line 285)

Thanks

SMA
Code:

/* AMX Mod X
*  TimeLeft Plugin
*
* by the AMX Mod X Development Team
*  originally developed by OLO
*
* This file is part of AMX Mod X.
*
*
*  This program is free software; you can redistribute it and/or modify it
*  under the terms of the GNU General Public License as published by the
*  Free Software Foundation; either version 2 of the License, or (at
*  your option) any later version.
*
*  This program is distributed in the hope that it will be useful, but
*  WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
*  General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with this program; if not, write to the Free Software Foundation,
*  Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*  In addition, as a special exception, the author gives permission to
*  link the code of this program with the Half-Life Game Engine ("HL
*  Engine") and Modified Game Libraries ("MODs") developed by Valve,
*  L.L.C ("Valve"). You must obey the GNU General Public License in all
*  respects for all of the code used other than the HL Engine and MODs
*  from Valve. If you modify this file, you may extend this exception
*  to your version of the file, but you are not obligated to do so. If
*  you do not wish to do so, delete this exception statement from your
*  version.
*/

#include <amxmodx>
#include <colorchat>

new g_TimeSet[32][2]
new g_LastTime
new g_CountDown
new g_Switch

public plugin_init()
{
    register_plugin("TimeLeft", AMXX_VERSION_STR, "AMXX Dev Team")
    register_dictionary("timeleft.txt")
    register_cvar("amx_time_voice", "1")
    register_srvcmd("amx_time_display", "setDisplaying")
    register_cvar("amx_timeleft", "00:00", FCVAR_SERVER|FCVAR_EXTDLL|FCVAR_UNLOGGED|FCVAR_SPONLY)
    register_clcmd("say timeleft", "sayTimeLeft", 0, "- displays timeleft")
    register_clcmd("say thetime", "sayTheTime", 0, "- displays current time")
   
    set_task(0.8, "timeRemain", 8648458, "", 0, "b")
}

public sayTheTime(id)
{
    if (get_cvar_num("amx_time_voice"))
    {
        new mhours[6], mmins[6], whours[32], wmins[32], wpm[6]
       
        get_time("%H", mhours, 5)
        get_time("%M", mmins, 5)
       
        new mins = str_to_num(mmins)
        new hrs = str_to_num(mhours)
       
        if (mins)
            num_to_word(mins, wmins, 31)
        else
            wmins[0] = 0
       
        if (hrs < 12)
            wpm = "am "
        else
        {
            if (hrs > 12) hrs -= 12
            wpm = "pm "
        }

        if (hrs)
            num_to_word(hrs, whours, 31)
        else
            whours = "twelve "
       
        client_cmd(id, "spk ^"fvox/time_is_now %s_period %s%s^"", whours, wmins, wpm)
    }
   
    new ctime[64]
   
    get_time("%m/%d/%Y - %H:%M:%S", ctime, 63)
    client_print(0, print_chat, "%L:  %s", LANG_PLAYER, "THE_TIME", ctime)
   
    return PLUGIN_CONTINUE
}

public sayTimeLeft(id)
{
    if (get_cvar_float("mp_timelimit"))
    {
        new a = get_timeleft()
       
        if (get_cvar_num("amx_time_voice"))
        {
            new svoice[128]
            setTimeVoice(svoice, 127, 0, a)
            client_cmd(id, "%s", svoice)
        }
        ColorChat(id, RED, "~%L:  ^x04 %d:%02d", LANG_PLAYER, "TIME_LEFT", (a / 60), (a % 60))
    }
    else
        ColorChat(id, RED, "~%L", LANG_PLAYER, "NO_T_LIMIT")
   
    return PLUGIN_CONTINUE
}

setTimeText(text[], len, tmlf, id)
{
    new secs = tmlf % 60
    new mins = tmlf / 60
   
    if (secs == 0)
        format(text, len, "%d %L", mins, id, (mins > 1) ? "MINUTES" : "MINUTE")
    else if (mins == 0)
        format(text, len, "%d %L", secs, id, (secs > 1) ? "SECONDS" : "SECOND")
    else
        format(text, len, "%d %L %d %L", mins, id, (mins > 1) ? "MINUTES" : "MINUTE", secs, id, (secs > 1) ? "SECONDS" : "SECOND")
}

setTimeVoice(text[], len, flags, tmlf)
{
    new temp[7][32]
    new secs = tmlf % 60
    new mins = tmlf / 60
   
    for (new a = 0;a < 7;++a)
        temp[a][0] = 0

    if (secs > 0)
    {
        num_to_word(secs, temp[4], 31)
       
        if (!(flags & 8))
            temp[5] = "seconds "    /* there is no "second" in default hl */
    }
   
    if (mins > 59)
    {
        new hours = mins / 60
       
        num_to_word(hours, temp[0], 31)
       
        if (!(flags & 8))
            temp[1] = "hours "
       
        mins = mins % 60
    }
   
    if (mins > 0)
    {
        num_to_word(mins, temp[2], 31)
       
        if (!(flags & 8))
            temp[3] = "minutes "
    }
   
    if (!(flags & 4))
        temp[6] = "remaining "
   
    return format(text, len, "spk ^"vox/%s%s%s%s%s%s%s^"", temp[0], temp[1], temp[2], temp[3], temp[4], temp[5], temp[6])
}

findDispFormat(time)
{
    for (new i = 0; g_TimeSet[i][0]; ++i)
    {
        if (g_TimeSet[i][1] & 16)
        {
            if (g_TimeSet[i][0] > time)
            {
                if (!g_Switch)
                {
                    g_CountDown = g_Switch = time
                    remove_task(8648458)
                    set_task(1.0, "timeRemain", 34543, "", 0, "b")
                }
               
                return i
            }
        }
        else if (g_TimeSet[i][0] == time)
        {
            return i
        }
    }
   
    return -1
}

public setDisplaying()
{
    new arg[32], flags[32], num[32]
    new argc = read_argc() - 1
    new i = 0

    while (i < argc && i < 32)
    {
        read_argv(i + 1, arg, 31)
        parse(arg, flags, 31, num, 31)
       
        g_TimeSet[i][0] = str_to_num(num)
        g_TimeSet[i][1] = read_flags(flags)
       
        i++
    }
    g_TimeSet[i][0] = 0
   
    return PLUGIN_HANDLED
}

public timeRemain(param[])
{
    new gmtm = get_timeleft()
    new tmlf = g_Switch ? --g_CountDown : gmtm
    new stimel[12]
   
    format(stimel, 11, "%02d:%02d", gmtm / 60, gmtm % 60)
    set_cvar_string("amx_timeleft", stimel)
   
    if (g_Switch && gmtm > g_Switch)
    {
        remove_task(34543)
        g_Switch = 0
        set_task(0.8, "timeRemain", 8648458, "", 0, "b")
       
        return
    }

    if (tmlf > 0 && g_LastTime != tmlf)
    {
        g_LastTime = tmlf
        new tm_set = findDispFormat(tmlf)
       
        if (tm_set != -1)
        {
            new flags = g_TimeSet[tm_set][1]
            new arg[128]
           
            if (flags & 1)
            {
                new players[32], pnum
               
                get_players(players, pnum, "c")
               
                for (new i = 0; i < pnum; i++)
                {
                    setTimeText(arg, 127, tmlf, players[i])
                   
                    if (flags & 16)
                        set_hudmessage(255, 255, 255, -1.0, 0.85, 0, 0.0, 1.1, 0.1, 0.5, -1)
                    else
                        set_hudmessage(255, 255, 255, -1.0, 0.85, 0, 0.0, 3.0, 0.0, 0.5, -1)
                   
                    show_hudmessage(players[i], "%s", arg)
                }
            }

            if (flags & 2)
            {
                setTimeVoice(arg, 127, flags, tmlf)
                client_cmd(0, "%s", arg)
            }
        }
    }
}

public client_putinserver(id)
{
    set_task(10.0, "msg", id)
}

public msg(id)
{
    ColorChat(id, GREEN, "^x01 Witaj na serwerze ^x04Paintball MOD ^x01zmodyfikowanym przez ^x04 xxxx")
    ColorChat(id, RED, "----Zyczymy milej gry i ^x03 duzo fragow!")
}


simanovich 02-07-2013 14:39

Re: Run time error 4: index out of bounds
 
Show us the lines cuz I cann't find them

danonix 02-07-2013 15:13

Re: Run time error 4: index out of bounds
 
And here is my colorchat.inc

Code:

/* Fun functions
*
* by Numb
*
* This file is provided as is (no warranties).
*/
 
#if defined _colorchat_included
  #endinput
#endif
#define _colorchat_included
 
enum Color
{
    NORMAL = 1, // clients scr_concolor cvar color
    GREEN, // Green Color
    TEAM_COLOR, // Red, grey, blue
    GREY, // grey
    RED, // Red
    BLUE, // Blue
}
 
new TeamName[][] =
{
    "",
    "TERRORIST",
    "CT",
    "SPECTATOR"
}
 
ColorChat(id, Color:type, const msg[], {Float,Sql,Result,_}:...)
{
    new message[256];
 
    switch(type)
    {
        case NORMAL: // clients scr_concolor cvar color
        {
            message[0] = 0x01;
        }
        case GREEN: // Green
        {
            message[0] = 0x04;
        }
        default: // White, Red, Blue
        {
            message[0] = 0x03;
        }
    }
 
    vformat(message[1], 251, msg, 4);
 
    // Make sure message is not longer than 192 character. Will crash the server.
    message[191] = '^0';
 
    new team, ColorChange, index, MSG_Type;
 
    if(id)
    {
        MSG_Type = MSG_ONE;
        index = id;
    } else {
        index = FindPlayer();
        MSG_Type = MSG_ALL;
    }
 
    team = get_user_team(index);
    ColorChange = ColorSelection(index, MSG_Type, type);
 
    ShowColorMessage(index, MSG_Type, message);
 
    if(ColorChange)
    {
        Team_Info(index, MSG_Type, TeamName[team]);
    }
}
 
ShowColorMessage(id, type, message[])
{
    static get_user_msgid_saytext;
    if(!get_user_msgid_saytext)
    {
        get_user_msgid_saytext = get_user_msgid("SayText");
    }
    message_begin(type, get_user_msgid_saytext, _, id);
    write_byte(id)       
    write_string(message);
    message_end();   
}
 
Team_Info(id, type, team[])
{
    static bool:teaminfo_used;
    static get_user_msgid_teaminfo;
    if(!teaminfo_used)
    {
        get_user_msgid_teaminfo = get_user_msgid("TeamInfo");
        teaminfo_used = true;
    }
    message_begin(type, get_user_msgid_teaminfo, _, id);
    write_byte(id);
    write_string(team);
    message_end();
 
    return 1;
}
 
ColorSelection(index, type, Color:Type)
{
    switch(Type)
    {
        case RED:
        {
            return Team_Info(index, type, TeamName[1]);
        }
        case BLUE:
        {
            return Team_Info(index, type, TeamName[2]);
        }
        case GREY:
        {
            return Team_Info(index, type, TeamName[0]);
        }
    }
 
    return 0;
}
 
FindPlayer()
{
    new i = -1;
 
    static iMaxPlayers;
 
    if( !iMaxPlayers )
    {
        iMaxPlayers = get_maxplayers( );
    }
 
    while(i <= iMaxPlayers)
    {
        if(is_user_connected(++i))
            return i;
    }
 
    return -1;
}


fysiks 02-08-2013 00:31

Re: Run time error 4: index out of bounds
 
Use the better version of ColorChat. If that doesn't fix it then there is something wrong in your plugin's code.

danonix 02-08-2013 09:56

Re: Run time error 4: index out of bounds
 
@fysiks, it didnt help. Still same problem

Code:

L 02/08/2013 - 14:52:58: [AMXX]    [0] colorchat.inc::ColorChat (line 74)
L 02/08/2013 - 14:52:58: [AMXX]    [1] timeleft.sma::msg (line 285)


csoldjb 02-08-2013 11:04

Re: Run time error 4: index out of bounds
 
The error comes from Team_Info(index, MSG_Type, TeamName[team]). You can print 'team value'

fysiks 02-08-2013 12:30

Re: Run time error 4: index out of bounds
 
When posting error messages, post the WHOLE thing.

danonix 02-08-2013 13:32

Re: Run time error 4: index out of bounds
 
Code:

L 02/08/2013 - 18:41:44: Start of error session.
L 02/08/2013 - 18:41:44: Info (map "de_inferno") (file "addons/amxmodx/logs/error_20130208.log")
L 02/08/2013 - 18:41:44: [AMXX] Displaying debug trace (plugin "timeleft.amxx")
L 02/08/2013 - 18:41:44: [AMXX] Run time error 4: index out of bounds
L 02/08/2013 - 18:41:44: [AMXX]    [0] colorchat.inc::ColorChat (line 74)
L 02/08/2013 - 18:41:44: [AMXX]    [1] timeleft.sma::msg (line 285)

That's it

@Csoldjb, I'll change it and tell, if its ok.

Thanks

fysiks 02-09-2013 00:00

Re: Run time error 4: index out of bounds
 
You didn't update to the include that I told you to use because in that version, this error is not possible.


All times are GMT -4. The time now is 20:41.

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