Advertisement
EmuDevs

EmuDevs: TrinityCore - CommandScript

Aug 23rd, 2013
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.08 KB | None | 0 0
  1. /*
  2.  *╔═╦═╦═╦╦╦══╦═╦╗─╔╦══╗
  3.  *║╦╣║║║║║╠╗╗║╦╣╚╦╝║══╣
  4.  *║╩╣║║║║║╠╩╝║╩╬╗║╔╬══║
  5.  *╚═╩╩═╩╩═╩══╩═╝╚═╝╚══╝
  6.  *            http://emudevs.com
  7. */
  8.  
  9. class cmd_tutorial : public CommandScript
  10. {
  11. public:
  12.     cmd_tutorial() : CommandScript("cmd_tutorial") { }
  13.  
  14.     ChatCommand* GetCommands() const OVERRIDE
  15.     {
  16.         static ChatCommand commandInfoTable[] =
  17.         {
  18.             { "info",           SEC_PLAYER,         false,  &HandleTestInfoCommand,          "", NULL },
  19.             { "emote",          SEC_PLAYER,         false,  &HandleTestInfoCommand,          "", NULL },
  20.             { NULL,             0,                  false,  NULL,                            "", NULL }
  21.         };
  22.  
  23.         static ChatCommand commandTable[] =
  24.         {
  25.             { "test",           SEC_PLAYER,         false,  &HandleTestCommand,              "", commandInfoTable },
  26.             { NULL,             0,                  false,  NULL,                            "", NULL }
  27.         };
  28.         return commandTable;
  29.     }
  30.  
  31.     static bool HandleTestCommand(ChatHandler* handler, const char* /* args */)
  32.     {
  33.         Player* player = handler->GetSession()->GetPlayer();
  34.         if (!player)
  35.             return false;
  36.         return true;
  37.     }
  38.  
  39.     static bool HandleTestInfoCommand(ChatHandler* handler, const char* args)
  40.     {
  41.         if (!*args)
  42.             return false;
  43.  
  44.         Player* player = handler->GetSession()->GetPlayer();
  45.         if (!player)
  46.             return false;
  47.  
  48.         char* arg1 = strtok((char*)args, " ");
  49.         char* arg2 = strtok((char*)NULL, "");
  50.  
  51.         if (!arg1 || !arg2)
  52.             return false;
  53.  
  54.         uint32 itemId = (uint32)atoi(arg1);
  55.         uint32 itemCount = (uint32)atoi(arg2);
  56.  
  57.         if (!itemId || itemCount)
  58.             return false;
  59.  
  60.         player->AddItem(itemId, itemCount);
  61.         return true;
  62.     }
  63. };
  64.  
  65. void AddSC_custom_thing()
  66. {
  67.     new cmd_tutorial();
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement