Advertisement
Rochet2

Portal Master C++ DB

Mar 16th, 2013
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. /*
  3. Portal Master convert to C++ for Trinitycore
  4. By Rochet2
  5.  
  6. Credits:
  7. Rochet2
  8. Eric
  9.  
  10. ScriptName: TeLe_gossip_codebox
  11. */
  12.  
  13. #include "ScriptPCH.h"
  14.  
  15. // Teleport data
  16.  
  17. struct Rochet2
  18. {
  19.     uint32 menu_id;
  20.     uint32 next_menu_id;
  21.     uint8 icon;
  22.     std::string name;
  23.     uint32 cost;
  24.     uint8 level;
  25.     uint8 faction; // 0 Both, 1 Horde, 2 Ally
  26.     uint32 map;
  27.     float x;
  28.     float y;
  29.     float z;
  30.     float o;
  31. };
  32.  
  33. // TextIDs from npc_text
  34. enum eEnums
  35. {
  36.     TEXT_MAIN_H     =   300000,         //Horde main menu text
  37.     TEXT_MAIN_A     =   300001,         //Alliance main menu text
  38.     TEXT_DUNGEON    =   300002,         //Dungeon teleport menu texts
  39.     TEXT_RAID       =   300003,         //Raid teleport menu text
  40.     TEXT_AREA       =   300004,         //Area teleport location menu texts
  41. };
  42.  
  43. #define ARE_YOU_SURE    "Are you sure, that you want to go to "
  44. #define ERROR_COMBAT    "You are in combat"
  45.  
  46. class TeLe_gossip_codebox : public CreatureScript
  47. {
  48. public:
  49.     typedef std::map<uint32, Rochet2*> TeLeTypeMap;
  50.     typedef UNORDERED_MAP<uint32, TeLeTypeMap > TeLeTypeUMap;
  51.     TeLeTypeUMap TeLe;
  52.  
  53.     TeLe_gossip_codebox() : CreatureScript("TeLe_gossip_codebox")
  54.     {
  55.         QueryResult result = WorldDatabase.Query("SELECT menu_id, next_menu_id, icon, name, cost, level, faction, map, x, y, z, o FROM table_here");
  56.         if (result)
  57.         {
  58.             do
  59.             {
  60.                 uint32 i = 0;
  61.                 Field* fields = result->Fetch();
  62.                 uint32 menu_id = fields[i++].GetUInt32();
  63.  
  64.                 Rochet2* data = new Rochet2;
  65.                 data->next_menu_id = fields[i++].GetUInt32();
  66.                 data->icon = fields[i++].GetUInt8();
  67.                 data->name = fields[i++].GetString();
  68.                 data->cost = fields[i++].GetUInt32();
  69.                 data->level = fields[i++].GetUInt8();
  70.                 data->faction = fields[i++].GetUInt8();
  71.                 data->map = fields[i++].GetUInt32();
  72.                 data->x = fields[i++].GetFloat();
  73.                 data->y = fields[i++].GetFloat();
  74.                 data->z = fields[i++].GetFloat();
  75.                 data->o = fields[i++].GetFloat();
  76.  
  77.                 // TeLe[menu_id][id] = data;
  78.                 TeLe[menu_id][TeLe[menu_id].size()] = data;
  79.             }
  80.             while (!result->NextRow());
  81.         }
  82.     }
  83.  
  84.     ~TeLe_gossip_codebox()
  85.     {
  86.         for (TeLeTypeUMap::iterator it = TeLe.begin(); it != TeLe.end(); ++it)
  87.         {
  88.             for (TeLeTypeMap::iterator itr = it->second.begin(); itr != it->second.end(); ++itr)
  89.                 delete itr->second;
  90.         }
  91.     }
  92.  
  93.     bool OnGossipHello(Player* player, Creature* creature)
  94.     {
  95.         Custom_GetMenu(player, creature, 1); // 1 = main menu
  96.         return true;
  97.     }
  98.  
  99.     bool OnGossipSelect(Player* player, Creature* creature, uint32 menu_id, uint32 id)
  100.     {
  101.         Rochet2* data = TeLe[menu_id][id];
  102.  
  103.         player->PlayerTalkClass->ClearMenus(); // clear the menu
  104.         player->ModifyMoney(-1 * data->cost); // take cash
  105.  
  106.         if (data->next_menu_id)
  107.             Custom_GetMenu(player, creature, data->next_menu_id);
  108.         else if (player->isInCombat())
  109.         {
  110.             player->GetSession()->SendNotification(ERROR_COMBAT);
  111.             Custom_GetMenu(player, creature, data->menu_id);
  112.         }
  113.         else
  114.         {
  115.             player->CLOSE_GOSSIP_MENU();
  116.             player->TeleportTo(data->map, data->x, data->y, data->z, data->o);
  117.         }
  118.         return true;
  119.     }
  120.  
  121.     bool Custom_FactCheck(uint32 team, uint32 fact)
  122.     {
  123.         switch (fact)
  124.         {
  125.         case 0: return true;
  126.         case 1: return (team == HORDE);
  127.         case 2: return (team == ALLIANCE);
  128.         }
  129.         return false;
  130.     }
  131.  
  132.     uint32 Custom_GetText(uint32 menu, uint32 team)
  133.     {
  134.         switch (menu)
  135.         {
  136.         case 1:
  137.             if (team == ALLIANCE)
  138.                 return TEXT_MAIN_A;
  139.             else
  140.                 return TEXT_MAIN_H;
  141.         case 2:
  142.         case 3:
  143.         case 4:
  144.             return TEXT_DUNGEON;
  145.         case 5:
  146.             return TEXT_RAID;
  147.         }
  148.         return TEXT_AREA;
  149.     }
  150.  
  151.     void Custom_GetMenu(Player* player, Creature* creature, uint32 menu_id)
  152.     {
  153.         for (TeLeTypeMap::iterator it = TeLe[menu_id].begin(); it != TeLe[menu_id].end(); ++it)
  154.         {
  155.             if (player->getLevel() >= it->second->level && Custom_FactCheck(player->GetTeam(), it->second->faction))
  156.             {
  157.                 if (it->second->next_menu_id)
  158.                     player->ADD_GOSSIP_ITEM_EXTENDED(it->second->icon, it->second->name, menu_id, it->first, "", it->second->cost, false);
  159.                 else
  160.                     player->ADD_GOSSIP_ITEM_EXTENDED(it->second->icon, it->second->name, menu_id, it->first, ARE_YOU_SURE+it->second->name, it->second->cost, false);
  161.             }
  162.         }
  163.         player->PlayerTalkClass->SendGossipMenu(Custom_GetText(menu_id, player->GetTeam()), creature->GetGUID());
  164.     }
  165. };
  166.  
  167. void AddSC_TeLe_gossip_codebox()
  168. {
  169.     new TeLe_gossip_codebox();
  170. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement