Advertisement
Rochet2

Level reset NPC

Aug 22nd, 2012
477
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.20 KB | None | 0 0
  1. // Made by Rochet2
  2. #include "ScriptPCH.h"
  3.  
  4. class PRESTIGE_NPC : public CreatureScript
  5. {
  6. public:
  7.     PRESTIGE_NPC() : CreatureScript("PRESTIGE_NPC") { }
  8.  
  9.     bool OnGossipHello(Player* player, Creature* creature)
  10.     {
  11.         player->ADD_GOSSIP_ITEM_EXTENDED(GOSSIP_ICON_CHAT, "Exchange level 80 to 100k gold", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 2, "WARNING!\nThis will reset your level to 1", 0, false);
  12.         player->ADD_GOSSIP_ITEM(GOSSIP_ICON_TALK, "Nevermind", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 1);
  13.         player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
  14.         return true;
  15.     }
  16.  
  17.     bool OnGossipSelect(Player* player, Creature* creature, uint32 sender, uint32 action)
  18.     {
  19.         player->PlayerTalkClass->ClearMenus();
  20.         player->CLOSE_GOSSIP_MENU();
  21.         if (sender == GOSSIP_SENDER_MAIN && action == GOSSIP_ACTION_INFO_DEF + 2)
  22.         {
  23.             if (player->getLevel() != 80)
  24.                 player->GetSession()->SendNotification("You need to be level 80");
  25.             else
  26.             {
  27.                 if (ResetPlayerLevel(player))
  28.                 {
  29.                     player->ModifyMoney(1000000000);
  30.                     for (uint8 slot = SLOT_HEAD; slot < SLOT_EMPTY; slot++)
  31.                     {
  32.                         if (player->CanUseItem(player->GetItemByPos(NULL_BAG, slot)) != EQUIP_ERR_OK)
  33.                             player->SetVisibleItemSlot(slot, NULL);
  34.                     }
  35.                     player->GetSession()->LogoutPlayer(true);
  36.                 }
  37.                 else
  38.                     player->GetSession()->SendNotification("ERROR: can not reset level");
  39.             }
  40.         }
  41.         return true;
  42.     }
  43.  
  44.     bool ResetPlayerLevel(Player* player)
  45.     {
  46.         if (!HandleResetStatsOrLevelHelper(player))
  47.             return false;
  48.  
  49.         uint8 oldLevel = player->getLevel();
  50.  
  51.         // set starting level
  52.         uint32 startLevel = player->getClass() != CLASS_DEATH_KNIGHT
  53.             ? sWorld->getIntConfig(CONFIG_START_PLAYER_LEVEL)
  54.             : sWorld->getIntConfig(CONFIG_START_HEROIC_PLAYER_LEVEL);
  55.  
  56.         player->_ApplyAllLevelScaleItemMods(false);
  57.         player->SetLevel(startLevel);
  58.         player->InitRunes();
  59.         player->InitStatsForLevel(true);
  60.         player->InitTaxiNodesForLevel();
  61.         player->InitGlyphsForLevel();
  62.         player->InitTalentForLevel();
  63.         player->SetUInt32Value(PLAYER_XP, 0);
  64.         player->resetSpells(true);
  65.  
  66.         player->_ApplyAllLevelScaleItemMods(true);
  67.  
  68.         // reset level for pet
  69.         if (Pet* pet = player->GetPet())
  70.             pet->SynchronizeLevelWithOwner();
  71.  
  72.         sScriptMgr->OnPlayerLevelChanged(player, oldLevel);
  73.         return true;
  74.     }
  75.  
  76.     bool HandleResetStatsOrLevelHelper(Player* player)
  77.     {
  78.         ChrClassesEntry const* classEntry = sChrClassesStore.LookupEntry(player->getClass());
  79.         if (!classEntry)
  80.         {
  81.             sLog->outError("Class %u not found in DBC (Wrong DBC files?)", player->getClass());
  82.             return false;
  83.         }
  84.  
  85.         uint8 powerType = classEntry->powerType;
  86.  
  87.         // reset m_form if no aura
  88.         if (!player->HasAuraType(SPELL_AURA_MOD_SHAPESHIFT))
  89.             player->SetShapeshiftForm(FORM_NONE);
  90.  
  91.         player->SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS, DEFAULT_WORLD_OBJECT_SIZE);
  92.         player->SetFloatValue(UNIT_FIELD_COMBATREACH, DEFAULT_COMBAT_REACH);
  93.  
  94.         player->setFactionForRace(player->getRace());
  95.  
  96.         player->SetUInt32Value(UNIT_FIELD_BYTES_0, ((player->getRace()) | (player->getClass() << 8) | (player->getGender() << 16) | (powerType << 24)));
  97.  
  98.         // reset only if player not in some form;
  99.         if (player->GetShapeshiftForm() == FORM_NONE)
  100.             player->InitDisplayIds();
  101.  
  102.         player->SetByteValue(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_PVP);
  103.  
  104.         player->SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE);
  105.  
  106.         //-1 is default value
  107.         player->SetUInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX, uint32(-1));
  108.  
  109.         //player->SetUInt32Value(PLAYER_FIELD_BYTES, 0xEEE00000);
  110.         return true;
  111.     }
  112. };
  113.  
  114. void AddSC_PRESTIGE_NPC()
  115. {
  116.     new PRESTIGE_NPC();
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement