Advertisement
Rochet2

Jamey's timers fixed

Aug 16th, 2012
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.96 KB | None | 0 0
  1. #include "ScriptPCH.h"
  2. #include "Chat.h"
  3.  
  4. #define PlayerAmount    10
  5. // uint32 playeroom = 10;
  6. static bool Countdownstart = true;
  7. static bool isbattleactive;
  8.  
  9. static std::vector<struct Constestor_info> Contestors;
  10. static struct Constestor_info
  11. {
  12.     const char* Name;
  13.     uint8 Level;
  14.     uint8 Class;
  15.     uint8 Race;
  16. };
  17.  
  18. class PvP_Event_Announcer : public WorldScript
  19. {
  20. public:
  21.     PvP_Event_Announcer() : WorldScript("PvP_Event_Announcer"){}
  22.  
  23.     void OnStartup()
  24.     {
  25.         CreateEvent(COUNTDOWN_60, 60);
  26.         sLog->outString("Event Created");
  27.     }
  28.  
  29.     void OnUpdate(uint32 diff)
  30.     {
  31.         UpdateEventTime(diff);
  32.         while (uint32 eventId = GetEventIdToExecute())
  33.         {
  34.             switch (eventId)
  35.             {
  36.             case COUNTDOWN_60:
  37.                 {
  38.                     sWorld->SendServerMessage(SERVER_MSG_STRING, "|cffffcc00[PvP Event Announcer]:|r|cFF8B0000The 1 versus 1 PvP event countdown is starting in 1 minute !");
  39.                     CreateEvent(COUNTDOWN_30, 30000);
  40.                     sLog->outString("countdown started");
  41.                 }break;
  42.             case COUNTDOWN_30:
  43.                 {
  44.                     sWorld->SendServerMessage(SERVER_MSG_STRING, "|cffffcc00[PvP Event Announcer]:|r|cFF8B0000The 1 versus 1 PvP event countdown is starting in 30 seconds, contestors be ready!");
  45.                     CreateEvent(EVENT_START_60, 30000);
  46.                 }break;
  47.             case EVENT_START_60:
  48.                 {
  49.                     sWorld->SendServerMessage(SERVER_MSG_STRING, "|cffffcc00[PvP Event Announcer]:|r|cFF8B0000The 1 versus 1 PvP event countdown has started, you have 1 minute to enter by typing: .pvpevent enter , be fast cause only 10 players can enter!");
  50.                     CreateEvent(EVENT_START_30, 30000);
  51.                 }break;
  52.             case EVENT_START_30:
  53.                 {
  54.                     sWorld->SendServerMessage(SERVER_MSG_STRING, "|cffffcc00[PvP Event Announcer]:|r|cFF8B0000The 1 versus 1 PvP event countdown is only 30 seconds more, enter fast if you still want to by typing : .pvpevent enter");
  55.                     CreateEvent(EVENT_START, 30000);
  56.                 }break;
  57.             case EVENT_START:
  58.                 {
  59.                     isbattleactive = true;
  60.                     sWorld->SendServerMessage(SERVER_MSG_STRING, "|cffffcc00[PvP Event Announcer]:|r|cFF8B0000The 1 versus 1 PvP event has started !");
  61.                     // Events.ScheduleEvent(EVENT_END, 60000);
  62.                 }
  63.                 break;
  64.             default:
  65.                 sLog->outString("TEST");
  66.             }
  67.         }
  68.     }
  69.  
  70. private:
  71.     std::map<uint32, uint32> events;
  72.     uint32 _time;
  73.  
  74.     enum eEvents
  75.     {
  76.         NONE,
  77.         COUNTDOWN_60,
  78.         COUNTDOWN_30,
  79.         EVENT_START_60,
  80.         EVENT_START_30,
  81.         EVENT_START,
  82.     };
  83.  
  84.     void CreateEvent(uint32 eventId, uint32 time)
  85.     {
  86.         time += _time;
  87.         std::map<uint32, uint32>::const_iterator itr = events.find(time);
  88.         while (itr != events.end())
  89.         {
  90.             ++time;
  91.             itr = events.find(time);
  92.         }
  93.         events.insert(std::make_pair(time, eventId));
  94.     }
  95.  
  96.     uint32 GetEventIdToExecute()
  97.     {
  98.         while (!events.empty())
  99.         {
  100.             if (events.begin()->first > _time)
  101.                 return 0;
  102.             else
  103.             {
  104.                 uint32 eventId = (events.begin()->second);
  105.                 events.erase(events.begin());
  106.                 return eventId;
  107.             }
  108.         }
  109.         return 0;
  110.     }
  111.    
  112.     void UpdateEventTime(uint32 time)
  113.     {
  114.         _time += time;
  115.     }
  116. };
  117.  
  118. class PvP_Event_Command : public CommandScript
  119. {
  120. public:
  121.     PvP_Event_Command() : CommandScript("PvP_Event_Command") {}
  122.  
  123.     ChatCommand* GetCommands() const
  124.     {
  125.         static ChatCommand PVPEventSubCommandTable[] =
  126.         {
  127.             { "enter",      SEC_PLAYER,     false&HandleEnterpvpcommand,     "", NULL },
  128.             { NULL,         0,              falseNULL,                       "", NULL }
  129.         };
  130.  
  131.         static ChatCommand CommandTable[] =
  132.         {
  133.             { "pvpevent",   SEC_PLAYER,     falseNULL,       "", PVPEventSubCommandTable },
  134.             { NULL,         0,              falseNULL,       "", NULL }
  135.         };
  136.         return CommandTable;
  137.     }
  138.  
  139.     static bool HandleEnterpvpcommand(ChatHandler* handler, const char* args)
  140.     {
  141.         WorldSession* session = handler->GetSession();
  142.         Player* player = session->GetPlayer();
  143.         // playeroom--; // what is this?
  144.         if(!Countdownstart)
  145.             session->SendNotification("There is currently no countdown for this event going on");
  146.         else if(Contestors.size() < PlayerAmount)
  147.         {
  148.             player->SaveRecallPosition();
  149.             Constestor_info temp = { player->GetName(), player->getLevel(), player->getClass(), player->getRace()};
  150.             Contestors.push_back(temp); // must use a temp variable, cant just push back an array like {1,2,3,4}
  151.             session->SendAreaTriggerMessage("Thank you for entering %s, there is room for %u more players!", player->GetName(), PlayerAmount-Contestors.size());
  152.             //Session->SendAreaTriggerMessage ("|cffffcc00[PvP Event Announcer]:|r|cFF8B0000The first contestor is %s and hes/her level is %u",Contestors.at(1),Contestors.at(2));
  153.         }
  154.         else
  155.             session->SendNotification("The maximum player amount for this event is already reached, please try another time");
  156.         return true;
  157.     }
  158. };
  159.  
  160. void AddSC_PvP_Event()
  161. {
  162.     new PvP_Event_Announcer;
  163.     new PvP_Event_Command;
  164. }
  165.  
  166.  
  167.  
  168.  
  169.  
  170. /*  while (!Contestors.empty())
  171. {
  172.  
  173. sWorld->SendServerMessage(SERVER_MSG_STRING," |cffffcc00[PvP Event Announcer]: |cFF8B0000Contestor %u just signed up, information :Name: %s  level: %u class: %u race: %u", Contestors.size(), Contestors.back().Name, Contestors.back().Level, Contestors.back().Class, Contestors.back().Race); // access last = Contestors.back()
  174. Contestors.pop_back(); // erase last
  175. }
  176.  
  177. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement