Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "ScriptPCH.h"
- struct CoordData { uint32 map; float x, y, z, o; };
- #define MAX_PLAYERS 24
- #define COUNTDOWNSECONDS 5
- struct CoordData Coords[] =
- {
- // {map, x, y ,z ,o},
- {37, 78.435f, 43.171f, 230.198f, 0.665f},
- {37, 66.207f, 48.055f, 233.108f, 0.374f},
- {37, 71.224f, 60.573f, 230.487f, 0.060f},
- {37, 70.335f, 77.316f, 230.655f, 6.281f},
- {37, 63.399f, 90.139f, 233.777f, 5.978f},
- {37, 75.196f, 96.457f, 230.735f, 5.476f},
- {37, 90.892f, 107.936f, 230.687f, 5.322f},
- {37, 93.509f, 124.852f, 235.606f, 5.206f},
- {37, 106.143f, 116.944f, 230.980f, 5.128f},
- {37, 125.035f, 121.985f, 231.222f, 4.782f},
- {37, 135.641f, 133.698f, 234.832f, 4.688f},
- {37, 145.978f, 123.116f, 230.728f, 4.641f},
- {37, 167.477f, 119.328f, 229.118f, 4.001f},
- {37, 176.141f, 97.227f, 230.376f, 3.867f},
- {37, 193.244f, 77.802f, 231.257f, 3.514f},
- {37, 204.523f, 64.648f, 233.862f, 2.999f},
- {37, 190.647f, 55.572f, 231.448f, 2.279f},
- {37, 178.287f, 40.348f, 232.187f, 2.642f},
- {37, 165.608f, 24.132f, 231.472f, 2.194f},
- {37, 147.554f, 15.504f, 232.119f, 1.743f},
- {37, 127.466f, 16.810f, 230.177f, 1.478f},
- {37, 108.817f, 19.988f, 230.199f, 1.228f},
- {37, 91.601f, 28.932f, 230.341f, 0.898f},
- {37, 60.758f, 92.920f, 235.488f, 5.940f},
- };
- typedef std::set<Player*> infoType; // Define infoType to be the set
- infoType info;
- bool Counting = false;
- class hunger_queue_npc : public CreatureScript
- {
- public:
- hunger_queue_npc() : CreatureScript("hunger_queue_npc") {}
- bool OnGossipHello(Player * player, Creature * creature)
- {
- player->ADD_GOSSIP_ITEM(1, "Queue me for the survival games!", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+1);
- player->ADD_GOSSIP_ITEM(1, "I wish to leave the queue!", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+3);
- player->PlayerTalkClass->SendGossipMenu(DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
- return true;
- }
- bool OnGossipSelect(Player * player, Creature * creature, uint32 sender, uint32 actions)
- {
- player->PlayerTalkClass->ClearMenus();
- switch(actions)
- {
- case GOSSIP_ACTION_INFO_DEF+1:
- if(info.find(player) == info.end()) // check if player is not in the set
- player->GetSession()->SendAreaTriggerMessage("You are already queued for The Survival Games");
- else
- {
- bool insert = true;
- if(info.size() >= MAX_PLAYERS) // if queue full, check if players offline:
- {
- ErasePlayers();
- if(info.size() >= MAX_PLAYERS)
- {
- if(!Counting)
- {
- sWorld->SendServerMessage(SERVER_MSG_STRING, "Countdown: "+COUNTDOWNSECONDS);
- events.ScheduleEvent(COUNTDOWNSECONDS, 1000); // start countdown // 5 is the amount of seconds
- Counting = true;
- }
- insert = false;
- ChatHandler(player).SendSysMessage("The queue is currently full");
- }
- }
- if(insert)
- {
- info.insert(player); // save player pointer to the set
- ChatHandler(player).SendSysMessage("You are now in the queue for The Survival Games");
- }
- }
- break;
- case GOSSIP_ACTION_INFO_DEF+3:
- if (info.find(player) == info.end())
- ChatHandler(player).SendSysMessage("You are not in the queue yet");
- else
- {
- info.erase(player);
- ChatHandler(player).SendSysMessage("You have been removed from the queue");
- }
- break;
- }
- OnGossipHello(player, creature);
- return true;
- }
- void ErasePlayers()
- {
- for(infoType::iterator it = info.begin(); it != info.end(); ++it) // loop records
- {
- Player* plr = (*it); // get player pointer from record
- if(!plr || !plr->IsInWorld()) // check if the player does not exist
- info.erase(it);
- }
- }
- void UpdateAI(const uint32 diff)
- {
- events.Update(diff);
- while (uint32 eventId = events.ExecuteEvent())
- {
- if(eventId == 1) // 1 is the last ID, so we need to teleport when it is called
- {
- uint32 i = 0;
- for(infoType::iterator it = info.begin(); it != info.end(); ++it, ++i)
- {
- (*it)->TeleportTo(Coords[i].map, Coords[i].x, Coords[i].y, Coords[i].z, Coords[i].o);
- }
- }
- else // id was something else than 1, wait more and announce the countdown
- {
- sWorld->SendServerMessage(SERVER_MSG_STRING, "Countdown: "+(--eventId));
- events.ScheduleEvent(eventId, 1000);
- }
- }
- };
- EventMap events;
- };
- void AddSC_hunger_queue_npc()
- {
- new hunger_queue_npc;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement