Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- std::multimap<uint32, std::tuple<uint32, uint32, uint32>> LostItemContainer;
- class ps_give_back_items : public PlayerScript
- {
- public:
- ps_give_back_items() : PlayerScript("give_items") {}
- void OnLogin(Player* player) override
- {
- bool hasReclaimed = false;
- auto result = CharacterDatabase.PQuery("SELECT reclaimed FROM characters WHERE guid=%u", player->GetGUIDLow());
- if (!result)
- return;
- hasReclaimed = result->Fetch()[0].GetUInt16() == 1 ? true : false;
- // We check if the player has the 4 initial bags, if they do, we stop the system
- if (hasReclaimed)
- return;
- uint32 guid = player->GetGUIDLow();
- // Equip 4 bags to players so that there's room to add items
- for (uint32 i = INVENTORY_SLOT_BAG_START; i < INVENTORY_SLOT_BAG_END; i++)
- {
- Item* bag = Item::CreateItem(73005, 1, player);
- player->EquipItem(i, bag, true);
- }
- // Inital query to select the guid and entry of all of the items that belong to the player
- auto result1 = CharacterDatabase.PQuery("SELECT guid, itemEntry, count FROM item_instance WHERE owner_guid = %u", guid);
- if (!result1)
- return;
- do
- {
- LostItemContainer.insert({ guid, std::make_tuple(result1->Fetch()[0].GetUInt32(), result1->Fetch()[1].GetUInt32(), result1->Fetch()[2].GetUInt32()) });
- } while (result1->NextRow());
- for (auto &it = LostItemContainer.find(guid); it != LostItemContainer.end(); it++)
- {
- ItemTemplate const* pProto = sObjectMgr->GetItemTemplate(std::get<1>(it->second));
- if (!pProto)
- continue;
- if (!player->AddItem(std::get<1>(it->second), std::get<2>(it->second)))
- player->SendItemRetrievalMail(std::get<1>(it->second), std::get<2>(it->second));
- }
- CharacterDatabase.PExecute("UPDATE characters SET reclaimed = 1 WHERE guid=%u", guid);
- ChatHandler(player->GetSession()).SendSysMessage("|cffff0000CHECK YOUR MAIL!\nYou have successfully reclaimed your items. We apologize for the inconvenience.");
- player->GetSession()->SendAreaTriggerMessage("|cffff0000CHECK YOUR MAIL!!!\nYou have successfully reclaimed your items. We apologize for the inconvenience.");
- }
- };
- void AddSC_ps_give_back_items()
- {
- new ps_give_back_items();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement