ChatBlade How To Documentation
How To Add a new Slash Command Function to ChatBlade

Related ChatBlade Classes and functions:  
    CBSlashCommands
    CBCommandMap
    CBData
    CBClientImplementation

 
Summary:  
  Jump to section   Create the new OnCommandXXX() member function in CBSlashCommands to handle your new Slash Command functionality.  
  Jump to section Add the function pointer to CBSlashCommands::InitializeCommandPointerMap().  
  Jump to section Load a CBCommandMap instance containing the function pointer and the typed Slash Commands which invoke it in CBClientImplementation::LoadSlashCommands().  
If the new OnCommandXXX() function needs a new Chat Channel defined see How To Add a Chat Channel for information on adding new Chat Channels to ChatBlade.  
 

 
Details:  
 
Create the new OnCommandXXX() member function in CBSlashCommands.  
     Create a new OnCommandXXX() function header in CBSlashCommands.h.  
Create the new OnCommandXXX() function body in CBSlashCommands.cpp.  
The new function should be declared as static int and take 2 CBSTRING parameters as defined by the ONCOMMANDFUNCTION  typedef.  
Implement the body of the new OnCommandXXX() function to handle the new functionality.  
Sample Code:  
 
Add the function pointer to CBSlashCommands::InitializeCommandPointerMap().  
     Modify the body of CBSlashCommands::InitializeCommandPointerMap() and add in an entry for our new OnCommandXXX() function.  
Call CBData::AddOnCommandFunction() with the name of the Function (its Map Key) and the pointer to the new function.  
This allows CBClientImplementation::LoadSlashCommands() to access the function pointer by supplying the function name.  
Sample Code:  
 
Load a CBCommandMap instance in CBClientImplementation::LoadSlashCommands().  
     CBClientImplementation::LoadSlashCommands() is designed to allow the Developer to load up all the Player typed Slash Commands possible, and the OnCommandXXX() function that each Slash Command should invoke.  
The typed Slash Commands and the function pointer they are associated with are stored in a CBCommandMap instance.  
An array of all the CBCommandMap instances is stored in CBData::vCommandMapArray.  
Developers can add an instance to this array by calling CBData::AddCommandMap().  
CBData::AddCommandMap() should be called from CBClientImplementation::LoadSlashCommands() with a CommandMap representing the new Slash Command function and the typed out Slash Commands which invoke it.  
See CBSampleImplementation::LoadSlashCommands() source for an example.  
Sample Code:  
 

 

Code Samples:  

Creating a new Slash Command function to handle sending messages to all the current Players in a single Town.  
     Modify CBSlashCommands.h
     // Command invoked when a user types a message all the Players in the same Town or City
// Typical commands include /town, /city
// Examples:
//  /town Anyone want a free Bag of Storage?  
//  Sends a message to all Characters in the current City
static int OnCommandTownChat(CBSTRING sCommand, CBSTRING sCommandParameters);
     Modify CBSlashCommands.cpp and add in the new Function Body
     // Command invoked when a user types a message all the Players in the same Town or City
int CBSlashCommands::OnCommandTownChat(CBSTRING sCommand, CBSTRING sCommandParameters)
     {
CBSTRING sTownName;
 
//  Assuming a Developer created function to get the name of the Current Town
sTownName = CBData::pChatHandler->m_ClientImplementation.GetCurrentTownName();
//  Make sure the Player is in a Town currently
if(sTownName == CB_NONE)
     {
//  Inform the Player that they are not currently in a Town
CBData::pChatHandler->AddMessageCommandFeedback(CB_TEXT_NO_TOWN);
return(CB_ERROR_NO_TOWN);
}
return(CBSlashCommands::ProcessAdvancedChannelCommand(sCommandParameters, CB_CHANNEL_TOWN, sTownName, CB_TRUE));
}
 
Add the function pointer to CBSlashCommands::InitializeCommandPointerMap().  
Add the following line to CBSlashCommands::InitializeCommandPointerMap().  
     CBData::AddOnCommandFunction("OnCommandTownChat", CBSlashCommands::OnCommandTownChat);
 
Loading a new Command Map representing the new Town Chat Slash Command which can be invoked by typing "/town" or "/city".    
Add the following lines to CBClientImplementation::LoadSlashCommands().  
     CBCommandMap cbcmTownChatCommandMap;
 
cbcmTownChatCommandMap.SetPointer(CBData::mCommandFunctionPointerMap["OnCommandTownChat"]);
cbcmTownChatCommandMap.AddAlias("/TOWN");
cbcmTownChatCommandMap.AddAlias("/CITY");
 
CBData::AddCommandMap(cbcmTownChatCommandMap);
    
 
    

 

 

 

 

 

 
 
 
 
ChatBlade Copyright Flex Dolphynn