I use this as a member function of my plugin's class:
Code:
void ClientMsg(edict_t* pEntity, const unsigned int TIME, const DIALOG_TYPE TYPE, const char* FORMAT, ...) {
tchar szBuf[256];
va_list arg_ptr;
va_start(arg_ptr, FORMAT);
_vsntprintf(szBuf, sizeof(szBuf)-1, FORMAT, arg_ptr);
va_end(arg_ptr);
szBuf[sizeof(szBuf)-1] = 0;
KeyValues *kv = new KeyValues("msg");
kv->SetString("title", szBuf);
kv->SetString("msg", "This is the msg");
kv->SetColor("color", Color(10, 240, 10, 255));
kv->SetInt("level", 5);
kv->SetInt("time", TIME);
helpers->CreateMessage(pEntity, TYPE, kv, this);
kv->deleteThis();
}
Example use:
Code:
ClientMsg(pEntity, 5, DIALOG_MSG, "You have %d turtles", turtlesCount)
Can't be used for console messages though. But it would be easy to make it work for that also, altering the third parameter. Maybe creating a new enum:
Code:
typedef enum
{
MSG_CHAT = 0, // just an on screen message
MSG_MENU, // an options menu
MSG_RICH, // a richtext dialog
MSG_CONSOLE,
} DIALOG_TYPE_EXTENDED;
void ClientMsg(edict_t* pEntity, const unsigned int TIME, const DIALOG_TYPE_EXTENDED TYPE, const char* FORMAT, ...) {
tchar szBuf[256];
va_list arg_ptr;
va_start(arg_ptr, FORMAT);
_vsntprintf(szBuf, sizeof(szBuf)-1, FORMAT, arg_ptr);
va_end(arg_ptr);
switch (TYPE) {
case MSG_CONSOLE: {
szBuf[sizeof(szBuf) - 1] = '\n';
szBuf[sizeof(szBuf)] = 0;
engine->ClientPrintf(pEntity, szBuf);
break;
}
default: {
szBuf[sizeof(szBuf)-1] = 0;
KeyValues *kv = new KeyValues("msg");
kv->SetString("title", szBuf);
kv->SetString("msg", "This is the msg");
kv->SetColor("color", Color(10, 240, 10, 255));
kv->SetInt("level", 5);
kv->SetInt("time", TIME);
helpers->CreateMessage(pEntity, (DIALOG_TYPE)TYPE, kv, this);
kv->deleteThis();
}
}
}