Jump to content

Recommended Posts

Posted (edited)

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
Posted

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).

Posted (edited)
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
  • 4 years later...
  • 8 months later...
Posted (edited)
On 12/29/2023 at 4:34 PM, MoodFreak said:

I tested this code, I think it have the problem with pages, it do not transfer the items to next pages and it gives the error cause of too long html.

well i didnt used to had that issue u reffering , u can always lower the page value that would show on each page . keep in mind it was taken  from h5 that it can handle more html length than interlude .

 

package handlers.admincommandhandlers;

import org.l2jmobius.gameserver.handler.IAdminCommandHandler;
import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.Player;
import org.l2jmobius.gameserver.model.item.instance.Item;
import org.l2jmobius.gameserver.network.SystemMessageId;
import org.l2jmobius.gameserver.network.serverpackets.NpcHtmlMessage;
import org.l2jmobius.gameserver.util.Util;

public class AdminInventory implements IAdminCommandHandler {

    private static final String[] ADMIN_COMMANDS =
            {
                    "admin_showinv",
                    "admin_delete_item"
            };

    @Override
    public boolean useAdminCommand(String command, Player activeChar)
    {

        WorldObject target = activeChar.getTarget();

        if (target == null || !target.isPlayer())  {
            activeChar.sendPacket(SystemMessageId.INVALID_TARGET);
            return false;
        }

        if (command.startsWith(ADMIN_COMMANDS[0]))
        {
            if (command.length() > ADMIN_COMMANDS[0].length())
            {
                String com = command.substring(ADMIN_COMMANDS[0].length() + 1);
                if (Util.isDigit(com))
                {
                    showItemsPage(activeChar, Integer.parseInt(com));
                }
            }
            else
            {
                showItemsPage(activeChar, 0);
            }
        }

        int count = 1;
        if (command.contains(ADMIN_COMMANDS[1])) {
            String[] parts = command.split(" ");
            if (parts.length == 3) {
                try {
                    count = Integer.parseInt(parts[2]);
                } catch (NumberFormatException e) {
                    activeChar.sendMessage("Invalid quantity format.");
                    return false;
                }
            }

            if (count == 0) {
                activeChar.sendMessage("Quantity must be 1 or above, or left blank for default.");
                showItemsPage(activeChar, 0);
                return false;
            }

            String val = parts[1];
            target.getActingPlayer().destroyItem("GM Destroy", Integer.parseInt(val), count, null, true);
            showItemsPage(activeChar, 0);
        }
        return true;
    }

    private void showItemsPage(Player activeChar, int page)
    {
        final WorldObject target = activeChar.getTarget();
        final Player player = target.getActingPlayer();

        final Item[] items = player.getInventory().getItems().toArray(new Item[0]);

        int maxItemsPerPage = 13;
        int maxPages = items.length / maxItemsPerPage;
        if (items.length > (maxItemsPerPage * maxPages))
        {
            maxPages++;
        }

        if (page > maxPages)
        {
            page = maxPages;
        }

        int itemsStart = maxItemsPerPage * page;
        int itemsEnd = items.length;
        if ((itemsEnd - itemsStart) > maxItemsPerPage)
        {
            itemsEnd = itemsStart + maxItemsPerPage;
        }

        final NpcHtmlMessage adminReply = new NpcHtmlMessage(0);
        adminReply.setFile(activeChar, "data/html/admin/inventory.htm");
        adminReply.replace("%PLAYER_NAME%", activeChar.getName());

        StringBuilder sbPages = new StringBuilder();
        for (int x = 0; x < maxPages; x++)
        {
            int pagenr = x + 1;
            sbPages.append("<td><button value=\"" + pagenr + "\" action=\"bypass -h admin_showinv " + x + "\" width=20 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
        }

        adminReply.replace("%PAGES%", sbPages.toString());

        StringBuilder sbItems = getStringBuilder(itemsStart, itemsEnd, items);

        adminReply.replace("%ITEMS%", sbItems.toString());

        activeChar.sendPacket(adminReply);
    }

    private static StringBuilder getStringBuilder(int itemsStart, int itemsEnd, Item[] items) {
        StringBuilder sbItems = new StringBuilder();

        sbItems.append("<table width=270>");
        sbItems.append("<tr>");
        sbItems.append("<td width=24><b> </b></td>");
        sbItems.append("<td width=120><b> </b></td>");
        sbItems.append("<td width=90><b>Count</b></td>");
        sbItems.append("<td width=65><b>Quantity</b></td>");
        sbItems.append("</tr>");
        for (int i = itemsStart; i < itemsEnd; i++) {
            Item item = items[i];
            sbItems.append("<tr>");
            sbItems.append("<td><img src=").append(item.getTemplate().getIcon()).append(" width=24 height=24></td>");
            sbItems.append("<td>").append(item.getName()).append("</td>");
            sbItems.append("<td>").append(item.getCount()).append("</td>");
            sbItems.append("<td>");
            sbItems.append("<edit var=\"itemCount_").append(i).append("\" width=40>");
            sbItems.append("</td>");
            sbItems.append("<td><button action=\"bypass -h admin_delete_item ").append(item.getObjectId()).append(" $itemCount_").append(i).append("\" width=16 height=16 back=\"L2UI_ct1.Button_DF_Delete\" fore=\"L2UI_ct1.Button_DF_Delete\"></button></td>");
            sbItems.append("</tr>");
        }
        sbItems.append("</table>");
        return sbItems;
    }

    @Override
    public String[] getAdminCommandList()
    {
        return ADMIN_COMMANDS;
    }
}


Since i did jumped to mobius here the mobius one with quantity field aswell . 
feel free to adapt it back to acis or wherever 

 

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

