Advertisement
julienanid

[Trinity] Points for Tokens

Sep 26th, 2013
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.42 KB | None | 0 0
  1. /*
  2. <--------------------------------------------------------------------------->
  3. - Developer(s): Mthsena
  4. - Complete: %100
  5. - ScriptName: 'Donor_Voter_Trader'
  6. - Comment: Untested
  7. - Shared for: Emudevs
  8. <--------------------------------------------------------------------------->
  9. */
  10.  
  11. #include "ScriptPCH.h"
  12.  
  13. enum Tokens
  14. {
  15.     DONOR_TOKEN = 24581, // Your token ID, Default: Mark of Thrallmar
  16.     VOTER_TOKEN = 24579, // Your token ID, Default: Mark of Honor Hold
  17. };
  18.  
  19. class Donor_Voter_Trader : public CreatureScript
  20. {
  21. public:
  22.     Donor_Voter_Trader() : CreatureScript("Donor_Voter_Trader") { }
  23.  
  24.     bool OnGossipHello(Player *player, Creature *creature)
  25.     {
  26.         player->ADD_GOSSIP_ITEM(0, "[Donor Points]->", GOSSIP_SENDER_MAIN, 1);
  27.         player->ADD_GOSSIP_ITEM(0, "[Voter Points]->", GOSSIP_SENDER_MAIN, 2);
  28.         player->ADD_GOSSIP_ITEM(0, "Show My Points", GOSSIP_SENDER_MAIN, 3);
  29.         player->ADD_GOSSIP_ITEM(4, "Close Window.", GOSSIP_SENDER_MAIN, 10);
  30.         player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());        
  31.         return true;
  32.     }
  33.  
  34.     bool OnGossipSelect(Player *player, Creature *creature, uint32 sender, uint32 uiAction)
  35.     {
  36.         QueryResult select = LoginDatabase.PQuery("SELECT dp, vp FROM account WHERE id = '%u'", player->GetSession()->GetAccountId());
  37.  
  38.         if(!select)
  39.         {
  40.             player->GetSession()->SendAreaTriggerMessage("Internal error!");
  41.             return false;
  42.         }
  43.  
  44.         Field* fields = select->Fetch();
  45.         uint32 dp = fields[0].GetUInt32();
  46.         uint32 vp = fields[1].GetUInt32();
  47.  
  48.         player->PlayerTalkClass->ClearMenus();
  49.  
  50.         if (sender == GOSSIP_SENDER_MAIN)
  51.         {
  52.             switch(uiAction)
  53.             {
  54.             case 1:// Donor Points
  55.                 if (dp == 0)
  56.                 {
  57.                     player->GetSession()->SendAreaTriggerMessage("You don't have none donor point.");
  58.                     player->CLOSE_GOSSIP_MENU();
  59.                     return false;
  60.                 }
  61.  
  62.                 player->ADD_GOSSIP_ITEM_EXTENDED(0, "[1 Point] For [1 Token]", GOSSIP_SENDER_MAIN, 4, "Are you sure?", 0, false);
  63.                 player->ADD_GOSSIP_ITEM_EXTENDED(0, "[10 Points] For [10 Tokens]", GOSSIP_SENDER_MAIN, 5, "Are you sure?", 0, false);
  64.                 player->ADD_GOSSIP_ITEM(4, "...Back", GOSSIP_SENDER_MAIN, 11);
  65.                 player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());  
  66.                 break;
  67.  
  68.             case 2:// Voter Points
  69.                 if (vp == 0)
  70.                 {
  71.                     player->GetSession()->SendAreaTriggerMessage("You don't have none voter point.");
  72.                     player->CLOSE_GOSSIP_MENU();
  73.                     return false;
  74.                 }
  75.  
  76.                 player->ADD_GOSSIP_ITEM_EXTENDED(0, "[1 Point] For [1 Token]", GOSSIP_SENDER_MAIN, 6, "Are you sure?", 0, false);
  77.                 player->ADD_GOSSIP_ITEM_EXTENDED(0, "[10 Points] For [10 Tokens]", GOSSIP_SENDER_MAIN, 7, "Are you sure?", 0, false);
  78.                 player->ADD_GOSSIP_ITEM(4, "...Back", GOSSIP_SENDER_MAIN, 11);
  79.                 player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
  80.                 break;
  81.  
  82.             case 3:// Show My Points
  83.                 player->GetSession()->SendAreaTriggerMessage("Donor Points: %u", dp);
  84.                 player->GetSession()->SendAreaTriggerMessage("Voter Points: %u", vp);
  85.                 player->CLOSE_GOSSIP_MENU();
  86.                 break;
  87.  
  88.             case 4:// [1 Donor Point] For [1 Donor Token]
  89.                 if (dp < 1)
  90.                 {
  91.                     player->GetSession()->SendAreaTriggerMessage("You don't have the required points.");
  92.                     player->CLOSE_GOSSIP_MENU();
  93.                 }
  94.                 else
  95.                 {
  96.                     LoginDatabase.PExecute("UPDATE account SET dp = '%u' -1 WHERE id = '%u'", dp, player->GetSession()->GetAccountId()); // DP Exchange 1
  97.                     player->GetSession()->SendAreaTriggerMessage("Successfully!");
  98.                     player->AddItem(DONOR_TOKEN, 1);
  99.                     player->SaveToDB();
  100.                     player->CLOSE_GOSSIP_MENU();
  101.                 }
  102.                 break;
  103.  
  104.             case 5:// [10 Donor Points] For [10 Donor Tokens]
  105.                 if (dp < 10)
  106.                 {
  107.                     player->GetSession()->SendAreaTriggerMessage("You don't have the required points.");
  108.                     player->CLOSE_GOSSIP_MENU();
  109.                 }
  110.                 else
  111.                 {
  112.                     LoginDatabase.PExecute("UPDATE account SET dp = '%u' -10 WHERE id = '%u'", dp, player->GetSession()->GetAccountId()); // DP Exchange 10
  113.                     player->GetSession()->SendAreaTriggerMessage("Successfully!");
  114.                     player->AddItem(DONOR_TOKEN, 10);
  115.                     player->SaveToDB();
  116.                     player->CLOSE_GOSSIP_MENU();
  117.                 }
  118.                 break;
  119.  
  120.             case 6:// [1 Voter Point] For [1 Voter Token]
  121.                 if (vp < 1)
  122.                 {
  123.                     player->GetSession()->SendAreaTriggerMessage("You don't have the required points.");
  124.                     player->CLOSE_GOSSIP_MENU();
  125.                 }
  126.                 else
  127.                 {
  128.                     LoginDatabase.PExecute("UPDATE account SET vp = '%u' -1 WHERE id = '%u'", vp, player->GetSession()->GetAccountId()); // VP Exchange 1
  129.                     player->GetSession()->SendAreaTriggerMessage("Successfully!");
  130.                     player->AddItem(VOTER_TOKEN, 1);
  131.                     player->SaveToDB();
  132.                     player->CLOSE_GOSSIP_MENU();
  133.                 }
  134.                 break;
  135.  
  136.             case 7:// [10 Voter Points] For [10 Voter Tokens]
  137.                 if (vp < 10)
  138.                 {
  139.                     player->GetSession()->SendAreaTriggerMessage("You don't have the required points.");
  140.                     player->CLOSE_GOSSIP_MENU();
  141.                 }
  142.                 else
  143.                 {
  144.                     LoginDatabase.PExecute("UPDATE account SET vp = '%u' -10 WHERE id = '%u'", vp, player->GetSession()->GetAccountId()); // VP Exchange 10
  145.                     player->GetSession()->SendAreaTriggerMessage("Successfully!");
  146.                     player->AddItem(VOTER_TOKEN, 10);
  147.                     player->SaveToDB();
  148.                     player->CLOSE_GOSSIP_MENU();
  149.                 }
  150.                 break;
  151.  
  152.             case 10:// Close Window
  153.                 player->CLOSE_GOSSIP_MENU();
  154.                 break;
  155.  
  156.             case 11: // ...Back
  157.                 OnGossipHello(player, creature);
  158.                 break;
  159.             }
  160.         }
  161.  
  162.         return true;
  163.     }
  164. };
  165.  
  166. void AddSC_Donor_Voter_Trader()
  167. {
  168.     new Donor_Voter_Trader();
  169. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement