Advertisement
Rochet2

Token swapper

Jan 4th, 2013
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.35 KB | None | 0 0
  1. struct tokenData {uint32 TAKE_ENTRY, TAKE_AMOUNT, GIVE_ENTRY, GIVE_AMOUNT; };
  2. struct tokenData Tokens[] =
  3. {
  4. //  {TAKE_ENTRY, TAKE_AMOUNT, GIVE_ENTRY, GIVE_AMOUNT},
  5.     {60000, 50000, 60033, 1},
  6.     {60000, 50000, 60033, 1},
  7.     {60000, 50000, 60033, 1},
  8.     {60000, 50000, 60033, 1},
  9. };
  10.  
  11. const uint32 tokensSize = sizeof Tokens/sizeof(*Tokens);
  12. #include "ScriptPCH.h"
  13.  
  14. class CustomSwapItems : public CreatureScript
  15. {
  16. public:
  17.     CustomSwapItems() : CreatureScript("CustomSwapItems") { }
  18.  
  19.     std::string GetName(uint32 entry)
  20.     {
  21.         return sObjectMgr->GetItemTemplate(entry)->Name1;
  22.     }
  23.  
  24.     bool OnGossipHello(Player* player, Creature* creature)
  25.     {
  26.         for (uint32 i = 0; i < tokensSize; ++i)
  27.         {
  28.             std::ostringstream ss;
  29.             // Swap 50 x Token to 10 x token2 (names set automatically)
  30.             ss << "Swap " << Tokens[i].TAKE_AMOUNT << " x " << GetName(Tokens[i].TAKE_ENTRY) << " to " << Tokens[i].GIVE_AMOUNT << " x " << GetName(Tokens[i].GIVE_ENTRY);
  31.             player->ADD_GOSSIP_ITEM_EXTENDED(0, ss.str(), GOSSIP_SENDER_MAIN, i, "Are you sure?", 0, false);
  32.         }
  33.         player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
  34.         return true;
  35.     }
  36.  
  37.     bool OnGossipSelect(Player* player, Creature* creature, uint32 sender, uint32 action)
  38.     {
  39.         player->PlayerTalkClass->ClearMenus();
  40.         if(sender == GOSSIP_SENDER_MAIN && action < tokensSize)
  41.         {
  42.             if(player->HasItemCount(Tokens[action].TAKE_ENTRY, Tokens[action].TAKE_AMOUNT))
  43.             {
  44.                 if(player->AddItem(Tokens[action].GIVE_ENTRY, Tokens[action].GIVE_AMOUNT))
  45.                 {
  46.                     player->DestroyItemCount(Tokens[action].TAKE_ENTRY, Tokens[action].TAKE_AMOUNT, true);
  47.                     player->GetSession()->SendAreaTriggerMessage("%u x %s swapped to %u x %s", Tokens[action].TAKE_AMOUNT, GetName(Tokens[action].TAKE_ENTRY).c_str(), Tokens[action].GIVE_AMOUNT, GetName(Tokens[action].GIVE_ENTRY).c_str());
  48.                 }
  49.             }
  50.             else
  51.                 player->GetSession()->SendNotification("You need at least %u x %ss", Tokens[action].TAKE_AMOUNT, GetName(Tokens[action].TAKE_ENTRY).c_str());
  52.         }
  53.         OnGossipHello(player, creature);
  54.         return true;
  55.     }
  56. };
  57.  
  58. void AddSC_CustomSwapItems()
  59. {
  60.     new CustomSwapItems();
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement