Advertisement
EmuDevs

EmuDevs: TrinityCore - Trigger Plots

Jul 19th, 2013
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.96 KB | None | 0 0
  1. /*
  2.  *╔═╦═╦═╦╦╦══╦═╦╗─╔╦══╗
  3.  *║╦╣║║║║║╠╗╗║╦╣╚╦╝║══╣
  4.  *║╩╣║║║║║╠╩╝║╩╬╗║╔╬══║
  5.  *╚═╩╩═╩╩═╩══╩═╝╚═╝╚══╝
  6.  *       EmuDevs - (http://emudevs.com)
  7. */
  8. struct Plots
  9. {
  10.     float x, y;
  11. };
  12.  
  13. UNORDERED_MAP<uint64, Plots> PlotsContainer;
  14.  
  15. class npc_gossip_plot : public CreatureScript
  16. {
  17. public:
  18.     npc_gossip_plot() : CreatureScript("npc_gossip_plot") { }
  19.  
  20.     bool OnGossipHello(Player* player, Creature* creature)
  21.     {
  22.         player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Get Plot 1", GOSSIP_SENDER_MAIN, 1);
  23.         player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Get Plot 2", GOSSIP_SENDER_MAIN, 2);
  24.         player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Nevermind", GOSSIP_SENDER_MAIN, 3);
  25.         player->SEND_GOSSIP_MENU(1, creature->GetGUID());
  26.         return true;
  27.     }
  28.  
  29.     bool OnGossipSelect(Player* player, Creature* creature, uint32 /* sender */, uint32 actions)
  30.     {
  31.         player->PlayerTalkClass->ClearMenus();
  32.  
  33.         if (PlotsContainer.size() > 0)
  34.         {
  35.             UNORDERED_MAP<uint64, Plots>::iterator itr = PlotsContainer.find(player->GetGUID());
  36.             if (itr != PlotsContainer.end())
  37.             {
  38.                 player->GetSession()->SendNotification("You already have a plot!");
  39.                 player->CLOSE_GOSSIP_MENU();
  40.                 return false;
  41.             }
  42.         }
  43.  
  44.         if (actions == 1)
  45.         {
  46.             PlotsContainer[player->GetGUID()].x = 5780.797363f;
  47.             PlotsContainer[player->GetGUID()].y = -2959.686279f;
  48.             creature->SummonCreature(54001, 5780.797363f, -2959.686279f, 274, 1.0f, TEMPSUMMON_MANUAL_DESPAWN, 0);
  49.             ChatHandler(player->GetSession()).SendSysMessage("Plot created!");
  50.             player->CLOSE_GOSSIP_MENU();
  51.         }
  52.         else if (actions == 2)
  53.         {
  54.             PlotsContainer[player->GetGUID()].x = 5748.431641f;
  55.             PlotsContainer[player->GetGUID()].y = -2973.928223f;
  56.             creature->SummonCreature(54002, 5748.431641f, -2973.928223f, 274, 1.0f, TEMPSUMMON_MANUAL_DESPAWN, 0);
  57.             ChatHandler(player->GetSession()).SendSysMessage("Plot created!");
  58.             player->CLOSE_GOSSIP_MENU();
  59.         }
  60.         else if (actions == 3)
  61.             player->CLOSE_GOSSIP_MENU();
  62.         return true;
  63.     }
  64. };
  65.  
  66. class npc_trigger_plot : public CreatureScript
  67. {
  68. public:
  69.     npc_trigger_plot() : CreatureScript("npc_trigger_plot") { }
  70.  
  71.     struct npc_trigger_plotAI : public ScriptedAI
  72.     {
  73.         npc_trigger_plotAI(Creature* creature) : ScriptedAI(creature) { }
  74.  
  75.         uint32 teleportTimer;
  76.  
  77.         void Reset()
  78.         {
  79.             teleportTimer = 1000;
  80.         }
  81.  
  82.         void UpdateAI(uint32 diff)
  83.         {
  84.             if (teleportTimer <= diff)
  85.             {
  86.                 Player* player = me->SelectNearestPlayer(15.0f);
  87.                 if (player && !player->isDead())
  88.                 {
  89.                     if (PlotsContainer.size() > 0)
  90.                     {
  91.                         UNORDERED_MAP<uint64, Plots>::iterator itr = PlotsContainer.find(player->GetGUID());
  92.                         if (itr != PlotsContainer.end())
  93.                         {
  94.                             if (player->GetGUID() == itr->first) // If the guid matches
  95.                             {
  96.                                 if (itr->second.x != me->GetPositionX() && itr->second.y != me->GetPositionY()) // If these don't match, gtfo
  97.                                 {
  98.                                     player->TeleportTo(player->GetMapId(), player->GetPositionX() + 15, player->GetPositionY() - 15, player->GetPositionZ() + 5, player->GetOrientation());
  99.                                     player->GetSession()->SendNotification("This isn't your plot!");
  100.                                 }
  101.                             }
  102.                         }
  103.                         else // You don't have a plot, don't touch MINE!
  104.                         {
  105.                             player->TeleportTo(player->GetMapId(), player->GetPositionX() + 15, player->GetPositionY() - 15, player->GetPositionZ() + 5, player->GetOrientation());
  106.                             player->GetSession()->SendNotification("This isn't your plot!");
  107.                         }
  108.                     }
  109.                 }
  110.             }
  111.             else
  112.                 teleportTimer -= diff;
  113.         }
  114.     };
  115.  
  116.     CreatureAI* GetAI(Creature* creature) const
  117.     {
  118.         return new npc_trigger_plotAI(creature);
  119.     }
  120. };
  121.  
  122. class npc_trigger_plotTwo : public CreatureScript
  123. {
  124. public:
  125.     npc_trigger_plotTwo() : CreatureScript("npc_trigger_plotTwo") { }
  126.  
  127.     struct npc_trigger_plotTwoAI : public ScriptedAI
  128.     {
  129.         npc_trigger_plotTwoAI(Creature* creature) : ScriptedAI(creature) { }
  130.  
  131.         uint32 teleportTimer;
  132.  
  133.         void Reset()
  134.         {
  135.             teleportTimer = 1000;
  136.         }
  137.  
  138.         void UpdateAI(uint32 diff)
  139.         {
  140.             if (teleportTimer <= diff)
  141.             {
  142.                 Player* player = me->SelectNearestPlayer(15.0f);
  143.                 if (player && !player->isDead())
  144.                 {
  145.                     if (PlotsContainer.size() > 0)
  146.                     {
  147.                         UNORDERED_MAP<uint64, Plots>::iterator itr = PlotsContainer.find(player->GetGUID());
  148.                         if (itr != PlotsContainer.end())
  149.                         {
  150.                             if (player->GetGUID() == itr->first) // If the guid matches
  151.                             {
  152.                                 if (itr->second.x != me->GetPositionX() && itr->second.y != me->GetPositionY()) // If these don't match, gtfo
  153.                                 {
  154.                                     player->TeleportTo(player->GetMapId(), player->GetPositionX() + 15, player->GetPositionY() - 15, player->GetPositionZ() + 5, player->GetOrientation());
  155.                                     player->GetSession()->SendNotification("This isn't your plot!");
  156.                                 }
  157.                             }
  158.                         }
  159.                         else // You don't have a plot, don't touch MINE!
  160.                         {
  161.                             player->TeleportTo(player->GetMapId(), player->GetPositionX() + 15, player->GetPositionY() - 15, player->GetPositionZ() + 5, player->GetOrientation());
  162.                             player->GetSession()->SendNotification("This isn't your plot!");
  163.                         }
  164.                     }
  165.                 }
  166.             }
  167.             else
  168.                 teleportTimer -= diff;
  169.         }
  170.     };
  171.  
  172.     CreatureAI* GetAI(Creature* creature) const
  173.     {
  174.         return new npc_trigger_plotTwoAI(creature);
  175.     }
  176. };
  177.  
  178. void AddSC_custom_thing() // This is your ScriptLoader.cpp setup function
  179. {
  180.    new npc_gossip_plot; // Call any new classes here as 'new classname();'
  181.    new npc_trigger_plot;
  182.    new npc_trigger_plotTwo;
  183. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement