Difference between revisions of "Clientside UserMessages"

From Valve Developer Community
Jump to: navigation, search
(Created page with 'This code lets you send usermessages to clients completely clientside. (This code only works in the Client project) <source lang="cpp"> #include "cbase.h" #include "usermessages…')
 
m
Line 8: Line 8:
 
#include "tier0/memdbgon.h"
 
#include "tier0/memdbgon.h"
  
CON_COMMAND_F(measure, "Opens the Measure menu", FCVAR_CLIENTCMD_CAN_EXECUTE) {
+
CON_COMMAND_F(test, "TEEEST", FCVAR_CLIENTCMD_CAN_EXECUTE) {
Msg("User Message: \"SayText\"\n");
 
 
 
 
CUtlBuffer msg_data;
 
CUtlBuffer msg_data;
 
msg_data.PutChar(0);
 
msg_data.PutChar(0);
msg_data.PutString("TESTTEST");
+
msg_data.PutString("BAM, SayText");
 
msg_data.PutChar(1);
 
msg_data.PutChar(1);
 
usermessages->DispatchUserMessage(usermessages->LookupUserMessage("SayText"), bf_read(msg_data.Base(), msg_data.TellPut()));
 
usermessages->DispatchUserMessage(usermessages->LookupUserMessage("SayText"), bf_read(msg_data.Base(), msg_data.TellPut()));

Revision as of 10:37, 20 June 2011

This code lets you send usermessages to clients completely clientside. (This code only works in the Client project)

#include "cbase.h"
#include "usermessages.h"
#include "utlbuffer.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"

CON_COMMAND_F(test, "TEEEST", FCVAR_CLIENTCMD_CAN_EXECUTE) {
	CUtlBuffer msg_data;
	msg_data.PutChar(0);
	msg_data.PutString("BAM, SayText");
	msg_data.PutChar(1);
	usermessages->DispatchUserMessage(usermessages->LookupUserMessage("SayText"), bf_read(msg_data.Base(), msg_data.TellPut()));
}