Advertisement
EmuDevs

EmuDevs: TrinityCore - Adding data to a map and other stuff

Aug 7th, 2013
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.32 KB | None | 0 0
  1. /*
  2.     EmuDevs NPC Tutorial
  3.     http://emudevs.com
  4.     TrinityCore Tutorial
  5. */
  6.  
  7. struct SpecialCoords
  8. {
  9.     float x, y, z;
  10. };
  11.  
  12. UNORDERED_MAP<uint64, SpecialCoords> CoordsStore;
  13.  
  14. class npc_tutorial : public CreatureScript
  15. {
  16. public:
  17.     npc_tutorial() : CreatureScript("npc_tutorial") { }
  18.  
  19.     bool OnGossipHello(Player* player, Creature* creature)
  20.     {
  21.         player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Add Coords", GOSSIP_SENDER_MAIN, 1);
  22.         player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Show Data", GOSSIP_SENDER_MAIN, 2);
  23.         player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Delete my aata", GOSSIP_SENDER_MAIN, 3);
  24.         player->SEND_GOSSIP_MENU(1, creature->GetGUID());
  25.         return true;
  26.     }
  27.  
  28.     bool OnGossipSelect(Player* player, Creature* creature, uint32 /*sender*/, uint32 actions)
  29.     {
  30.         player->PlayerTalkClass->ClearMenus();
  31.  
  32.         if (CoordsStore.size() > 0)
  33.         {
  34.             UNORDERED_MAP<uint64, SpecialCoords>::iterator itr = CoordsStore.find(player->GetGUID());
  35.             if (itr != CoordsStore.end())
  36.             {
  37.                 player->GetSession()->SendNotification("You are already in!");
  38.                 player->CLOSE_GOSSIP_MENU();
  39.                 return false;
  40.             }
  41.         }
  42.  
  43.         if (actions == 1)
  44.         {
  45.             CoordsStore[player->GetGUID()].x = 5912.873212f;
  46.             CoordsStore[player->GetGUID()].y = -1912.473212f;
  47.             CoordsStore[player->GetGUID()].z = 122.873212f;
  48.             ChatHandler(player->GetSession()).SendSysMessage("You are in this map!");
  49.             player->CLOSE_GOSSIP_MENU();
  50.         }
  51.         else if (actions == 2)
  52.         {
  53.             for (UNORDERED_MAP<uint64, SpecialCoords>::const_iterator itr = CoordsStore.begin(); itr != CoordsStore.end(); ++itr)
  54.             {
  55.                 Player* _player = sObjectMgr->GetPlayerByLowGUID(GUID_LOPART(itr->first));
  56.                 if (player || player->IsInWorld())
  57.                     ChatHandler(player->GetSession()).PSendSysMessage("DATA FOR COORDS \n Name: %s \n Coords: \n X: %f \n Y: %f \n Z: %f", _player->GetName().c_str(), itr->second.x, itr->second.y, itr->second.z);
  58.             }
  59.         }
  60.         else if (actions == 3)
  61.             CoordsStore.erase(player->GetGUID());
  62.         return true;
  63.     }
  64. };
  65.  
  66. void AddSC_gossip()
  67. {
  68.     new npc_tutorial();
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement