Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- <--------------------------------------------------------------------------->
- - Developer(s): Parranoia,Mthsena.
- - Edited & Updated:Synth
- - Complete: 100%
- - ScriptName: 'PlayerCommands'
- - Comment: Untested
- - Updated - 9/17/2013
- - Shared for:Emudevs
- <--------------------------------------------------------------------------->
- */
- #include "ScriptPCH.h"
- #include "Chat.h"
- #include "InstanceSaveMgr.h"
- class PlayerCommands : public CommandScript
- {
- public:
- PlayerCommands() : CommandScript("PlayerCommands"){}
- ChatCommand * GetCommands() const
- {
- static ChatCommand ResetCharacterCommandTable[] =
- {
- {"info", SEC_PLAYER, false, &HandleResetCharacterInfoCommand, "", NULL},
- {"reset", SEC_PLAYER, false, &HandleResetCharacterResetCommand, "", NULL},
- {NULL, 0, false, NULL, "", NULL}
- };
- static ChatCommand PlayerCommandsCommandTable[] =
- {
- {"chat", SEC_PLAYER, false, &HandleWorldChatCommand, "", NULL},
- {"start", SEC_PLAYER, false, &HandleStartCommand, "", NULL},
- {"maxskills", SEC_PLAYER, false, &HandleMaxSkillsCommand, "", NULL},
- {"resetcombat", SEC_PLAYER, false, &HandleResetCombatCommand, "", NULL},
- {"resetinstances", SEC_PLAYER, false, &HandleResetInstancesCommand, "", NULL},
- {"resetcharacter", SEC_PLAYER, false, NULL, "", ResetCharacterCommandTable},
- {"vault", SEC_PLAYER, false, &HandleVaultCommand, "", NULL},
- {NULL, 0, false, NULL, "", NULL}
- };
- return PlayerCommandsCommandTable;
- }
- static std::string GetTimeString(uint64 time)
- {
- uint64 days = time / DAY, hours = (time % DAY) / HOUR, minute = (time % HOUR) / MINUTE;
- std::ostringstream ss;
- if (days)
- ss << days << "d ";
- if (hours)
- ss << hours << "h ";
- ss << minute << 'm';
- return ss.str();
- }
- static bool HandleWorldChatCommand(ChatHandler * handler, const char * args)
- {
- if (!handler->GetSession()->GetPlayer()->CanSpeak())
- return false;
- std::string temp = args;
- if (!args || temp.find_first_not_of(' ') == std::string::npos)
- return false;
- std::string msg = "";
- Player * player = handler->GetSession()->GetPlayer();
- switch(player->GetSession()->GetSecurity())
- {
- case SEC_PLAYER: // PLAYER
- if (player->GetTeam() == ALLIANCE)
- {
- msg += "|cff0064ff[A]|r|cff0bf10aChat: |r";
- msg += handler->GetNameLink(player);
- msg += "|cffffffff:|r |cff4387c4";
- }
- else
- {
- msg += "|cffc30000[H]|r|cff0bf10aChat: |r";
- msg += handler->GetNameLink(player);
- msg += "|cffffffff:|r |cff4387c4";
- }
- break;
- case SEC_MODERATOR: // MODERATOR
- msg += "|cffffc800<MOD>|r |cff0bf10aChat: |r";
- msg += handler->GetNameLink(player);
- msg += "|cffffffff:|r |cff4387c4";
- break;
- case SEC_GAMEMASTER: // GAMEMASTER
- msg += "|cffff5f00<GM>|r |cff0bf10aChat: |r";
- msg += handler->GetNameLink(player);
- msg += "|cffffffff:|r |cff4387c4";
- break;
- case SEC_ADMINISTRATOR: // ADMINISTARDOR
- msg += "|cffff0000<ADM>|r |cff0bf10aChat: |r";
- msg += handler->GetNameLink(player);
- msg += "|cffffffff:|r |cff4387c4";
- break;
- case SEC_CONSOLE: // Console
- msg += "|cffff0000<OWNER>|r |cff0bf10aChat: |r";
- msg += handler->GetNameLink(player);
- msg += "|cffffffff:|r |cff4387c4";
- break;
- }
- msg += args;
- sWorld->SendServerMessage(SERVER_MSG_STRING, msg.c_str(), 0);
- PreparedStatement * mt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_MUTE_TIME);
- int64 muteTime = time(NULL) + 15;
- player->GetSession()->m_muteTime = muteTime;
- mt->setInt64(0, muteTime);
- return true;
- }
- static bool HandleStartCommand(ChatHandler * handler, const char * args)
- {
- Player* player = handler->GetSession()->GetPlayer();
- if (player->IsInFlight() || player->IsInCombat())
- {
- handler->SendSysMessage("Cannot do that while combat or flying.");
- handler->SetSentErrorMessage(true);
- return false;
- }
- if (player->HasStealthAura() || player->HasFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_FEIGN_DEATH) || player->isDead())
- {
- player->ResurrectPlayer(100);
- player->TeleportTo(player->GetStartPosition());
- return true;
- }
- player->TeleportTo(player->GetStartPosition());
- return true;
- }
- static bool HandleMaxSkillsCommand(ChatHandler* handler, const char* args)
- {
- Player* player = handler->GetSession()->GetPlayer();
- if (player->HasStealthAura() || player->HasFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_FEIGN_DEATH) || player->isDead())
- {
- player->GetSession()->SendNotification("You can't chat when you're dead!");
- handler->SetSentErrorMessage(true);
- return false;
- }
- player->UpdateSkillsToMaxSkillsForLevel();
- return true;
- }
- static bool HandleResetCombatCommand(ChatHandler * handler, const char * args)
- {
- Player* player = handler->GetSession()->GetPlayer();
- if(player->IsInCombat())
- {
- player->CombatStop();
- PreparedStatement * mt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_MUTE_TIME);
- int64 muteTime = time(NULL) + 15;
- player->GetSession()->m_muteTime = muteTime;
- mt->setInt64(0, muteTime);
- return true;
- }
- return true;
- }
- static bool HandleResetInstancesCommand(ChatHandler * handler, const char * args)
- {
- Player* player = handler->GetSession()->GetPlayer();
- char* map = strtok((char*)args, " ");
- char* pDiff = strtok(NULL, " ");
- int8 diff = -1;
- if (pDiff)
- diff = atoi(pDiff);
- uint16 counter = 0;
- uint16 MapId = 0;
- for (uint8 i = 0; i < MAX_DIFFICULTY; ++i)
- {
- Player::BoundInstancesMap &binds = player->GetBoundInstances(Difficulty(i));
- for (Player::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end();)
- {
- InstanceSave* save = itr->second.save;
- if (itr->first != player->GetMapId() && (!MapId || MapId == itr->first) && (diff == -1 || diff == save->GetDifficulty()))
- {
- std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
- handler->PSendSysMessage("unbinding map: %d inst: %d perm: %s diff: %d canReset: %s TTR: %s", itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no", save->GetDifficulty(), save->CanReset() ? "yes" : "no", timeleft.c_str());
- player->UnbindInstance(itr, Difficulty(i));
- counter++;
- }
- else
- ++itr;
- }
- }
- handler->PSendSysMessage("instances unbound: %d", counter);
- return true;
- }
- static bool HandleResetCharacterInfoCommand(ChatHandler * handler, const char * args)
- {
- Player* player = handler->GetSession()->GetPlayer();
- handler->PSendSysMessage("- The system will clean your char, this include: Spells, Talents, Skills and Others.");
- handler->PSendSysMessage("- |cffff0000Is strongly recommended that you store your equipped items in the bag or vault.|r");
- handler->PSendSysMessage("- If you are sure of this, use the subcommand \"reset\"");
- return true;
- }
- static bool HandleResetCharacterResetCommand(ChatHandler * handler, const char * args)
- {
- Player* player = handler->GetSession()->GetPlayer();
- if (player->IsInFlight() || player->IsInCombat())
- {
- handler->SendSysMessage("Cannot do that while combat or flying.");
- handler->SetSentErrorMessage(true);
- return false;
- }
- if (player->HasStealthAura() || player->HasFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_FEIGN_DEATH) || player->isDead())
- {
- player->GetSession()->SendNotification("You can't chat when you're dead!");
- handler->SetSentErrorMessage(true);
- return false;
- }
- Player* player = handler->GetSession()->GetPlayer();
- player->resetSpells();
- player->resetTalents(true);
- player->SendTalentsInfoData(false);
- player->InitStatsForLevel(true);
- player->GetSession()->LogoutPlayer(false);
- return true;
- }
- static bool HandleVaultCommand(ChatHandler * handler, const char * args)
- {
- Player* player = handler->GetSession()->GetPlayer();
- if (player->IsInFlight() || player->IsInCombat())
- {
- handler->SendSysMessage("Cannot do that while combat or flying.");
- handler->SetSentErrorMessage(true);
- return false;
- }
- if (player->HasStealthAura() || player->HasFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_FEIGN_DEATH) || player->isDead())
- {
- player->GetSession()->SendNotification("You can't chat when you're dead!");
- handler->SetSentErrorMessage(true);
- return false;
- }
- handler->GetSession()->SendShowBank(handler->GetSession()->GetPlayer()->GetGUID());
- return true;
- }
- };
- void AddSC_PlayerCommands()
- {
- new PlayerCommands();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement