Advertisement
julienanid

[Trinity]Player Commands

Sep 17th, 2013
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.35 KB | None | 0 0
  1. /*
  2. <--------------------------------------------------------------------------->
  3.  - Developer(s): Parranoia,Mthsena.
  4.  - Edited & Updated:Synth
  5.  - Complete: 100%
  6.  - ScriptName: 'PlayerCommands'
  7.  - Comment: Untested
  8.  - Updated - 9/17/2013
  9.  - Shared for:Emudevs
  10. <--------------------------------------------------------------------------->
  11. */
  12.  
  13. #include "ScriptPCH.h"
  14. #include "Chat.h"
  15. #include "InstanceSaveMgr.h"
  16.  
  17. class PlayerCommands : public CommandScript
  18. {
  19. public:
  20.     PlayerCommands() : CommandScript("PlayerCommands"){}
  21.  
  22.     ChatCommand * GetCommands() const
  23.     {
  24.         static ChatCommand ResetCharacterCommandTable[] =
  25.         {
  26.             {"info", SEC_PLAYER, false, &HandleResetCharacterInfoCommand, "", NULL},
  27.             {"reset", SEC_PLAYER, false, &HandleResetCharacterResetCommand, "", NULL},
  28.             {NULL, 0, false, NULL, "", NULL}
  29.         };
  30.         static ChatCommand PlayerCommandsCommandTable[] =
  31.         {
  32.             {"chat", SEC_PLAYER, false, &HandleWorldChatCommand, "", NULL},
  33.             {"start", SEC_PLAYER, false, &HandleStartCommand, "", NULL},
  34.             {"maxskills", SEC_PLAYER, false, &HandleMaxSkillsCommand, "", NULL},
  35.             {"resetcombat", SEC_PLAYER, false, &HandleResetCombatCommand, "", NULL},
  36.             {"resetinstances", SEC_PLAYER, false, &HandleResetInstancesCommand, "", NULL},
  37.             {"resetcharacter", SEC_PLAYER, false, NULL, "", ResetCharacterCommandTable},
  38.             {"vault", SEC_PLAYER, false, &HandleVaultCommand, "", NULL},
  39.             {NULL, 0, false, NULL, "", NULL}
  40.         };
  41.  
  42.         return PlayerCommandsCommandTable;
  43.     }
  44.     static std::string GetTimeString(uint64 time)
  45.     {
  46.         uint64 days = time / DAY, hours = (time % DAY) / HOUR, minute = (time % HOUR) / MINUTE;
  47.         std::ostringstream ss;
  48.  
  49.         if (days)
  50.             ss << days << "d ";
  51.  
  52.         if (hours)
  53.             ss << hours << "h ";
  54.         ss << minute << 'm';
  55.         return ss.str();
  56.     }
  57.     static bool HandleWorldChatCommand(ChatHandler * handler, const char * args)
  58.     {
  59.         if (!handler->GetSession()->GetPlayer()->CanSpeak())
  60.             return false;
  61.  
  62.         std::string temp = args;
  63.  
  64.         if (!args || temp.find_first_not_of(' ') == std::string::npos)
  65.             return false;
  66.  
  67.         std::string msg = "";
  68.  
  69.         Player * player = handler->GetSession()->GetPlayer();
  70.  
  71.         switch(player->GetSession()->GetSecurity())
  72.         {
  73.         case SEC_PLAYER: // PLAYER
  74.             if (player->GetTeam() == ALLIANCE)
  75.             {
  76.                 msg += "|cff0064ff[A]|r|cff0bf10aChat: |r";
  77.                 msg += handler->GetNameLink(player);
  78.                 msg += "|cffffffff:|r |cff4387c4";
  79.             }
  80.             else
  81.             {
  82.                 msg += "|cffc30000[H]|r|cff0bf10aChat: |r";
  83.                 msg += handler->GetNameLink(player);
  84.                 msg += "|cffffffff:|r |cff4387c4";
  85.             }
  86.             break;
  87.         case SEC_MODERATOR: // MODERATOR
  88.             msg += "|cffffc800<MOD>|r |cff0bf10aChat: |r";
  89.             msg += handler->GetNameLink(player);
  90.             msg += "|cffffffff:|r |cff4387c4";
  91.             break;
  92.         case SEC_GAMEMASTER: // GAMEMASTER
  93.             msg += "|cffff5f00<GM>|r |cff0bf10aChat: |r";
  94.             msg += handler->GetNameLink(player);
  95.             msg += "|cffffffff:|r |cff4387c4";
  96.             break;
  97.         case SEC_ADMINISTRATOR: // ADMINISTARDOR
  98.             msg += "|cffff0000<ADM>|r |cff0bf10aChat: |r";
  99.             msg += handler->GetNameLink(player);
  100.             msg += "|cffffffff:|r |cff4387c4";
  101.             break;
  102.         case SEC_CONSOLE: // Console
  103.             msg += "|cffff0000<OWNER>|r |cff0bf10aChat: |r";
  104.             msg += handler->GetNameLink(player);
  105.             msg += "|cffffffff:|r |cff4387c4";
  106.             break;
  107.         }
  108.  
  109.         msg += args;
  110.         sWorld->SendServerMessage(SERVER_MSG_STRING, msg.c_str(), 0);
  111.  
  112.         PreparedStatement * mt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_MUTE_TIME);
  113.         int64 muteTime = time(NULL) + 15;
  114.         player->GetSession()->m_muteTime = muteTime;
  115.         mt->setInt64(0, muteTime);
  116.         return true;
  117.     }
  118.     static bool HandleStartCommand(ChatHandler * handler, const char * args)
  119.     {
  120.         Player* player = handler->GetSession()->GetPlayer();
  121.  
  122.         if (player->IsInFlight() || player->IsInCombat())
  123.         {
  124.             handler->SendSysMessage("Cannot do that while combat or flying.");
  125.             handler->SetSentErrorMessage(true);
  126.             return false;
  127.         }
  128.  
  129.         if (player->HasStealthAura() || player->HasFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_FEIGN_DEATH) || player->isDead())
  130.         {
  131.             player->ResurrectPlayer(100);
  132.             player->TeleportTo(player->GetStartPosition());
  133.             return true;
  134.         }
  135.  
  136.         player->TeleportTo(player->GetStartPosition());
  137.         return true;
  138.     }
  139.     static bool HandleMaxSkillsCommand(ChatHandler* handler, const char* args)
  140.     {
  141.  
  142.         Player* player = handler->GetSession()->GetPlayer();
  143.  
  144.         if (player->HasStealthAura() || player->HasFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_FEIGN_DEATH) || player->isDead())
  145.         {
  146.             player->GetSession()->SendNotification("You can't chat when you're dead!");
  147.             handler->SetSentErrorMessage(true);
  148.             return false;
  149.         }
  150.  
  151.         player->UpdateSkillsToMaxSkillsForLevel();
  152.         return true;
  153.     }
  154.     static bool HandleResetCombatCommand(ChatHandler * handler, const char * args)
  155.     {
  156.         Player* player = handler->GetSession()->GetPlayer();
  157.  
  158.         if(player->IsInCombat())
  159.         {  
  160.             player->CombatStop();
  161.             PreparedStatement * mt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_MUTE_TIME);
  162.             int64 muteTime = time(NULL) + 15;
  163.             player->GetSession()->m_muteTime = muteTime;
  164.             mt->setInt64(0, muteTime);
  165.             return true;
  166.         }
  167.         return true;
  168.     }
  169.     static bool HandleResetInstancesCommand(ChatHandler * handler, const char * args)
  170.     {
  171.         Player* player = handler->GetSession()->GetPlayer();
  172.  
  173.         char* map = strtok((char*)args, " ");
  174.         char* pDiff = strtok(NULL, " ");
  175.         int8 diff = -1;
  176.  
  177.         if (pDiff)
  178.             diff = atoi(pDiff);
  179.         uint16 counter = 0;
  180.         uint16 MapId = 0;
  181.  
  182.         for (uint8 i = 0; i < MAX_DIFFICULTY; ++i)
  183.         {
  184.             Player::BoundInstancesMap &binds = player->GetBoundInstances(Difficulty(i));
  185.             for (Player::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end();)
  186.             {
  187.                 InstanceSave* save = itr->second.save;
  188.  
  189.                 if (itr->first != player->GetMapId() && (!MapId || MapId == itr->first) && (diff == -1 || diff == save->GetDifficulty()))
  190.                 {
  191.                     std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
  192.                     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());
  193.                     player->UnbindInstance(itr, Difficulty(i));
  194.                     counter++;
  195.                 }
  196.                 else
  197.                     ++itr;
  198.             }
  199.         }
  200.  
  201.         handler->PSendSysMessage("instances unbound: %d", counter);
  202.         return true;
  203.     }
  204.     static bool HandleResetCharacterInfoCommand(ChatHandler * handler, const char * args)
  205.     {
  206.         Player* player = handler->GetSession()->GetPlayer();
  207.  
  208.         handler->PSendSysMessage("- The system will clean your char, this include: Spells, Talents, Skills and Others.");
  209.         handler->PSendSysMessage("- |cffff0000Is strongly recommended that you store your equipped items in the bag or vault.|r");
  210.         handler->PSendSysMessage("- If you are sure of this, use the subcommand \"reset\"");
  211.         return true;
  212.     }
  213.     static bool HandleResetCharacterResetCommand(ChatHandler * handler, const char * args)
  214.     {
  215.         Player* player = handler->GetSession()->GetPlayer();
  216.  
  217.         if (player->IsInFlight() || player->IsInCombat())
  218.         {
  219.             handler->SendSysMessage("Cannot do that while combat or flying.");
  220.             handler->SetSentErrorMessage(true);
  221.             return false;
  222.         }
  223.  
  224.         if (player->HasStealthAura() || player->HasFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_FEIGN_DEATH) || player->isDead())
  225.         {
  226.             player->GetSession()->SendNotification("You can't chat when you're dead!");
  227.             handler->SetSentErrorMessage(true);
  228.             return false;
  229.         }
  230.  
  231.         Player* player = handler->GetSession()->GetPlayer();
  232.         player->resetSpells();
  233.         player->resetTalents(true);
  234.         player->SendTalentsInfoData(false);
  235.         player->InitStatsForLevel(true);
  236.         player->GetSession()->LogoutPlayer(false);
  237.         return true;
  238.     }
  239.     static bool HandleVaultCommand(ChatHandler * handler, const char * args)
  240.     {
  241.         Player* player = handler->GetSession()->GetPlayer();
  242.  
  243.         if (player->IsInFlight() || player->IsInCombat())
  244.         {
  245.             handler->SendSysMessage("Cannot do that while combat or flying.");
  246.             handler->SetSentErrorMessage(true);
  247.             return false;
  248.         }
  249.  
  250.         if (player->HasStealthAura() || player->HasFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_FEIGN_DEATH) || player->isDead())
  251.         {
  252.             player->GetSession()->SendNotification("You can't chat when you're dead!");
  253.             handler->SetSentErrorMessage(true);
  254.             return false;
  255.         }
  256.  
  257.         handler->GetSession()->SendShowBank(handler->GetSession()->GetPlayer()->GetGUID());
  258.         return true;
  259.     }
  260. };
  261.  
  262. void AddSC_PlayerCommands()
  263. {
  264.     new PlayerCommands();
  265. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement