搜索
查看: 4678|回复: 16

Rulzy版主你什么时候能讲解下最新的颜色信息

[复制链接]
发表于 2008-2-6 15:15:42 | 显示全部楼层 |阅读模式 来自 云南西双版纳州景洪
在官方上看到有关指定使用聊天信息颜色的方法.但是看了半天没看懂怎么使用指定颜色.比如说指定使用红色,蓝色,绿色,灰色.
麻烦Rulzy版主能不能讲解下使用方法啊!我是看了半天没看懂怎么调用这些指定颜色函数.
enum Color
{
    YELLOW = 1,
    GREEN,         
    TEAM_COLOR,     
    GREY,   
    RED,   
    BLUE,
}

new TERRORIST[] = "TERRORIST"
new CT[]     = "CT"
new NOTHING[]     = ""
new SPEC[]     = "SPECTATOR"

public color_chat(id, Color:type, const msg[], {Float, Sql, Result, _}:...)
{
    static message[STR_L]

    switch(type)
    {
        case YELLOW:     message[0] = 0x01
        case GREEN:    message[0] = 0x04
        default:     message[0] = 0x03
    }

    vformat(message[1], (STR_L-1), msg, 4)
    message[192] = '^0'

    new team, did
    if(id)
    {
        team = get_user_team(id)

        did = color_selection(id, type)
        show_message(id, message)

        if(did) TeamSelection(id, team)
    }
}

show_message(id, message[])
{
    message_begin(MSG_ONE, g_msg_saytext, _, id)
    write_byte(id)
    write_string(message)
    message_end()
}

Team_Info(id, team[])
{
    message_begin(MSG_ONE, g_msg_teaminfo, _, id)
    write_byte(id)
    write_string(team)
    message_end()

    return 1
}

color_selection(index, Color:Type)
{
    switch(Type)
    {
        case RED:     return Team_Info(index, TERRORIST)
        case BLUE:     return Team_Info(index, CT)
        case GREY:     return Team_Info(index, NOTHING)
    }
    return 0
}

TeamSelection(index, team)
{
    switch(team)
    {
        case 0:     Team_Info(index, NOTHING)
        case 1:     Team_Info(index, TERRORIST)
        case 2:     Team_Info(index, CT)
        case 3:     Team_Info(index, SPEC)
    }
}
发表于 2008-2-6 20:02:24 | 显示全部楼层 来自 福建漳州

回复: Rulzy版主你什么时候能讲解下最新的颜色信息

颜色同时只能有三种:默认的黄色、绿色、按队伍区分颜色(控制字节分别为:^x01、^x04、^x03)。而按队伍区分颜色,有三种颜色:蓝(CT)、红(T)、灰(SPEC)。具体可以参考我签名中的:[分享]如何使用彩色聊天信息

现在问题的关键是,如果我想不管玩家是哪个队伍,都想显示为红色,这时就要发个消息到玩家,让其认为指定的玩家是T,这样就会显示为红色了。下面这个代码其实就是要实现这个功能:
Team_Info(id, team[])
{
message_begin(MSG_ONE, g_msg_teaminfo, _, id)
write_byte(id)
write_string(team)
message_end()

return 1
}

要注意,发送完聊天信息之后,要及时把玩家队伍信息恢复为实际队伍。
回复

使用道具 举报

 楼主| 发表于 2008-2-6 23:31:37 | 显示全部楼层 来自 云南西双版纳州景洪

回复: Rulzy版主你什么时候能讲解下最新的颜色信息

虽然我还是没有搞懂意思.但是还是谢谢版主的解答,等我有时间在好好研究下吧.祝版主新年快乐!
回复

使用道具 举报

发表于 2008-2-7 18:09:36 | 显示全部楼层 来自 广东深圳

回复: Rulzy版主你什么时候能讲解下最新的颜色信息