    %ITEMS%

</body>
</html>


spacer.png

Edited by Acacia

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Posts

    • looking for someone who has cache cleaner for h5 
    • I’m looking to buy GeoEngine compatible with L2Scripts (Essence). A test server must be provided so I can verify functionality before purchase. DM here or through Telegram: @nick77737
    • fixed !.. thank you veru much @NevesOma  someone lock it
    • OFFICIAL DEVELOPERS Undetected since : Release Updated for last patch : 29/11/2025 After payment you will receive: Product download link1 Activation key for the selected period. Free support for the duration of the product subscription.   ✅AC - Undetected ▸WINDOWS 10/11 (All versions, even 24H2) ▸INTEL / AMD ▸Our software mainly targets player wanting to cheat legitimately. . Precision. Stealth. Performance.   The external ARC Raiders cheats from stern designed to elevate your gameplay without slowing your system. Fully compatible with Windows 10/11 — Intel & AMD ready.   Our Functions: AIMBOT **Enable Aim requires a mandatory confirmation popup, so there’s zero risk of activating it by accident for users who don’t want to use it. Aimbot Aimbot Drone Fov Aim (Draw fov circle) Target Line (Draw targetline) Arrow Fov (Draw arrow fov) Visible Check (Aim visible) Humanize (Aim randomize) Custom Aim Key Fov Value / Smooth Value / Aim Delay Arrow Size & Spacing VISUALS – PLAYERS Box ESP (2D / Corner) Health / Shield Bar Skeleton ESP Distance ESP Name ESP Tracers / Player Lines Visible & Invisible Check Squad Name ESP Draw Eyes Directions Radar ESP Radar Distance ESP Players Flags (corpse/knocked/exit/alive) VISUALS – ENTITY Pickup Base ESP Drone ESP Probe Crashed ESP Apricot ESP Mullein ESP Agave ESP MossRock ESP Crate ESP Salvage Container ESP Rsr Lockers ESP Raiders Cache Esp Bin Trash Esp Shredder Esp Fruit Basket ESP Ammo Box ESP Computer ESP Backpack ESP Leaper ESP Probe ESP Mushroom ESP Cargo Ship ESP Firewall ESP Assault Rifle ESP Battle Rifle ESP SMG ESP Grenade ESP Medical Bag ESP Turret ESP Sentinel Esp Weapon Case Esp Extraction ESP All Weapons ESP Max Distance & Fade distance MISC FOV Arrow Player Count Display Custom Arrow Size & Distance Streamproof (Invisible in recordings & screenshots) External (No injection) Maximum Privacy & Security 24/7 Support Available: replies within minutes Our prices: Prices must be checked directly on our website, as they may change at any time to control sales — however, we remain among the most competitive in the market.   Discover our website   GET GOOD, GET STERN
    • I paid this guy yesterday (i got screen for the payment for proof), he told me that someone will log to send me my adena. Then he said he had some problems and couldn't send me the adena. Waited and waited and waited until he replied that he can't find the guy and he will return the money i gave him. Today still no money returned and he doesn't reply to the discord messages. If he doesn't return the money i paid or send the adena he promised in game, i will report him in every single website and many more. Stay away. I have all the discussion screenshot on discord with him. He knows who i am so he better keep his promise legit.
  • Topics

×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock