View Single Post
FiFiX
Senior Member
Join Date: May 2008
Location: Poland
Old 10-03-2010 , 14:33   Re: CS Color Chat Function Updated:[01/26/2007]
Reply With Quote #62

Code:
L 10/03/2010 - 19:28:52: [AMXX] Run time error 4: index out of bounds 
L 10/03/2010 - 19:28:52: [AMXX]    [0] colorchat.inc::ColorChat (line 76)
Using GREY color...

OFC message shows on server without problems

Using that as include:
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 const TeamName[][] = 
{
    "",
    "TERRORIST",
    "CT",
    "SPECTATOR"
}

ColorChat(id, Color:type, const msg[], any:...)
{
    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[192] = '^0';

    new team, ColorChange, index, MSG_Type;
    
    if(id)
    {
        MSG_Type = MSG_ONE_UNRELIABLE;
        index = id;
    } else {
        index = FindPlayer();
        MSG_Type = MSG_BROADCAST;
    }
    
    team = get_user_team(index);
    ColorChange = ColorSelection(index, MSG_Type, type);
    
    replace_colors(message, 191);

    ShowColorMessage(index, MSG_Type, message);
        
    if(ColorChange)
    {
        Team_Info(index, MSG_Type, TeamName[team]);
    }
}

replace_colors(message[], len)
{
    replace_all(message, len, "!g", "^x04");
    replace_all(message, len, "!t", "^x03");
    replace_all(message, len, "!y", "^x01");
}

ShowColorMessage(id, type, message[])
{
    static msgSayText;
    if(!msgSayText)
    {
        msgSayText = get_user_msgid("SayText");
    }
    message_begin(type, msgSayText, _, id);
    write_byte(id)        
    write_string(message);
    message_end();    
}

Team_Info(id, type, team[])
{
    static msgTeamInfo;
    if(!msgTeamInfo)
    {
        msgTeamInfo = get_user_msgid("TeamInfo");
    }
    message_begin(type, msgTeamInfo, _, 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;

    while(i <= get_maxplayers())
    {
        if(is_user_connected(++i))
            return i;
    }

    return -1;
}
Sloved... Just checked if user was connected ;]

Last edited by FiFiX; 10-04-2010 at 09:27.
FiFiX is offline
Send a message via Skype™ to FiFiX