stoneharry

Untitled

May 23rd, 2011
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.59 KB | None | 0 0
  1.  
  2. #include "ScriptPCH.h"
  3. #include <cstring>
  4.  
  5. //This function is called when the player opens the gossip menubool
  6. bool GossipHello_custom_gossip_codebox(Player *player, Creature* pCreature)
  7. {
  8.     player->ADD_GOSSIP_ITEM_EXTENDED(4, "I would like to redeem a code.", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+1, "Your Reward Code:", 0, true);
  9.     player->ADD_GOSSIP_ITEM(0, "Nevermind.", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+2);
  10.  
  11.     player->PlayerTalkClass->SendGossipMenu(907,pCreature->GetGUID());
  12.     return true;
  13. }
  14.  
  15. //This function is called when the player clicks an option on the gossip menubool
  16. bool GossipSelect_custom_gossip_codebox(Player *player, Creature* pCreature, uint32 sender, uint32 action)
  17. {
  18.     if (action == GOSSIP_ACTION_INFO_DEF+2)
  19.     {
  20.         player->CLOSE_GOSSIP_MENU();
  21.     }
  22.     return true;
  23. }
  24.  
  25. bool GossipSelectWithCode_custom_gossip_codebox(Player *player, Creature* pCreature, uint32 sender, uint32 action, const char* sCode)
  26. {
  27.     if (sender == GOSSIP_SENDER_MAIN)
  28.     {
  29.         if (action == GOSSIP_ACTION_INFO_DEF+1)
  30.         {
  31.             std::stringstream ss;
  32.             ss << "SELECT code, reward FROM codelist WHERE code = ";
  33.             ss << sCode;
  34.             ss << ";";
  35.             QueryResult_AutoPtr result = CharacterDatabase.Query(ss.str().c_str());
  36.             if (!result)
  37.             {
  38.                 std::string text = "Invalid code!";
  39.                 WorldPacket data(SMSG_MESSAGECHAT, 200);
  40.                 data << uint8(CHAT_MSG_RAID_WARNING);
  41.                 data << uint32(LANG_UNIVERSAL);
  42.                 data << uint64(player->GetGUID());
  43.                 data << uint32(LANG_UNIVERSAL);
  44.                 data << uint64(player->GetGUID());
  45.                 data << uint32(text.length() + 1);
  46.                 data << text;
  47.                 data << uint8( 0 );
  48.                 //player->whisper
  49.             }
  50.             else
  51.             {
  52.                 result->NextRow();
  53.                 Field *fields = result->Fetch();
  54.                 fields[1].GetString();
  55.                 Item *pItem = new Item;
  56.                 pItem->SetEntry(atoi(fields[1].GetString()));
  57.                 player->SendNewItem(pItem, 1, true, true, true);
  58.                 std::stringstream ss;
  59.                 ss << "DELETE FROM codelist WHERE code = ";
  60.                 ss << sCode;
  61.                 ss << ";";
  62.                 CharacterDatabase.Execute(ss.str().c_str());
  63.             }
  64.             player->CLOSE_GOSSIP_MENU();
  65.             return true;
  66.         }
  67.     }
  68.     return false;
  69. }
  70.  
  71. void AddSC_custom_gossip_codebox()
  72. {
  73.     Script *newscript;
  74.  
  75.     newscript = new Script;
  76.     newscript->Name = "custom_gossip_codebox";
  77.     newscript->pGossipHello =           &GossipHello_custom_gossip_codebox;
  78.     newscript->pGossipSelect =          &GossipSelect_custom_gossip_codebox;
  79.     newscript->pGossipSelectWithCode =  &GossipSelectWithCode_custom_gossip_codebox;
  80.     newscript->RegisterSelf();
  81. }
Advertisement
Add Comment
Please, Sign In to add comment