[Inc/Stock] PrintF - [R]ak - 21/10/2013
Hola :3 como todos sabrán, existen stock o includes para mandar un mensaje con color, bueno.. no me gusta ninguno así que me arme este xD; soporta todos los colores.. aca les dejo unas imágenes
Código:
#if defined _printf_included
#endinput
#endif
#define _printf_included
enum {
DEFAULT,
RED,
BLUE,
GRAY,
GREEN
}
stock printf(id, color, const msg[], any:...) {
static Buffer[192], MsgSayText, MsgTeamInfo, Team[11]
if(!MsgSayText) {
MsgTeamInfo = get_user_msgid("TeamInfo")
MsgSayText = get_user_msgid("SayText")
}
vformat(Buffer[1], charsmax(Buffer) - 1, msg, 4)
static const Teams[4][11] = {
"UNASSIGNED",
"TERRORIST",
"CT",
"SPECTATOR"
}
if(color) {
if(color == GREEN) {
Buffer[0] = 0x04
printf_do(id, Buffer, MsgSayText)
}
else {
Buffer[0] = 0x03
get_user_team(id, Team, charsmax(Team))
printf_do(id, Teams[color], MsgTeamInfo)
printf_do(id, Buffer, MsgSayText)
printf_do(id, Team, MsgTeamInfo)
}
}
else {
Buffer[0] = 0x01
printf_do(id, Buffer, MsgSayText)
}
}
printf_do(id, const data[], MsgID) {
message_begin(MSG_ONE_UNRELIABLE, MsgID, _, id)
write_byte(id)
write_string(data)
message_end()
}
Código PHP:
enum { DEFAULT, RED , BLUE , GRAY , GREEN } stock printf ( id , color , const msg [], any :...) { static Buffer [ 192 ], MsgSayText , MsgTeamInfo , Team [ 11 ] if(! MsgSayText ) { MsgTeamInfo = get_user_msgid ( "TeamInfo" ) MsgSayText = get_user_msgid ( "SayText" ) } vformat ( Buffer [ 1 ], charsmax ( Buffer ) - 1 , msg , 4 ) static const g_Teams [ 4 ][ 11 ] = { "UNASSIGNED" , "TERRORIST" , "CT" , "SPECTATOR" } if( color ) { if( color == GREEN ) { Buffer [ 0 ] = 0x04 message_begin ( MSG_ONE_UNRELIABLE , MsgSayText , _ , id ) write_byte ( id ) write_string ( Buffer ) message_end () } else { Buffer [ 0 ] = 0x03 get_user_team ( id , Team , charsmax ( Team )) message_begin ( MSG_ONE_UNRELIABLE , MsgTeamInfo , _ , id ) write_byte ( id ) write_string ( g_Teams [ color ]) message_end () message_begin ( MSG_ONE_UNRELIABLE , MsgSayText , _ , id ) write_byte ( id ) write_string ( Buffer ) message_end () message_begin ( MSG_ONE_UNRELIABLE , MsgTeamInfo , _ , id ) write_byte ( id ) write_string ( Team ) message_end () } } else { Buffer [ 0 ] = 0x01 message_begin ( MSG_ONE_UNRELIABLE , MsgSayText , _ , id ) write_byte ( id ) write_string ( Buffer ) message_end () } }
Código PHP:
#include <amxmodx> #include <printf> #define PLUGIN "Test Stock Chat Color" #define VERSION "1.0" #define AUTHOR "[R]ak" public plugin_init () { register_plugin ( PLUGIN , VERSION , AUTHOR ) register_clcmd ( "say test" , "cmdTest" ) register_clcmd ( "say test2" , "cmdTest2" ) } public cmdTest ( id ) { printf ( id , DEFAULT, "%s Acme Inc.- %s" , AUTHOR , PLUGIN ) // comun printf ( id , RED , "%s Acme Inc.- %s" , AUTHOR , PLUGIN ) // rojo printf ( id , BLUE , "%s Acme Inc.- %s" , AUTHOR , PLUGIN ) // azul printf ( id , GRAY , "%s Acme Inc.- %s" , AUTHOR , PLUGIN ) // gris printf ( id , GREEN , "^%s Acme Inc.- %s" , AUTHOR , PLUGIN ) // verde return PLUGIN_HANDLED } public cmdTest2 ( id ) { printf ( id , DEFAULT, "^x04%s^x03 Acme Inc.- ^x01%s" , AUTHOR , PLUGIN ) // comun printf ( id , RED , "^x04%s^x03 Acme Inc.- ^x01%s" , AUTHOR , PLUGIN ) // rojo printf ( id , BLUE , "^x04%s^x03 Acme Inc.- ^x01%s" , AUTHOR , PLUGIN ) // azul printf ( id , GRAY , "^x04%s^x03 Acme Inc.- ^x01%s" , AUTHOR , PLUGIN ) // gris printf ( id , GREEN , "%s^x03 Acme Inc.- ^x01%s" , AUTHOR , PLUGIN ) // verde return PLUGIN_HANDLED }
Código PHP:
#include <amxmodx> #define PLUGIN "Test Stock Chat Color" #define VERSION "1.0" #define AUTHOR "[R]ak" enum { DEFAULT, RED , BLUE , GRAY , GREEN } public plugin_init () { register_plugin ( PLUGIN , VERSION , AUTHOR ) register_clcmd ( "say test" , "cmdTest" ) register_clcmd ( "say test2" , "cmdTest2" ) } public cmdTest ( id ) { printf ( id , DEFAULT, "%s Acme Inc.- %s" , AUTHOR , PLUGIN ) // comun printf ( id , RED , "%s Acme Inc.- %s" , AUTHOR , PLUGIN ) // rojo printf ( id , BLUE , "%s Acme Inc.- %s" , AUTHOR , PLUGIN ) // azul printf ( id , GRAY , "%s Acme Inc.- %s" , AUTHOR , PLUGIN ) // gris printf ( id , GREEN , "^%s Acme Inc.- %s" , AUTHOR , PLUGIN ) // verde return PLUGIN_HANDLED } public cmdTest2 ( id ) { printf ( id , DEFAULT, "^x04%s^x03 Acme Inc.- ^x01%s" , AUTHOR , PLUGIN ) // comun printf ( id , RED , "^x04%s^x03 Acme Inc.- ^x01%s" , AUTHOR , PLUGIN ) // rojo printf ( id , BLUE , "^x04%s^x03 Acme Inc.- ^x01%s" , AUTHOR , PLUGIN ) // azul printf ( id , GRAY , "^x04%s^x03 Acme Inc.- ^x01%s" , AUTHOR , PLUGIN ) // gris printf ( id , GREEN , "%s^x03 Acme Inc.- ^x01%s" , AUTHOR , PLUGIN ) // verde return PLUGIN_HANDLED } stock printf ( id , color , const msg [], any :...) { static Buffer [ 192 ], MsgSayText , MsgTeamInfo , Team [ 11 ] if(! MsgSayText ) { MsgTeamInfo = get_user_msgid ( "TeamInfo" ) MsgSayText = get_user_msgid ( "SayText" ) } vformat ( Buffer [ 1 ], charsmax ( Buffer ) - 1 , msg , 4 ) static const Teams [ 4 ][ 11 ] = { "UNASSIGNED" , "TERRORIST" , "CT" , "SPECTATOR" } if( color ) { if( color == GREEN ) { Buffer [ 0 ] = 0x04 message_begin ( MSG_ONE_UNRELIABLE , MsgSayText , _ , id ) write_byte ( id ) write_string ( Buffer ) message_end () } else { Buffer [ 0 ] = 0x03 get_user_team ( id , Team , charsmax ( Team )) message_begin ( MSG_ONE_UNRELIABLE , MsgTeamInfo , _ , id ) write_byte ( id ) write_string ( Teams [ color ]) message_end () message_begin ( MSG_ONE_UNRELIABLE , MsgSayText , _ , id ) write_byte ( id ) write_string ( Buffer ) message_end () message_begin ( MSG_ONE_UNRELIABLE , MsgTeamInfo , _ , id ) write_byte ( id ) write_string ( Team ) message_end () } } else { Buffer [ 0 ] = 0x01 message_begin ( MSG_ONE_UNRELIABLE , MsgSayText , _ , id ) write_byte ( id ) write_string ( Buffer ) message_end () } }
Saludos :3
RE: [Inc/Stock] PrintF - alan_el_more - 21/10/2013
Estaría bueno si le pudieras agregar soporte para ML
RE: [Inc/Stock] PrintF - r0ma' - 21/10/2013
y soporte para index 0
RE: [Inc/Stock] PrintF - [R]ak - 22/10/2013
(21/10/2013, 11:57 PM) r0ma escribió: y soporte para index 0
haces un loop cuando queres mandarlo a varios users y evitas q ponga un chequeo todo el tiempo
RE: [Inc/Stock] PrintF - Neeeeeeeeeel.- - 22/10/2013
(22/10/2013, 12:58 AM) [R]ak escribió: (21/10/2013, 11:57 PM) r0ma escribió: y soporte para index 0
haces un loop cuando queres mandarlo a varios users y evitas q ponga un chequeo todo el tiempo
Es mejor hacer un if todo el tiempo en vez de un get_players cada vez que querés mandar a todos...
PD: Lo muevo a tutoriales/guias despues creo una sección para incs y porongas así...