Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "ScriptMgr.h"
- class example_votepoint_gossip : public CreatureScript
- {
- public:
- example_votepoint_gossip() : CreatureScript("example_votepoint_gossip") { }
- bool OnGossipHello(Player* player, Creature* creature)
- {
- player->ADD_GOSSIP_ITEM_EXTENDED(GOSSIP_ICON_CHAT, "Change 1 vote point for 1 copper", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+1, "Are you sure?", 0, false);
- player->ADD_GOSSIP_ITEM_EXTENDED(GOSSIP_ICON_CHAT, "Change 10 vote points for 10 copper", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+2, "Are you sure?", 0, false);
- player->PlayerTalkClass->SendGossipMenu(DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
- return true;
- }
- bool OnGossipSelect(Player* player, Creature* creature, uint32 sender, uint32 action)
- {
- player->PlayerTalkClass->ClearMenus();
- switch(action)
- {
- case GOSSIP_ACTION_INFO_DEF+1:
- {
- if(SpendVotePoints(1, player)) // 1 is the amount of votepoints spent
- {
- // this is executed if the votepoints are succesfully spent
- player->ModifyMoney(1);
- }
- } break;
- case GOSSIP_ACTION_INFO_DEF+2:
- {
- if(SpendVotePoints(10, player)) // 10 is the amount of votepoints spent
- {
- // this is executed if the votepoints are succesfully spent
- player->ModifyMoney(10);
- }
- } break;
- }
- OnGossipHello(player, creature); // return to Gossip hello (main menu)
- return true;
- }
- private:
- bool SpendVotePoints(uint32 amount, Player* player) // custom function
- {
- QueryResult result = WorldDatabase.PQuery("SELECT points FROM votepoints WHERE account = %u", player->GetSession()->GetAccountId());
- if(!result) // no votepoints or no record found
- {
- player->GetSession()->SendNotification("Not enough vote points");
- return false;
- }
- uint32 votepoints = result->Fetch()[0].GetUInt32();
- if(votepoints < amount) // vote point amount smaller than amount we spend
- {
- player->GetSession()->SendNotification("Not enough vote points");
- return false;
- }
- WorldDatabase.PExecute("UPDATE votepoints SET points = points-%u WHERE account = %u", amount, player->GetSession()->GetAccountId());
- player->GetSession()->SendAreaTriggerMessage("Vote points used succesfully");
- return true;
- }
- };
- void AddSC_example_votepoint_gossip()
- {
- new example_votepoint_gossip();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement