stoneharry

Untitled

May 23rd, 2011
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.62 KB | None | 0 0
  1. #include "ScriptPCH.h"
  2. #include <cstring>
  3.  
  4. //This function is called when the player opens the gossip menubool
  5. bool GossipHello_custom_gossip_codebox(Player *player, Creature* pCreature)
  6. {
  7.     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);
  8.     player->ADD_GOSSIP_ITEM(0, "Nevermind.", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+2);
  9.  
  10.     player->PlayerTalkClass->SendGossipMenu(907,pCreature->GetGUID());
  11.     return true;
  12. }
  13.  
  14. //This function is called when the player clicks an option on the gossip menubool
  15. bool GossipSelect_custom_gossip_codebox(Player *player, Creature* pCreature, uint32 sender, uint32 action)
  16. {
  17.     if (action == GOSSIP_ACTION_INFO_DEF+2)
  18.     {
  19.         player->CLOSE_GOSSIP_MENU();
  20.     }
  21.     return true;
  22. }
  23.  
  24. bool GossipSelectWithCode_custom_gossip_codebox(Player *player, Creature* pCreature, uint32 sender, uint32 action, const char* sCode)
  25. {
  26.     if (sender == GOSSIP_SENDER_MAIN)
  27.     {
  28.         if (action == GOSSIP_ACTION_INFO_DEF+1)
  29.         {
  30.             std::stringstream ss;
  31.             ss << "SELECT code, reward FROM codelist WHERE code = '";
  32.             ss << sCode;
  33.             ss << "';";
  34.             QueryResult_AutoPtr result = CharacterDatabase.Query(ss.str().c_str());
  35.             if (!result)
  36.             {
  37.                 std::string text = "Invalid code!";
  38.                 WorldPacket data(SMSG_MESSAGECHAT, 200);
  39.                 data << uint8(CHAT_MSG_RAID_WARNING);
  40.                 data << uint32(LANG_UNIVERSAL);
  41.                 data << uint64(player->GetGUID());
  42.                 data << uint32(LANG_UNIVERSAL);
  43.                 data << uint64(player->GetGUID());
  44.                 data << uint32(text.length() + 1);
  45.                 data << text;
  46.                 data << uint8( 0 );
  47.                 player->SendPacket(data);
  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