Advertisement
Rochet2

Title giver

Nov 17th, 2013
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. struct HonorGossip
  2. {
  3.     uint8 icon;
  4.     std::string name;
  5.     uint32 HK, titleID;
  6. };
  7.  
  8. // {icon, "title name", honored_kills, titleID}
  9. HonorGossip Titles [] =
  10. {
  11.     {9, "Private", 1, 1 },
  12.     {9, "Corporal", 100, 2 },
  13.     {9, "Sergeant", 250, 3 },
  14.     {9, "Master Sergeant", 500, 4 },
  15.     {9, "Sergeant Major", 750, 5 },
  16.     {9, "Knight", 1000, 6 },
  17.     {9, "Knight-Lieutenant", 1500, 7 },
  18.     {9, "Knight-Captain", 2000, 8 },
  19.     {9, "Knight-Champion", 2500, 9 },
  20.     {9, "Lieutenant Commander", 3000, 10 },
  21.     {9, "Commander", 3500, 11 },
  22.     {9, "Marshal", 4000, 12 },
  23.     {9, "Field Marshal", 4500, 13 },
  24.     {9, "Grand Marshal", 5000, 14 },
  25.  
  26.     {9, "Scout", 1, 15 },
  27.     {9, "Grunt", 100, 16 },
  28.     {9, "Sergeant", 250, 17 },
  29.     {9, "Senior Sergeant", 500, 18 },
  30.     {9, "First Sergeant", 750, 19 },
  31.     {9, "Stone Guard", 1000, 20 },
  32.     {9, "Blood Guard", 1500, 21 },
  33.     {9, "Legionnaire", 2000, 22 },
  34.     {9, "Centurion", 2500, 23 },
  35.     {9, "Champion", 3000, 24 },
  36.     {9, "Lieutenant General", 3500, 25 },
  37.     {9, "General", 4000, 26 },
  38.     {9, "Warlord", 4500, 27 },
  39.     {9, "High Warlord", 5000, 28 },
  40. };
  41. static const uint32 TITLES_SIZE = (sizeof(Titles) / sizeof(*Titles)); // NOTE, this was wrong. it was uint32 instead of *Titles or HonorGossip in the sizeof.
  42.  
  43. class npc_honor_gossip : public CreatureScript
  44. {
  45. public:
  46.     npc_honor_gossip() : CreatureScript("npc_honor_gossip") { }
  47.  
  48.     bool OnGossipHello(Player* player, Creature* creature)
  49.     {
  50.         player->ADD_GOSSIP_ITEM(0, "|TInterface\\icons\\INV_Misc_QuestionMark:30|tHow does this npc work?|r", GOSSIP_SENDER_MAIN, 100);
  51.         player->ADD_GOSSIP_ITEM(4, "|TInterface\\icons\\Achievement_PVP_H_15:30|tHonorable Kills Titles|r", GOSSIP_SENDER_MAIN, 101);
  52.         player->ADD_GOSSIP_ITEM(7, "|TInterface\\icons\\Ability_Spy:30|tNevermind|r", GOSSIP_SENDER_MAIN, 102);
  53.         player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
  54.         return true;
  55.     }
  56.  
  57.     bool OnGossipSelect(Player* player, Creature* creature, uint32 /* sender */, uint32 actions)
  58.     {
  59.         player->PlayerTalkClass->ClearMenus();
  60.         if (actions == 100)
  61.         {
  62.             ChatHandler(player->GetSession()).SendSysMessage("|cffff6060[Information]:|r This npc show you 2 different options,Honorable Kills Titles costed on LifeTime Kills,Devium WoW Titles show you our own titles |cffff0000[Patch Required]|r,and costed on [Devium Title Token].");
  63.             OnGossipHello(player, creature);
  64.         }
  65.         else if(actions == 101)
  66.         {
  67.             if (player->GetTeamId() == ALLIANCE)
  68.                 for (int i = 0; i < TITLES_SIZE/2; ++i)
  69.                     player->ADD_GOSSIP_ITEM(Titles[i].icon, Titles[i].name.c_str(), GOSSIP_SENDER_MAIN, i);
  70.             else
  71.                 for (int i = TITLES_SIZE/2; i < TITLES_SIZE; ++i)
  72.                     player->ADD_GOSSIP_ITEM(Titles[i].icon, Titles[i].name.c_str(), GOSSIP_SENDER_MAIN, i);
  73.             player->ADD_GOSSIP_ITEM(GOSSIP_ICON_DOT, "<- Back", GOSSIP_SENDER_MAIN, 999);
  74.             player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
  75.         }
  76.         else if (actions == 102)
  77.             player->CLOSE_GOSSIP_MENU();
  78.         else if (actions == 999) // NOTE main menu, no need to write the options twice, use the function like this.
  79.             OnGossipHello(player, creature);
  80.         else if (actions < TITLES_SIZE) // must check so we wont accidently go overboard
  81.         {
  82.             if (player->HasTitle(Titles[actions].titleID))
  83.                 player->GetSession()->SendNotification("You already have this title!");
  84.             else if (player->GetUInt32Value(PLAYER_FIELD_LIFETIME_HONORABLE_KILLS) < Titles[actions].HK)
  85.                 player->GetSession()->SendNotification("You don't have enough kills!");
  86.             else if (CharTitlesEntry const* titleEntry = sCharTitlesStore.LookupEntry(Titles[actions].titleID))
  87.             {
  88.                 player->SetTitle(titleEntry);
  89.                 player->GetSession()->SendAreaTriggerMessage("Title granted!");
  90.             }
  91.             OnGossipHello(player, creature);
  92.         }
  93.         return true; // NOTE always return true, unless you want to send the default gossip menu from DB
  94.     }
  95. };
  96.  
  97. void AddSC_honor_gossip()
  98. {
  99.     new npc_honor_gossip;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement