Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Custom event system V2
- * Idea From Goliath
- * Some Help from Rochet2
- */
- #include "ScriptPCH.h"
- #include "GroupMgr.h"
- #include "Group.h"
- #include "Language.h"
- //Simple MapID X,Y,Z,O
- const WorldLocation* eventLocation = new WorldLocation(xxx, x.xf, x.xf, x.xf, x.xf); // location of the event teleport
- uint32 sGroupID = 0;
- bool CanJoin = false;
- bool AnnouncedFull = false;
- typedef std::map<Player*, WorldLocation*> playerLocationType;
- playerLocationType playerLocations;
- static void endEvent(bool reward = false)
- {
- Group* sGroup = sGroupMgr->GetGroupByDbStoreId(sGroupID);
- if(sGroup)
- sGroup->Disband();
- for(playerLocationType::iterator it = playerLocations.begin(); it != playerLocations.end(); ++it)
- {
- Player* player = it->first;
- if(reward)
- {
- // player->AddItem(ItemID, Amount);
- player->AddItem(xxx, x);
- player->AddItem(xxx, x);
- player->AddItem(xxx, x);
- }
- player->TeleportTo(*it->second);
- }
- playerLocations.clear();
- AnnouncedFull = false;
- CanJoin = false;
- }
- static void removePlayer(Player* player, bool teleport = true)
- {
- if(Group* group = player->GetGroup())
- {
- Group* sGroup = sGroupMgr->GetGroupByDbStoreId(sGroupID);
- if(sGroup)
- if(group->GetDbStoreId() == sGroupID)
- sGroup->RemoveMember(player->GetGUID());
- }
- if(teleport && playerLocations.find(player) != playerLocations.end())
- {
- player->TeleportTo(*playerLocations[player]);
- playerLocations.erase(player);
- }
- }
- static uint8 addPlayerToGroup(Player* player)
- {
- ChatHandler* handler = &ChatHandler(player->GetSession());
- if (player->isInCombat())
- {
- handler->GetSession()->SendNotification("You are in combat");
- return 1;
- }
- if (player->isInFlight())
- {
- handler->GetSession()->SendNotification("You are in flight");
- return 2;
- }
- Group* sGroup = sGroupMgr->GetGroupByDbStoreId(sGroupID);
- if(sGroup)
- {
- if(Group* group = player->GetGroup())
- {
- if(group->GetDbStoreId() != sGroupID)
- group->RemoveMember(player->GetGUID());
- else
- {
- handler->GetSession()->SendNotification("You have already joined");
- return 3;
- }
- }
- if(sGroup->IsFull())
- {
- handler->GetSession()->SendNotification("The group is already full");
- return 4;
- }
- sGroup->AddMember(player);
- return 0;
- }
- if(Group* group = player->GetGroup())
- group->RemoveMember(player->GetGUID());
- sGroup = new Group();
- sGroup->ConvertToRaid();
- sGroup->Create(player);
- sGroupMgr->AddGroup(sGroup);
- sGroupID = sGroup->GetDbStoreId();
- return 0;
- }
- class custom_commandScript1 : public CommandScript
- {
- public:
- custom_commandScript1() : CommandScript("custom_commandScript1") { }
- static bool HandleStartEvent(ChatHandler* handler, const char* args)
- {
- // End event
- if(CanJoin)
- endEvent();
- CanJoin = true;
- sWorld->SendServerMessage(SERVER_MSG_STRING, "You can now type .joinevent to be invited and teleported");
- return true;
- }
- static bool HandleStopEvent(ChatHandler* handler, const char* args)
- {
- if(CanJoin)
- endEvent();
- return true;
- }
- static bool HandleJoinEvent(ChatHandler* handler, const char* args)
- {
- WorldSession* session = handler->GetSession();
- Player* player = session->GetPlayer();
- if(!CanJoin)
- session->SendNotification("You can not join the event at this time");
- else if(playerLocations.find(player) == playerLocations.end())
- {
- uint8 result = addPlayerToGroup(player);
- if(!result)
- {
- float x, y, z, o;
- player->GetPosition(x, y, z, o);
- playerLocations[player] = new WorldLocation(player->GetMapId(), x, y, z, o);
- player->TeleportTo(*eventLocation); // event area
- }
- else if(!AnnouncedFull && result == 4)
- {
- sWorld->SendServerMessage(SERVER_MSG_STRING, "The event is now full");
- AnnouncedFull = true;
- }
- }
- else
- {
- Group* sGroup = sGroupMgr->GetGroupByDbStoreId(sGroupID);
- if(sGroup && !player->GetGroup() && !addPlayerToGroup(player))
- player->TeleportTo(*eventLocation); // event area
- }
- return true;
- }
- ChatCommand* GetCommands() const
- {
- static ChatCommand CustomCommandscript1Table[] =
- {
- //In the database execute the row
- { "startevent", SEC_MODERATOR, true, &HandleStartEvent, "", NULL },
- { "stopevent", SEC_MODERATOR, true, &HandleStopEvent, "", NULL },
- { "joinevent", SEC_PLAYER, false, &HandleJoinEvent, "", NULL },
- { NULL, 0, false, NULL, "", NULL }
- };
- return CustomCommandscript1Table;
- }
- };
- class custom_bossScript1 : public CreatureScript
- {
- public:
- custom_bossScript1() : CreatureScript("custom_bossScript1") { }
- struct custom_bossScript1AI : public ScriptedAI
- {
- custom_bossScript1AI(Creature* creature) : ScriptedAI(creature) {}
- void JustDied(Unit* killer)
- {
- endEvent(true);
- }
- /*
- void Reset()
- {
- me->RestoreFaction();
- }
- */
- /*
- void EnterCombat(Unit* who)
- {
- }
- */
- /*
- void UpdateAI(const uint32 uiDiff)
- {
- if (!UpdateVictim())
- return;
- DoMeleeAttackIfReady();
- }
- */
- };
- CreatureAI* GetAI(Creature* creature) const
- {
- return new custom_bossScript1AI(creature);
- }
- };
- class custom_playerScript1 : public PlayerScript
- {
- public:
- custom_playerScript1() : PlayerScript("custom_playerScript1") { }
- void OnPlayerLogin(Player* player)
- {
- if(playerLocations.find(player) == playerLocations.end())
- removePlayer(player);
- }
- void OnPlayerLogout(Player* player)
- {
- if(playerLocations.find(player) == playerLocations.end())
- removePlayer(player);
- }
- void OnPlayerLeaveMap(Map* map, Player* player)
- {
- if(map && map->GetId() == eventLocation->GetMapId())
- removePlayer(player);
- }
- };
- void AddSC_custom_eventScript1()
- {
- new custom_commandScript1();
- new custom_bossScript1();
- new custom_playerScript1();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement