Advertisement
yvoms

Item Swapper

Nov 9th, 2014
473
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.07 KB | None | 0 0
  1. /* Item swapper
  2. Created by yvoms & Rochet2, enjoy the swapper.
  3. Please do not alter the credits.
  4. */
  5. struct tokenData {uint32 TAKE_ENTRY, TAKE_AMOUNT, GIVE_ENTRY, GIVE_AMOUNT; };
  6. struct tokenData Tokens[] =
  7. {
  8. //  {TAKE_ENTRY, TAKE_AMOUNT, GIVE_ENTRY, GIVE_AMOUNT},
  9. // Make a custom structure, so for example.
  10.  
  11.     //this takes itemid 50 and gives itemid 62 in return
  12.         {50, 1, 62, 1},
  13.     //you can also take 5000 and give itemid 62 back 1000 times.
  14.         {50, 500, 62, 1000},
  15.     //And so on
  16.         {50, 500, 62, 1000},
  17.         {50, 1000, 62, 2000},
  18.         {50, 1500, 62, 3000},
  19.         {50, 2500, 62, 5000},
  20.         {50, 5000, 62, 10000},
  21.         {50, 10000, 62, 20000},
  22.         {50, 100000, 62, 200000},
  23.     //The above takes an item, and gives a different item back in a higher quantity.
  24.     //its also possible to do it in negatives.
  25.     {62, 1000, 50, 500},
  26.     {62, 2500, 50, 1250},
  27.     {62, 5000, 50, 2500},
  28.     {62, 10000, 50, 5000},
  29.     {62, 50000, 50, 25000},
  30. /*
  31. This is all up to you you can do whatever u want with it.
  32. Enjoy :)
  33. */ 
  34.  
  35. };
  36.  
  37. const uint32 tokensSize = sizeof Tokens/sizeof(*Tokens);
  38. #include "ScriptPCH.h"
  39.  
  40. class CustomSwapItems : public CreatureScript
  41. {
  42. public:
  43.     CustomSwapItems() : CreatureScript("CustomSwapItems") { }
  44.  
  45.     std::string GetName(uint32 entry)
  46.     {
  47.         return sObjectMgr->GetItemTemplate(entry)->Name1;
  48.     }
  49.  
  50.     bool OnGossipHello(Player* player, Creature* creature)
  51.     {
  52.         for (uint32 i = 0; i < tokensSize; ++i)
  53.         {
  54.             std::ostringstream ss;
  55.             // Swap 50 x Token to 10 x token2 (names set automatically)
  56.             ss << "Swap " << Tokens[i].TAKE_AMOUNT << " x " << GetName(Tokens[i].TAKE_ENTRY) << " to " << Tokens[i].GIVE_AMOUNT << " x " << GetName(Tokens[i].GIVE_ENTRY);
  57.             player->ADD_GOSSIP_ITEM_EXTENDED(0, ss.str(), GOSSIP_SENDER_MAIN, i, "Are you sure?", 0, false);
  58.         }
  59.         player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
  60.         return true;
  61.     }
  62.  
  63.     bool OnGossipSelect(Player* player, Creature* creature, uint32 sender, uint32 action)
  64.     {
  65.         player->PlayerTalkClass->ClearMenus();
  66.         if(sender == GOSSIP_SENDER_MAIN && action < tokensSize)
  67.         {
  68.             if(player->HasItemCount(Tokens[action].TAKE_ENTRY, Tokens[action].TAKE_AMOUNT))
  69.             {
  70.                 if(player->AddItem(Tokens[action].GIVE_ENTRY, Tokens[action].GIVE_AMOUNT))
  71.                 {
  72.                     player->DestroyItemCount(Tokens[action].TAKE_ENTRY, Tokens[action].TAKE_AMOUNT, true);
  73.                     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());
  74.                 }
  75.             }
  76.             else
  77.                 player->GetSession()->SendNotification("You need at least %u x %ss", Tokens[action].TAKE_AMOUNT, GetName(Tokens[action].TAKE_ENTRY).c_str());
  78.         }
  79.         OnGossipHello(player, creature);
  80.         return true;
  81.     }
  82. };
  83.  
  84. void AddSC_CustomSwapItems()
  85. {
  86.     new CustomSwapItems();
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement