bool ChatHandler::HandleAddInvItemCommand(const char* args, WorldSession* m_session) { uint32 itemid, count = 1; int32 randomprop = 0; int32 numadded = 0; if(strlen(args) < 1) return false; if(sscanf(args, "%u %u %d", &itemid, &count, &randomprop) < 1) { // check for item link uint16 ofs = GetItemIDFromLink(args, &itemid); if(!itemid) return false; sscanf(args + ofs, "%u %d", &count, &randomprop); // these may be empty } Player* chr = getSelectedChar(m_session, false); if(!chr) chr = m_session->GetPlayer(); ItemPrototype* it = ItemPrototypeStorage.LookupEntry(itemid); if(it) { numadded -= chr->GetItemInterface()->GetItemCount(itemid); bool result = false; result = chr->GetItemInterface()->AddItemById(itemid, count, randomprop); numadded += chr->GetItemInterface()->GetItemCount(itemid); if(result == true) { if(count == 0) sGMLog.writefromsession(m_session, "used add item command, item id %u [%s], quantity %u, to %s", it->ItemId, it->Name1, numadded, chr->GetName()); else sGMLog.writefromsession(m_session, "used add item command, item id %u [%s], quantity %u (only %lu added due to full inventory), to %s", it->ItemId, it->Name1, numadded, numadded, chr->GetName()); char messagetext[512]; snprintf(messagetext, 512, "Added item %s (id: %d), quantity %u, to %s's inventory.", GetItemLinkByProto(it, m_session->language).c_str(), (unsigned int)it->ItemId, numadded, chr->GetName()); SystemMessage(m_session, messagetext); //snprintf(messagetext, 128, "%s added item %d (%s) to your inventory.", m_session->GetPlayer()->GetName(), (unsigned int)itemid, it->Name1); snprintf(messagetext, 512, "%s added item %s, quantity %u, to your inventory.", m_session->GetPlayer()->GetName(), GetItemLinkByProto(it, chr->GetSession()->language).c_str(), numadded); SystemMessageToPlr(chr, messagetext); } else SystemMessageToPlr(chr, "Failed to add item."); return true; } else { RedSystemMessage(m_session, "Item %d is not a valid item!", itemid); return false; } }
bool ChatHandler::HandleItemRemoveCommand(const char* args, WorldSession *m_session) { if (!args) return false; Creature* pCreature = getSelectedCreature(m_session, false); if(!pCreature || !(pCreature->HasNpcFlag(UNIT_NPC_FLAG_VENDOR) || pCreature->HasNpcFlag(UNIT_NPC_FLAG_ARMORER))) { SystemMessage(m_session, "You should select a vendor."); return true; } uint32 itemguid = 0; if(sscanf(args, "%u", &itemguid) < 1) { // check for item link GetItemIDFromLink(args, &itemguid); if(itemguid == 0) return false; } if(itemguid == 0) return false; std::stringstream sstext; int slot = pCreature->GetSlotByItemId(itemguid); if(slot != -1) { std::stringstream ss; ss << "DELETE FROM vendors WHERE entry = '" << pCreature->GetEntry() << "' AND vendormask = '" << pCreature->VendorMask << "' AND item = " << itemguid << " LIMIT 1;"; WorldDatabase.Execute( ss.str().c_str() ); pCreature->RemoveVendorItem(itemguid); ItemPrototype* tmpItem = ItemPrototypeStorage.LookupEntry(itemguid); if(tmpItem) sstext << "Item '" << itemguid << "' '" << tmpItem->Name1 << "' Deleted from list" << '\0'; else sstext << "Item '" << itemguid << "' Deleted from list" << '\0'; } else { sstext << "Item '" << itemguid << "' Not Found in List." << '\0'; } SystemMessage(m_session, sstext.str().c_str()); return true; }
bool ChatHandler::HandleItemCommand(const char* args, WorldSession *m_session) { if(strlen(args) < 1) return false; Creature* pCreature = getSelectedCreature(m_session, false); if(!pCreature || !pCreature->m_spawn || !(pCreature->HasNpcFlag(UNIT_NPC_FLAG_VENDOR) || pCreature->HasNpcFlag(UNIT_NPC_FLAG_ARMORER))) { SystemMessage(m_session, "You should select a vendor."); return true; } int amount = 1; uint32 item = 0, extendedcost = 0, vendormask = 0; if(sscanf(args, "%u %u %u %u", &item, &amount, &extendedcost, &vendormask) < 1) { // check for item link GetItemIDFromLink(args, &item); if(item == 0) return false; } if(item == 0) return false; if(vendormask == 0) vendormask = pCreature->m_spawn->vendormask; ItemPrototype* tmpItem = ItemPrototypeStorage.LookupEntry(item); std::stringstream sstext; if(tmpItem) { std::stringstream ss; ss << "INSERT INTO vendors(entry, item, amount, extendedcost, vendormask) VALUES ('" << pCreature->GetEntry() << "', '" << item << "', '" << amount << "', " << extendedcost << ", " << vendormask << " );"; WorldDatabase.Execute( ss.str().c_str() ); pCreature->AddVendorItem(item, amount, vendormask, extendedcost); sstext << "Item '" << item << "' '" << tmpItem->Name1 << "' Added to list" << '\0'; } else sstext << "Item '" << item << "' Not Found in Database." << '\0'; sWorld.LogGM(m_session, "added item %u to vendor %u", item, pCreature->GetEntry()); SystemMessage(m_session, sstext.str().c_str()); return true; }