Advertisement
Rochet2

Vote NPC

Sep 24th, 2012
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.66 KB | None | 0 0
  1. #include "ScriptMgr.h"
  2.  
  3. class example_votepoint_gossip : public CreatureScript
  4. {
  5. public:
  6.     example_votepoint_gossip() : CreatureScript("example_votepoint_gossip") { }
  7.  
  8.     bool OnGossipHello(Player* player, Creature* creature)
  9.     {
  10.         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);
  11.         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);
  12.  
  13.         player->PlayerTalkClass->SendGossipMenu(DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
  14.  
  15.         return true;
  16.     }
  17.  
  18.     bool OnGossipSelect(Player* player, Creature* creature, uint32 sender, uint32 action)
  19.     {
  20.         player->PlayerTalkClass->ClearMenus();
  21.  
  22.         switch(action)
  23.         {
  24.         case GOSSIP_ACTION_INFO_DEF+1:
  25.             {
  26.                 if(SpendVotePoints(1, player)) // 1 is the amount of votepoints spent
  27.                 {
  28.                     // this is executed if the votepoints are succesfully spent
  29.                     player->ModifyMoney(1);
  30.                 }
  31.             } break;
  32.         case GOSSIP_ACTION_INFO_DEF+2:
  33.             {
  34.                 if(SpendVotePoints(10, player)) // 10 is the amount of votepoints spent
  35.                 {
  36.                     // this is executed if the votepoints are succesfully spent
  37.                     player->ModifyMoney(10);
  38.                 }
  39.             } break;
  40.         }
  41.  
  42.         OnGossipHello(player, creature); // return to Gossip hello (main menu)
  43.         return true;
  44.     }
  45.  
  46. private:
  47.  
  48.     bool SpendVotePoints(uint32 amount, Player* player) // custom function
  49.     {
  50.         QueryResult result = WorldDatabase.PQuery("SELECT points FROM votepoints WHERE account = %u", player->GetSession()->GetAccountId());
  51.         if(!result) // no votepoints or no record found
  52.         {
  53.             player->GetSession()->SendNotification("Not enough vote points");
  54.             return false;
  55.         }
  56.  
  57.         uint32 votepoints = result->Fetch()[0].GetUInt32();
  58.  
  59.         if(votepoints < amount) // vote point amount smaller than amount we spend
  60.         {
  61.             player->GetSession()->SendNotification("Not enough vote points");
  62.             return false;
  63.         }
  64.  
  65.         WorldDatabase.PExecute("UPDATE votepoints SET points = points-%u WHERE account = %u", amount, player->GetSession()->GetAccountId());
  66.         player->GetSession()->SendAreaTriggerMessage("Vote points used succesfully");
  67.         return true;
  68.     }
  69. };
  70.  
  71. void AddSC_example_votepoint_gossip()
  72. {
  73.     new example_votepoint_gossip();
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement