Advertisement
Guest User

Final Version char_inv Corruption

a guest
Sep 23rd, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.16 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.        
  24.         for (uint32 i = INVENTORY_SLOT_BAG_START; i < INVENTORY_SLOT_BAG_END; i++)
  25.         {
  26.             Item* bag = Item::CreateItem(73005, 1, player);
  27.             player->EquipItem(i, bag, true);
  28.         }
  29.  
  30.         // Inital query to select the guid and entry of all of the items that belong to the player
  31.         auto result1 = CharacterDatabase.PQuery("SELECT guid, itemEntry, count FROM item_instance WHERE owner_guid = %u", guid);
  32.         if (!result1)
  33.             return;
  34.         do
  35.         {
  36.             LostItemContainer.insert({ guid, std::make_tuple(result1->Fetch()[0].GetUInt32(), result1->Fetch()[1].GetUInt32(), result1->Fetch()[2].GetUInt32()) });
  37.         } while (result1->NextRow());
  38.  
  39.         for (auto &it = LostItemContainer.find(guid); it != LostItemContainer.end(); it++)
  40.         {
  41.             ItemTemplate const* pProto = sObjectMgr->GetItemTemplate(std::get<1>(it->second));
  42.             if (!pProto)
  43.                 continue;
  44.             if (!player->AddItem(std::get<1>(it->second), std::get<2>(it->second)))
  45.                 player->SendItemRetrievalMail(std::get<1>(it->second), std::get<2>(it->second));
  46.         }
  47.         CharacterDatabase.PExecute("UPDATE characters SET reclaimed = 1 WHERE guid=%u", guid);
  48.         ChatHandler(player->GetSession()).SendSysMessage("|cffff0000CHECK YOUR MAIL!\nYou have successfully reclaimed your items. We apologize for the inconvenience.");
  49.         player->GetSession()->SendAreaTriggerMessage("|cffff0000CHECK YOUR MAIL!!!\nYou have successfully reclaimed your items. We apologize for the inconvenience.");
  50.     }
  51. };
  52.  
  53. void AddSC_ps_give_back_items()
  54. {
  55.     new ps_give_back_items();
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement