Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "ScriptPCH.h"
- #include <cstring>
- //This function is called when the player opens the gossip menubool
- bool GossipHello_custom_gossip_codebox(Player *player, Creature* pCreature)
- {
- 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);
- player->ADD_GOSSIP_ITEM(0, "Nevermind.", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+2);
- player->PlayerTalkClass->SendGossipMenu(907,pCreature->GetGUID());
- return true;
- }
- //This function is called when the player clicks an option on the gossip menubool
- bool GossipSelect_custom_gossip_codebox(Player *player, Creature* pCreature, uint32 sender, uint32 action)
- {
- if (action == GOSSIP_ACTION_INFO_DEF+2)
- {
- player->CLOSE_GOSSIP_MENU();
- }
- return true;
- }
- bool GossipSelectWithCode_custom_gossip_codebox(Player *player, Creature* pCreature, uint32 sender, uint32 action, const char* sCode)
- {
- if (sender == GOSSIP_SENDER_MAIN)
- {
- if (action == GOSSIP_ACTION_INFO_DEF+1)
- {
- std::stringstream ss;
- ss << "SELECT code, reward FROM codelist WHERE code = ";
- ss << sCode;
- ss << ";";
- QueryResult_AutoPtr result = CharacterDatabase.Query(ss.str().c_str());
- if (!result)
- {
- std::string text = "Invalid code!";
- WorldPacket data(SMSG_MESSAGECHAT, 200);
- data << uint8(CHAT_MSG_RAID_WARNING);
- data << uint32(LANG_UNIVERSAL);
- data << uint64(player->GetGUID());
- data << uint32(LANG_UNIVERSAL);
- data << uint64(player->GetGUID());
- data << uint32(text.length() + 1);
- data << text;
- data << uint8( 0 );
- //player->whisper
- }
- else
- {
- result->NextRow();
- Field *fields = result->Fetch();
- fields[1].GetString();
- Item *pItem = new Item;
- pItem->SetEntry(atoi(fields[1].GetString()));
- player->SendNewItem(pItem, 1, true, true, true);
- std::stringstream ss;
- ss << "DELETE FROM codelist WHERE code = ";
- ss << sCode;
- ss << ";";
- CharacterDatabase.Execute(ss.str().c_str());
- }
- player->CLOSE_GOSSIP_MENU();
- return true;
- }
- }
- return false;
- }
- void AddSC_custom_gossip_codebox()
- {
- Script *newscript;
- newscript = new Script;
- newscript->Name = "custom_gossip_codebox";
- newscript->pGossipHello = &GossipHello_custom_gossip_codebox;
- newscript->pGossipSelect = &GossipSelect_custom_gossip_codebox;
- newscript->pGossipSelectWithCode = &GossipSelectWithCode_custom_gossip_codebox;
- newscript->RegisterSelf();
- }
Advertisement
Add Comment
Please, Sign In to add comment