Advertisement
Guest User

Final Version char_inv Corruption

a guest
Sep 23rd, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.07 KB | None | 0 0
  1.  
  2. std::multimap<uint32, std::tuple<uint32, uint32, uint32>> LostItemContainer;
  3.  
  4. class ps_give_back_items : public PlayerScript
  5. {
  6. public:
  7.     ps_give_back_items() : PlayerScript("give_items") {}
  8.  
  9.     void OnLogin(Player* player) override
  10.     {
  11.         bool hasReclaimed = false;
  12.         auto result = CharacterDatabase.PQuery("SELECT reclaimed FROM characters WHERE guid=%u", player->GetGUIDLow());
  13.         if (!result)
  14.             return;
  15.         hasReclaimed = result->Fetch()[0].GetUInt16() == 1 ? true : false;
  16.  
  17.         // We check if the player has the 4 initial bags, if they do, we stop the system
  18.         if (hasReclaimed)
  19.             return;
  20.  
  21.         uint32 guid = player->GetGUIDLow();
  22.         // Equip 4 bags to players so that there's room to add items
  23.         Item* bag = Item::CreateItem(73005, 1, player);
  24.         for (uint32 i = INVENTORY_SLOT_BAG_START; i < INVENTORY_SLOT_BAG_END; i++)
  25.             player->EquipItem(i, bag, true);
  26.  
  27.         // Inital query to select the guid and entry of all of the items that belong to the player
  28.         auto result1 = CharacterDatabase.PQuery("SELECT guid, itemEntry, count FROM item_instance WHERE owner_guid = %u", guid);
  29.         if (!result1)
  30.             return;
  31.         do
  32.         {
  33.             LostItemContainer.insert({ guid, std::make_tuple(result1->Fetch()[0].GetUInt32(), result1->Fetch()[1].GetUInt32(), result1->Fetch()[2].GetUInt32()) });
  34.         } while (result1->NextRow());
  35.  
  36.         for (auto &it = LostItemContainer.find(guid); it != LostItemContainer.end(); it++)
  37.         {
  38.             ItemTemplate const* pProto = sObjectMgr->GetItemTemplate(std::get<1>(it->second));
  39.             if (!pProto)
  40.                 continue;
  41.             player->SendItemRetrievalMail(std::get<1>(it->second), std::get<2>(it->second));
  42.         }
  43.         CharacterDatabase.PExecute("UPDATE characters SET reclaimed = 1 WHERE guid=%u", guid);
  44.         ChatHandler(player->GetSession()).SendSysMessage("|cffff0000CHECK YOUR MAIL!\nYou have successfully reclaimed your items. We apologize for the inconvenience.");
  45.         player->GetSession()->SendAreaTriggerMessage("|cffff0000CHECK YOUR MAIL!!!\nYou have successfully reclaimed your items. We apologize for the inconvenience.");
  46.     }
  47. };
  48.  
  49. void AddSC_ps_give_back_items()
  50. {
  51.     new ps_give_back_items();
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement