Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Portal Master convert to C++ for Trinitycore
- By Rochet2
- Credits:
- Rochet2
- Eric
- ScriptName: TeLe_gossip_codebox
- */
- #include "ScriptPCH.h"
- // Teleport data
- struct Rochet2
- {
- uint32 menu_id;
- uint32 next_menu_id;
- uint8 icon;
- std::string name;
- uint32 cost;
- uint8 level;
- uint8 faction; // 0 Both, 1 Horde, 2 Ally
- uint32 map;
- float x;
- float y;
- float z;
- float o;
- };
- // TextIDs from npc_text
- enum eEnums
- {
- TEXT_MAIN_H = 300000, //Horde main menu text
- TEXT_MAIN_A = 300001, //Alliance main menu text
- TEXT_DUNGEON = 300002, //Dungeon teleport menu texts
- TEXT_RAID = 300003, //Raid teleport menu text
- TEXT_AREA = 300004, //Area teleport location menu texts
- };
- #define ARE_YOU_SURE "Are you sure, that you want to go to "
- #define ERROR_COMBAT "You are in combat"
- class TeLe_gossip_codebox : public CreatureScript
- {
- public:
- typedef std::map<uint32, Rochet2*> TeLeTypeMap;
- typedef UNORDERED_MAP<uint32, TeLeTypeMap > TeLeTypeUMap;
- TeLeTypeUMap TeLe;
- TeLe_gossip_codebox() : CreatureScript("TeLe_gossip_codebox")
- {
- QueryResult result = WorldDatabase.Query("SELECT menu_id, next_menu_id, icon, name, cost, level, faction, map, x, y, z, o FROM table_here");
- if (result)
- {
- do
- {
- uint32 i = 0;
- Field* fields = result->Fetch();
- uint32 menu_id = fields[i++].GetUInt32();
- Rochet2* data = new Rochet2;
- data->next_menu_id = fields[i++].GetUInt32();
- data->icon = fields[i++].GetUInt8();
- data->name = fields[i++].GetString();
- data->cost = fields[i++].GetUInt32();
- data->level = fields[i++].GetUInt8();
- data->faction = fields[i++].GetUInt8();
- data->map = fields[i++].GetUInt32();
- data->x = fields[i++].GetFloat();
- data->y = fields[i++].GetFloat();
- data->z = fields[i++].GetFloat();
- data->o = fields[i++].GetFloat();
- // TeLe[menu_id][id] = data;
- TeLe[menu_id][TeLe[menu_id].size()] = data;
- }
- while (!result->NextRow());
- }
- }
- ~TeLe_gossip_codebox()
- {
- for (TeLeTypeUMap::iterator it = TeLe.begin(); it != TeLe.end(); ++it)
- {
- for (TeLeTypeMap::iterator itr = it->second.begin(); itr != it->second.end(); ++itr)
- delete itr->second;
- }
- }
- bool OnGossipHello(Player* player, Creature* creature)
- {
- Custom_GetMenu(player, creature, 1); // 1 = main menu
- return true;
- }
- bool OnGossipSelect(Player* player, Creature* creature, uint32 menu_id, uint32 id)
- {
- Rochet2* data = TeLe[menu_id][id];
- player->PlayerTalkClass->ClearMenus(); // clear the menu
- player->ModifyMoney(-1 * data->cost); // take cash
- if (data->next_menu_id)
- Custom_GetMenu(player, creature, data->next_menu_id);
- else if (player->isInCombat())
- {
- player->GetSession()->SendNotification(ERROR_COMBAT);
- Custom_GetMenu(player, creature, data->menu_id);
- }
- else
- {
- player->CLOSE_GOSSIP_MENU();
- player->TeleportTo(data->map, data->x, data->y, data->z, data->o);
- }
- return true;
- }
- bool Custom_FactCheck(uint32 team, uint32 fact)
- {
- switch (fact)
- {
- case 0: return true;
- case 1: return (team == HORDE);
- case 2: return (team == ALLIANCE);
- }
- return false;
- }
- uint32 Custom_GetText(uint32 menu, uint32 team)
- {
- switch (menu)
- {
- case 1:
- if (team == ALLIANCE)
- return TEXT_MAIN_A;
- else
- return TEXT_MAIN_H;
- case 2:
- case 3:
- case 4:
- return TEXT_DUNGEON;
- case 5:
- return TEXT_RAID;
- }
- return TEXT_AREA;
- }
- void Custom_GetMenu(Player* player, Creature* creature, uint32 menu_id)
- {
- for (TeLeTypeMap::iterator it = TeLe[menu_id].begin(); it != TeLe[menu_id].end(); ++it)
- {
- if (player->getLevel() >= it->second->level && Custom_FactCheck(player->GetTeam(), it->second->faction))
- {
- if (it->second->next_menu_id)
- player->ADD_GOSSIP_ITEM_EXTENDED(it->second->icon, it->second->name, menu_id, it->first, "", it->second->cost, false);
- else
- 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);
- }
- }
- player->PlayerTalkClass->SendGossipMenu(Custom_GetText(menu_id, player->GetTeam()), creature->GetGUID());
- }
- };
- void AddSC_TeLe_gossip_codebox()
- {
- new TeLe_gossip_codebox();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement