Advertisement
yvoms

Item Swapper Blank

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