Advertisement
Rochet2

Basic gossip with DB query

Oct 19th, 2012
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.40 KB | None | 0 0
  1. /*
  2. * Copyright (C) 2008-2011 TrinityCore <http: //www.trinitycore.org/>
  3. * Copyright information <http: //en.wikipedia.org/wiki/Copyright>
  4. *
  5. * This code was written solely for Arena Gods and is not meant for any kind of
  6. * pubic or other opensource projects. If you think you can use this code without
  7. * permission of either Discovered or AJ, we will take some serious action to
  8. * pay you back. We have the law in our right.
  9. *
  10. * All credits on this code/script are going to Jasper "Discovered" Rietrae.
  11. */
  12.  
  13. #include "ScriptPCH.h"
  14.  
  15. /* Gossip Colors */
  16. #define TEXT_CUSTOM_LEGENDARY            "|cffff8000"
  17.  
  18. class npc_donations : public CreatureScript
  19. {
  20. public:
  21.     npc_donations() : CreatureScript("npc_donations") { }
  22.    
  23.     uint32 GetDonationPoints(Player* player) // this is a custom function
  24.     {
  25.         QueryResult result = LoginDatabase.PQuery("SELECT recruiter FROM account WHERE id = %u", player->GetSession()->GetAccountId());
  26.         if(!result)
  27.             return 0; // query failed. No account exists or SQL invalid. %u
  28.         return result->Fetch()[0].GetUInt32(); // [0] means the first column in the select statement. Since donationpoints is the first column, we are getting an uint32 value from donationpoints column.
  29.     }
  30.  
  31.     bool OnGossipHello(Player *player, Creature *creature)
  32.     {
  33.         player->ADD_GOSSIP_ITEM(9, TEXT_CUSTOM_LEGENDARY "GIEF SHADOWMOURNEZ!", GOSSIP_SENDER_MAIN, 9006);
  34.         player->ADD_GOSSIP_ITEM(9, TEXT_CUSTOM_LEGENDARY "the hammer thing", GOSSIP_SENDER_MAIN, 9007);
  35.         player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
  36.         return true;
  37.     }
  38.  
  39.     bool OnGossipSelect(Player *player, Creature *creature, uint32 sender, uint32 uiAction)
  40.     {
  41.         player->PlayerTalkClass->ClearMenus();
  42.  
  43.         uint32 points = GetDonationPoints(player);
  44.  
  45.         switch(uiAction)
  46.         {
  47.         case 9006: // Send that shit
  48.             if (points == 1337) // use == instead of =
  49.             {
  50.                 player->AddItem(49623,1);
  51.             }
  52.             break;
  53.         case 9007: // other thing
  54.             player->AddItem(46017,1);
  55.             break;
  56.         default:
  57.             break;
  58.         }
  59.         // player->CLOSE_GOSSIP_MENU(); // Close on action select
  60.         OnGossipHello(player, creature); // return to main menu
  61.         return true;
  62.     }
  63. };
  64.  
  65. void AddSC_npc_donations()
  66. {
  67.     new npc_donations();
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement