Advertisement
yvoms

Swapper

Jan 8th, 2013
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.79 KB | None | 0 0
  1. /*  
  2.     -Souls -
  3.     soul =     60000
  4.     10.000   = 60020
  5.     30.000   = 60021
  6.     50.000   = 60022
  7.     100.000 =  60027
  8.  
  9.     -Unholy-
  10.     emblem =    60004
  11.     10.000   =  60023
  12.     30.000   =  60024
  13.     50.000   =  60025
  14.     100.000 =   60026
  15.  
  16.     -Demon head-
  17.     dem  =     60005
  18.     50.000   = 60033
  19.  
  20. */
  21. struct tokenData {uint32 TAKE_ENTRY, TAKE_AMOUNT, GIVE_ENTRY, GIVE_AMOUNT; };
  22. struct tokenData Tokens[] =
  23. {
  24. //  {TAKE_ENTRY, TAKE_AMOUNT, GIVE_ENTRY, GIVE_AMOUNT},
  25.  
  26.     //Souls
  27.     {60000, 10000, 60020, 1},
  28.     {60000, 30000, 60021, 1},
  29.     {60000, 50000, 60022, 1},
  30.     {60000, 100000, 60027, 1},
  31.     //Unholy
  32.     {60004, 10000, 60023, 1},
  33.     {60004, 30000, 60024, 1},
  34.     {60004, 50000, 60025, 1},
  35.     {60004, 100000, 60026, 1},
  36.     //demon
  37.     {60005, 50000, 60033, 1},
  38.  
  39.  
  40. };
  41.  
  42. const uint32 tokensSize = sizeof Tokens/sizeof(*Tokens);
  43. #include "ScriptPCH.h"
  44.  
  45. class CustomSwapItems : public CreatureScript
  46. {
  47. public:
  48.     CustomSwapItems() : CreatureScript("CustomSwapItems") { }
  49.  
  50.     std::string GetName(uint32 entry)
  51.     {
  52.         return sObjectMgr->GetItemTemplate(entry)->Name1;
  53.     }
  54.  
  55.     bool OnGossipHello(Player* player, Creature* creature)
  56.     {
  57.         for (uint32 i = 0; i < tokensSize; ++i)
  58.         {
  59.             std::ostringstream ss;
  60.             // Swap 50 x Token to 10 x token2 (names set automatically)
  61.             ss << "Swap " << Tokens[i].TAKE_AMOUNT << " x " << GetName(Tokens[i].TAKE_ENTRY) << " to " << Tokens[i].GIVE_AMOUNT << " x " << GetName(Tokens[i].GIVE_ENTRY);
  62.             player->ADD_GOSSIP_ITEM_EXTENDED(0, ss.str(), GOSSIP_SENDER_MAIN, i, "Are you sure?", 0, false);
  63.         }
  64.         player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
  65.         return true;
  66.     }
  67.  
  68.     bool OnGossipSelect(Player* player, Creature* creature, uint32 sender, uint32 action)
  69.     {
  70.         player->PlayerTalkClass->ClearMenus();
  71.         if(sender == GOSSIP_SENDER_MAIN && action < tokensSize)
  72.         {
  73.             if(player->HasItemCount(Tokens[action].TAKE_ENTRY, Tokens[action].TAKE_AMOUNT))
  74.             {
  75.                 if(player->AddItem(Tokens[action].GIVE_ENTRY, Tokens[action].GIVE_AMOUNT))
  76.                 {
  77.                     player->DestroyItemCount(Tokens[action].TAKE_ENTRY, Tokens[action].TAKE_AMOUNT, true);
  78.                     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());
  79.                 }
  80.             }
  81.             else
  82.                 player->GetSession()->SendNotification("You need at least %u x %ss", Tokens[action].TAKE_AMOUNT, GetName(Tokens[action].TAKE_ENTRY).c_str());
  83.         }
  84.         OnGossipHello(player, creature);
  85.         return true;
  86.     }
  87. };
  88.  
  89. void AddSC_CustomSwapItems()
  90. {
  91.     new CustomSwapItems();
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement