AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Coding MM:S Plugins & SM Extensions (https://forums.alliedmods.net/forumdisplay.php?f=75)
-   -   Sending say's Area Text (https://forums.alliedmods.net/showthread.php?t=36852)

BeetleFart 12-06-2004 13:57

Sending say's Area Text
 
Does anyone know how to send text to a client that will display in the
say text area?

i dont think the helpers->CreateMessage( pEntity, DIALOG_MSG, kv, this ); does this.

Johnny got his gun 12-06-2004 16:25

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();
                        }
                }
        }



All times are GMT -4. The time now is 22:11.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.