我这有一段代码,是来自Ryu2877在官方放的一段源码
貌似可以自己定义颜色,不需要特定的
[php]
//需要在前面定义
new iSayTextMsgID
//好像还要在plugin_init下增加
iSayTextMsgID=get_user_msgid("SayText")
//然后就可以定义颜色了。
new message[128]
format(message, 127, "^x01* 欢迎^x03管理员^x01【^x04%s^x01】^x03-->>^x01【排名】第^x04%d^x01名【来自】^x04%s^x01-^x04%s", op_name, iRankPos, country, area)
color_saytext(message, MSG_ALL, _, 4)//^x03这个时候就是,后面的4是代表的CT是蓝色。T为红色,旁观为灰色,如果定义为1就是T的颜色红色,定义为2为CT的颜色蓝色,3就旁观的颜色灰色
//MSG_ALL 定义为所有人看的。。。
//MSG_ID 定义为当前人看的。。。
//我的理解是这样的,你看下行不
////////////////////////////// color_saytext ////////////////////////////////////////////
/*
color_by_team = 1 use TE's team-color(red)
color_by_team = 2 use CT's team-color(blue)
color_by_team = 3 use SPEC's team-color(gray)
color_by_team = 4 use everyone's team-color(TE use red, CT use blue, SPECTATOR use gray)
*/
stock color_saytext(message[], dest, id = 0, color_by_team = 0 )
{
if ( (dest == MSG_ONE || dest == MSG_ONE_UNRELIABLE ) && !id )
return 0
new pList[32],pNum,i,color
if ( color_by_team > 3 )//by current definiens, affirm MSG_ALL
{
get_players(pList, pNum)
for ( i=0; i<pNum; i++ )
{
color = pList
message_begin(MSG_ONE, iSayTextMsgID, {0,0,0}, color)
write_byte(color)
write_string(message)
message_end()
}
return 1
}
if ( color_by_team && color_by_team < 3 )//if use te or ct's team-color
{
new iParam
get_players(pList, pNum)
for ( i=0; i<pNum; i++ )
{
iParam = pList
if ( get_user_team(iParam) == color_by_team )
{
color = iParam
break
}
}
}
if ( !color )//if cannot find any player by team or not const id, use gray color
color = (color_by_team == 3 || !id )?33:id
message_begin(dest, iSayTextMsgID, {0,0,0}, (dest == MSG_ONE || dest == MSG_ONE_UNRELIABLE)?id: 0)
write_byte(color)
write_string(message)
return message_end()
}[/php]

还有一个方法,参照下面代码看下咯
[PHP]/* AMX Mod X
*   Descriptive 'Fire in the hole!'
*
* (c) Copyright 2006 by VEN
*
* This file is provided as is (no warranties)
*
*     DESCRIPTION
*       Plugin provides additional colored text for "Fire in the hole!" radio chat message.
*       The color and the text is different for each grenade type and can be altered.
*       This will help teammates to get the throwed grenade type and act accordingly.
*       Search for "EDITABLE" mark in the plugin's source code to configure text and color.
*
*     CREDITS
*       Damaged Soul - colored chat text method
*       p3tsin - team color override method
*/
#include <amxmodx>
#define PLUGIN_NAME "Descriptive 'Fire in the hole!'"
#define PLUGIN_VERSION "0.1"
#define PLUGIN_AUTHOR "VEN"
enum grenade {
GRENADE_HE,
GRENADE_FLASH,
GRENADE_SMOKE
}
// EDITABLE: grenade description
new const g_grenade_description[_:grenade][] = {
" 【手榴弹】",
" 【闪光弹】",
" 【烟雾弹】"
}
enum color {
COLOR_NORMAL,
COLOR_RED,
COLOR_BLUE,
COLOR_GRAY,
COLOR_GREEN
}
// EDITABLE: grenade description text color
new const g_grenade_desccolor[_:grenade] = {
COLOR_RED,
COLOR_GRAY,
COLOR_GREEN
}
new const g_grenade_weaponid[_:grenade] = {
CSW_HEGRENADE,
CSW_FLASHBANG,
CSW_SMOKEGRENADE
}
#define COLORCODE_NORMAL 0x01
#define COLORCODE_TEAM 0x03
#define COLORCODE_LOCATION 0x04
new const g_color_code[_:color] = {
COLORCODE_NORMAL,
COLORCODE_TEAM,
COLORCODE_TEAM,
COLORCODE_TEAM,
COLORCODE_LOCATION
}
new const g_color_teamname[_:color][] = {
"",
"TERRORIST",
"CT",
"SPECTATOR",
""
}
#define RADIOTEXT_MSGARG_NUMBER 5
enum radiotext_msgarg {
RADIOTEXT_MSGARG_PRINTDEST = 1,
RADIOTEXT_MSGARG_CALLERID,
RADIOTEXT_MSGARG_TEXTTYPE,
RADIOTEXT_MSGARG_CALLERNAME,
RADIOTEXT_MSGARG_RADIOTYPE,
}
public client_color(playerid,colorid,msg[])
{
message_begin(playerid?MSG_ONE:MSG_ALL, get_user_msgid("SayText"), {0,0,0}, playerid)
write_byte(colorid)
write_string(msg)
message_end()
}
new const g_required_radiotype[] = "#Fire_in_the_hole"
new const g_radiotext_template[] = "^x04%s ^x01[对讲机]:^x03投了一颗!"
new g_msgid_saytext
new g_msgid_teaminfo
public plugin_init() {
register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR)
register_message(get_user_msgid("TextMsg"), "message_text")
g_msgid_saytext = get_user_msgid("SayText")
g_msgid_teaminfo = get_user_msgid("TeamInfo")
}
public message_text(msgid, dest, id) {
if (get_msg_args() != RADIOTEXT_MSGARG_NUMBER || get_msg_argtype(RADIOTEXT_MSGARG_RADIOTYPE) != ARG_STRING)
  return PLUGIN_CONTINUE
static arg[32]
get_msg_arg_string(RADIOTEXT_MSGARG_RADIOTYPE, arg, sizeof arg - 1)
if (!equal(arg, g_required_radiotype))
  return PLUGIN_CONTINUE
get_msg_arg_string(RADIOTEXT_MSGARG_CALLERID, arg, sizeof arg - 1)
new caller = str_to_num(arg)
if (!is_user_alive(caller))
  return PLUGIN_CONTINUE
new clip, ammo, weapon
weapon = get_user_weapon(caller, clip, ammo)
for (new i; i < sizeof g_grenade_weaponid; ++i) {
  if (g_grenade_weaponid == weapon) {
   static text[192]
   new pos = 0
   text[pos++] = g_color_code[COLOR_NORMAL]
   get_msg_arg_string(RADIOTEXT_MSGARG_CALLERNAME, arg, sizeof arg - 1)
   pos += formatex(text[pos], sizeof text - pos - 1, g_radiotext_template, arg)
   copy(text[++pos], sizeof text - pos - 1, g_grenade_description)
   new desccolor = g_grenade_desccolor
   if ((text[--pos] = g_color_code[desccolor]) == COLORCODE_TEAM) {
    static teamname[12]
    get_user_team(id, teamname, sizeof teamname - 1)
    if (!equal(teamname, g_color_teamname[desccolor])) {
     msg_teaminfo(id, g_color_teamname[desccolor])
     msg_saytext(id, text)
     msg_teaminfo(id, teamname)
     return PLUGIN_HANDLED
    }
   }
   msg_saytext(id, text)
   return PLUGIN_HANDLED
  }
}
return PLUGIN_CONTINUE
}
msg_teaminfo(id, teamname[]) {
message_begin(MSG_ONE, g_msgid_teaminfo, _, id)
write_byte(id)
write_string(teamname)
message_end()
}
msg_saytext(id, text[]) {
message_begin(MSG_ONE, g_msgid_saytext, _, id)
write_byte(id)
write_string(text)
message_end()
}
[/PHP]

