Veteran Member
Join Date: Jul 2006
Location: France (95)
|
02-17-2011
, 06:50
Re: How to write StatusText with green, blue, red colors
|
#3
|
This is not complete, but depending on your needs it could be enough.
Don't send the same message at few players, or change only 1 player name ;)
PHP Code:
/* Formatright © 2010, ConnorMcLeod
This plugin 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.
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 plugin; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include <amxmodx>
#include <fakemeta>
#define VERSION "0.0.1"
#define PLUGIN "StatusText Color"
enum _:mRestoreDatas {
m_szName[32],
m_szTeamName[11]
}
enum iColors {
GREY,
RED,
BLUE
}
new const g_szTeamNames[][] = {
"UNASSIGNED",
"TERRORIST",
"CT"
}
new gmsgStatusValue, gmsgStatusText, gmsgTeamInfo
public plugin_init()
{
register_plugin(PLUGIN, VERSION, "ConnorMcLeod")
register_clcmd("say", "HostSay")
gmsgStatusValue = get_user_msgid("StatusValue")
gmsgStatusText = get_user_msgid("StatusText")
gmsgTeamInfo = get_user_msgid("TeamInfo")
}
public HostSay( id )
{
new szSaid[192]
read_args(szSaid, charsmax(szSaid))
remove_quotes(szSaid)
if( szSaid[0] == '!' )
{
new iColors:iColor, bool:bColorTag = true
switch( szSaid[1] )
{
case 'g':iColor = GREY
case 'r':iColor = RED
case 'b':iColor = BLUE
default:bColorTag = false
}
client_print_status(id, iColor, szSaid[bColorTag ? 2 : 1])
}
return PLUGIN_CONTINUE
}
client_print_status( id, iColors:iColor = GREY, const fmt[], any:... )
{
if( task_exists(id) )
{
change_task(id, 0.1)
}
else
{
new mDatas[mRestoreDatas]
get_user_name(id, mDatas[m_szName], charsmax(mDatas[m_szName]))
get_user_team(id, mDatas[m_szTeamName], charsmax(mDatas[m_szTeamName]))
set_task(0.1, "Restore_Player", id, mDatas, mRestoreDatas)
}
new szMessage[192], iLen
iLen = vformat(szMessage, charsmax(szMessage), fmt, 4)
new szFakeName[32]
copy(szFakeName, charsmax(szFakeName), szMessage)
set_user_info(id, "name", szFakeName)
set_pev(id, pev_netname, szFakeName) // don't send SayText msg
TeamInfo(id, g_szTeamNames[iColor])
if( iLen > 31 )
{
format(szMessage, charsmax(szMessage), "%%p%s", szMessage[31])
}
else
{
formatex(szMessage, charsmax(szMessage), "%%p")
}
StatusText(id, szMessage)
StatusValue(id, 1, 2)
StatusValue(id, 2, id)
Set_Timers(id)
}
public Restore_Player(mDatas[], id)
{
set_user_info(id, "name", mDatas[m_szName])
set_pev(id, pev_netname, mDatas[m_szName])
TeamInfo(id, mDatas[m_szTeamName])
}
StatusValue(id, iFlag, iValue)
{
message_begin(MSG_ONE, gmsgStatusValue, .player=id)
{
write_byte(iFlag)
write_short(iValue)
}
message_end()
}
StatusText( id , const szText[] )
{
message_begin(MSG_ONE, gmsgStatusText, .player=id)
{
write_byte(0)
write_string(szText)
}
message_end()
}
Set_Timers(id, Float:flDelay = 2.0)
{
#define XO_PLAYER 5
// #define m_izSBarState_SBAR_ID_TARGETCLASS 446
// #define m_izSBarState_SBAR_ID_TARGETNAME 447
// #define m_izSBarState_SBAR_ID_TARGETHEALTH 448
#define m_flNextSBarUpdateTime 449
// #define m_flStatusBarDisappearDelay 450
#define m_SbarString0 451
// set_pdata_int(id, m_izSBarState_SBAR_ID_TARGETCLASS, 0, XO_PLAYER)
// set_pdata_int(id, m_izSBarState_SBAR_ID_TARGETNAME, 0, XO_PLAYER)
// set_pdata_int(id, m_izSBarState_SBAR_ID_TARGETHEALTH, 0, XO_PLAYER)
set_pdata_float(id, m_flNextSBarUpdateTime, get_gametime() + flDelay, XO_PLAYER)
// set_pdata_float(id, m_flStatusBarDisappearDelay, flHoldTime, XO_PLAYER)
set_pdata_int(id, m_SbarString0, 0, XO_PLAYER)
set_task(flDelay, "ResetStatusText", id + 32)
}
public ResetStatusText( id )
{
id -= 32
if( !get_pdata_int(id, 451) )
{
StatusText(id, "")
}
}
TeamInfo(id, szTeam[])
{
message_begin(MSG_ONE, gmsgTeamInfo, .player=id)
{
write_byte(id)
write_string(szTeam)
}
message_end()
}
__________________
|
|