Jump to content

Delete Item From Inventory aCis 374


Acacia

Recommended Posts

This code show up a window with a list of ur target's inventory  , and removes an item or more .

code is not mine i found it on net i think credits go to Zealar , i just readapted it to 374 aCis rev .
anyway it may come usefull for wiping bot's inv or ... w/e 

code tested and workin .

 

package net.sf.l2j.gameserver.handler.admincommandhandlers;

import java.util.Set;

import net.sf.l2j.commons.lang.StringUtil;

import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
import net.sf.l2j.gameserver.model.actor.instance.Player;
import net.sf.l2j.gameserver.model.item.instance.ItemInstance;
import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;


/**
 * This class handles following admin commands:
 * <ul>
 * <li>show_ivetory</li>
 * <li>delete_item</li>
 * </ul>
 * @author Zealar
 */

public class AdminInventory implements IAdminCommandHandler
{
	private static final String[] ADMIN_COMMANDS =
	{
		"admin_show_inventory",
		"admin_delete_item"
	};
	
	@Override
	public boolean useAdminCommand(String command, Player activeChar)
	{
		if ((activeChar.getTarget() == null))
		{
			activeChar.sendMessage("Select a target");
			return false;
		}
		
		if (!(activeChar.getTarget() instanceof Player))
		{
			activeChar.sendMessage("Target need to be player");
			return false;
		}
		
		Player player = activeChar.getTarget().getActingPlayer();
		
		if (command.startsWith(ADMIN_COMMANDS[0]))
		{
			if (command.length() > ADMIN_COMMANDS[0].length())
			{
				String com = command.substring(ADMIN_COMMANDS[0].length() + 1);
				if (StringUtil.isDigit(com))
				{
					showItemsPage(activeChar, Integer.parseInt(com));
				}
			}
			
			else
			{
				showItemsPage(activeChar, 0);
			}
		}
		else if (command.contains(ADMIN_COMMANDS[1]))
		{
			String val = command.substring(ADMIN_COMMANDS[1].length() + 1);
			
			player.destroyItem("GM Destroy", Integer.parseInt(val), player.getInventory().getItemByObjectId(Integer.parseInt(val)).getCount(), null, true);
			showItemsPage(activeChar, 0);
		}
		
		return true;
	}
	
	private static void showItemsPage(Player activeChar, int page)
	{
		final Player target = activeChar.getTarget().getActingPlayer();
		

		final Set<ItemInstance> items = target.getInventory().getItems();
		
		int maxItemsPerPage = 16;
		int maxPages = items.size() / maxItemsPerPage;
		if (items.size() > (maxItemsPerPage * maxPages))
		{
			maxPages++;
		}
	
		if (page > maxPages)
		{
			page = maxPages;
		}
		
		int itemsStart = maxItemsPerPage * page;
		int itemsEnd = items.size();
		if ((itemsEnd - itemsStart) > maxItemsPerPage)
		{
			itemsEnd = itemsStart + maxItemsPerPage;
		}
		
	final NpcHtmlMessage adminReply = new NpcHtmlMessage(0);
		adminReply.setFile("data/html/admin/inventory.htm");
		adminReply.replace("%PLAYER_NAME%", target.getName());
		
		StringBuilder sbPages = new StringBuilder();
		for (int x = 0; x < maxPages; x++)
		{
			int pagenr = x + 1;
			sbPages.append("<td><button value=\"" + String.valueOf(pagenr) + "\" action=\"bypass -h admin_show_inventory " + String.valueOf(x) + "\" width=14 height=14 back=\"sek.cbui67\" fore=\"sek.cbui67\"></td>");
		}
		
		adminReply.replace("%PAGES%", sbPages.toString());
		
		StringBuilder sbItems = new StringBuilder();
		
		for (ItemInstance item: items)
		{
			sbItems.append("<tr><td><button action=\"bypass -h admin_delete_item " + String.valueOf(item.getObjectId()) + "\" width=16 height=16 back=\"L2UI.bbs_delete\" fore=\"L2UI.bbs_delete\">" + "</td>");
			sbItems.append("<td width=60>" + item.getName() + "</td></tr><br>");
		}
		
		adminReply.replace("%ITEMS%", sbItems.toString());
		
		activeChar.sendPacket(adminReply);
	}
	
	@Override
	public String[] getAdminCommandList()
	{
		return ADMIN_COMMANDS;
	}
} 

register the handler

 

 

and  create inventory.htm into  gameserver/data/html/admin 


<html><body><title>Inventory : %PLAYER_NAME%</title>
<center>
<table width=270>
 <tr>
 %PAGES%
 </tr>
</table>

___________________________________
</center>
<br>
<table width=270>
 %ITEMS%
</table>
</body>
</html>

 

Edited by Kishin
  • Upvote 2
Link to comment
Share on other sites

isDigit(String text)  is already part of StringUtil.

 

You got already ingame, a way to see inventories using alt+g > Inventory (redundant with show_inventory).

 

I introduced a way to easy cut pages (see //knownlist for exemple - but it's used on any page system normally).

 

It's optional, but there is no way to remove a quantity for a stackable.

 

For wiping all items, you should use ItemContainer#destroyAllItems(String process, Player actor, WorldObject reference) and introduces a new admincommand (delete_all_items, I guess) rather than clicking on every single item from inventory (up to 120 items for dwarves, 80 for regular ppls).

Link to comment
Share on other sites

2 hours ago, Tryskell said:

isDigit(String text)  is already part of StringUtil.

 

You got already ingame, a way to see inventories using alt+g > Inventory (redundant with show_inventory).

 

I introduced a way to easy cut pages (see //knownlist for exemple - but it's used on any page system normally).

 

It's optional, but there is no way to remove a quantity for a stackable.

 

For wiping all items, you should use ItemContainer#destroyAllItems(String process, Player actor, WorldObject reference) and introduces a new admincommand (delete_all_items, I guess) rather than clicking on every single item from inventory (up to 120 items for dwarves, 80 for regular ppls).

didnt knew about the isDigit in string , i updated post , as for others its just handfull on pvp server to wipe a specific farm item or more from inv ,  can be edited to support iconstable .


wipAAkw.png

Edited by Kishin
Link to comment
Share on other sites

  • 4 years later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...