你试下吧,我这里也用了,没有问题的。
回复

使用道具 举报

发表于 2008-2-10 15:37:37 | 显示全部楼层 来自 江苏南京
提示: 作者被禁止或删除 内容自动屏蔽
回复

使用道具 举报

发表于 2008-2-10 15:42:11 | 显示全部楼层 来自 江苏南京
提示: 作者被禁止或删除 内容自动屏蔽
回复

使用道具 举报

 楼主| 发表于 2008-2-10 15:47:29 | 显示全部楼层 来自 云南西双版纳州景洪

回复: Rulzy版主你什么时候能讲解下最新的颜色信息

难道不用增加颜色代码名字?
enum color {
COLOR_NORMAL,
COLOR_RED,
COLOR_BLUE,
COLOR_GRAY,
COLOR_GREEN
}
回复

使用道具 举报

发表于 2008-2-10 16:00:02 | 显示全部楼层 来自 江苏南京
提示: 作者被禁止或删除 内容自动屏蔽
回复

使用道具 举报

 楼主| 发表于 2008-2-10 16:09:58 | 显示全部楼层 来自 云南西双版纳州景洪

回复: Rulzy版主你什么时候能讲解下最新的颜色信息

比如说显示玩家连接服务器时候提示
【玩家】用绿色
【管理员OP】用红色
【会员VIP】用蓝色
难道代码还象以前一样的用^x03和^x01这样的写吗?是不是这样它就能自动指定使用颜色!还是有点没搞懂你说的那些.能不能说明白点谢谢了
回复

使用道具 举报

发表于 2008-2-10 17:26:03 | 显示全部楼层 来自 江苏南京
提示: 作者被禁止或删除 内容自动屏蔽
回复

使用道具 举报

游客
回复
您需要登录后才可以回帖 登录 | 注个册吧

快速回复 返回顶部 返回列表