Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "ScriptPCH.h"
- #include "Chat.h"
- #define PlayerAmount 10
- // uint32 playeroom = 10;
- static bool Countdownstart = true;
- static bool isbattleactive;
- static std::vector<struct Constestor_info> Contestors;
- static struct Constestor_info
- {
- const char* Name;
- uint8 Level;
- uint8 Class;
- uint8 Race;
- };
- class PvP_Event_Announcer : public WorldScript
- {
- public:
- PvP_Event_Announcer() : WorldScript("PvP_Event_Announcer"){}
- void OnStartup()
- {
- CreateEvent(COUNTDOWN_60, 60);
- sLog->outString("Event Created");
- }
- void OnUpdate(uint32 diff)
- {
- UpdateEventTime(diff);
- while (uint32 eventId = GetEventIdToExecute())
- {
- switch (eventId)
- {
- case COUNTDOWN_60:
- {
- sWorld->SendServerMessage(SERVER_MSG_STRING, "|cffffcc00[PvP Event Announcer]:|r|cFF8B0000The 1 versus 1 PvP event countdown is starting in 1 minute !");
- CreateEvent(COUNTDOWN_30, 30000);
- sLog->outString("countdown started");
- }break;
- case COUNTDOWN_30:
- {
- 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!");
- CreateEvent(EVENT_START_60, 30000);
- }break;
- case EVENT_START_60:
- {
- 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!");
- CreateEvent(EVENT_START_30, 30000);
- }break;
- case EVENT_START_30:
- {
- 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");
- CreateEvent(EVENT_START, 30000);
- }break;
- case EVENT_START:
- {
- isbattleactive = true;
- sWorld->SendServerMessage(SERVER_MSG_STRING, "|cffffcc00[PvP Event Announcer]:|r|cFF8B0000The 1 versus 1 PvP event has started !");
- // Events.ScheduleEvent(EVENT_END, 60000);
- }
- break;
- default:
- sLog->outString("TEST");
- }
- }
- }
- private:
- std::map<uint32, uint32> events;
- uint32 _time;
- enum eEvents
- {
- NONE,
- COUNTDOWN_60,
- COUNTDOWN_30,
- EVENT_START_60,
- EVENT_START_30,
- EVENT_START,
- };
- void CreateEvent(uint32 eventId, uint32 time)
- {
- time += _time;
- std::map<uint32, uint32>::const_iterator itr = events.find(time);
- while (itr != events.end())
- {
- ++time;
- itr = events.find(time);
- }
- events.insert(std::make_pair(time, eventId));
- }
- uint32 GetEventIdToExecute()
- {
- while (!events.empty())
- {
- if (events.begin()->first > _time)
- return 0;
- else
- {
- uint32 eventId = (events.begin()->second);
- events.erase(events.begin());
- return eventId;
- }
- }
- return 0;
- }
- void UpdateEventTime(uint32 time)
- {
- _time += time;
- }
- };
- class PvP_Event_Command : public CommandScript
- {
- public:
- PvP_Event_Command() : CommandScript("PvP_Event_Command") {}
- ChatCommand* GetCommands() const
- {
- static ChatCommand PVPEventSubCommandTable[] =
- {
- { "enter", SEC_PLAYER, false, &HandleEnterpvpcommand, "", NULL },
- { NULL, 0, false, NULL, "", NULL }
- };
- static ChatCommand CommandTable[] =
- {
- { "pvpevent", SEC_PLAYER, false, NULL, "", PVPEventSubCommandTable },
- { NULL, 0, false, NULL, "", NULL }
- };
- return CommandTable;
- }
- static bool HandleEnterpvpcommand(ChatHandler* handler, const char* args)
- {
- WorldSession* session = handler->GetSession();
- Player* player = session->GetPlayer();
- // playeroom--; // what is this?
- if(!Countdownstart)
- session->SendNotification("There is currently no countdown for this event going on");
- else if(Contestors.size() < PlayerAmount)
- {
- player->SaveRecallPosition();
- Constestor_info temp = { player->GetName(), player->getLevel(), player->getClass(), player->getRace()};
- Contestors.push_back(temp); // must use a temp variable, cant just push back an array like {1,2,3,4}
- session->SendAreaTriggerMessage("Thank you for entering %s, there is room for %u more players!", player->GetName(), PlayerAmount-Contestors.size());
- //Session->SendAreaTriggerMessage ("|cffffcc00[PvP Event Announcer]:|r|cFF8B0000The first contestor is %s and hes/her level is %u",Contestors.at(1),Contestors.at(2));
- }
- else
- session->SendNotification("The maximum player amount for this event is already reached, please try another time");
- return true;
- }
- };
- void AddSC_PvP_Event()
- {
- new PvP_Event_Announcer;
- new PvP_Event_Command;
- }
- /* while (!Contestors.empty())
- {
- 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()
- Contestors.pop_back(); // erase last
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement