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

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.



  • Posts

    • Hello, I'd like to share with you a web template of me. https://www.mediafire.com/file/cslzde4h89it91y/Shinemaker.rar/file    
    • I never touch client, but now i want to use lordanov shared interface, but when i use it my lobby background change. in loging screen shows this static image: https://ibb.co/QF47WDmC But if i click on RECORD normal lobby shows up https://ibb.co/tpsG6F3G any idea how to fix it? i been looking for a solution, this thing happen when i paste interface.u file i decompiled interface.u but no idea where to do changes... thanks in advance, and sorry for poor english,
    • 🎙️ 1/ Creators, meet your new favorite tool: Chord.fm Record. Enhance. Deliver. A fully AI-powered recording studio, right in your browser. 🎧 Whether you're a podcaster, interviewer, or team running remote interviews — this is your upgrade. 🎥 2/ Record high-quality audio & video effortlessly ✅ Up to 4K video ✅ Uncompressed WAV audio ✅ Network-proof performance ✅ Multi-participant recording ✅ AI-powered post-processing 💡 No more "can you hear me?" moments. 🔊 3/ Get individual tracks for every participant One of Chord.fm’s superpowers: 🎚️ Each speaker's audio/video is recorded and exported separately. Perfect for post-production: 🎛️ Clean edits 🎧 Custom audio mixes 🎙️ Noise isolation per track   🧠 4/ Let AI do the heavy lifting 💬 Auto-generated subtitles 📝 Transcriptions you can trust 🧾 Smart summarization of recordings 🔍 Keyword highlights & topics Turn raw content into share-ready material without lifting a finger. 🧰 5/ Built for creators who value quality 🎬 Audiograms from your voice 🎚️ Auto-leveling 🌐 Browser-based (no install) 📁 Local backups during recording ⏱️ Time-saving features everywhere Chord.fm isn’t a Zoom alternative — it’s a production studio. 🚀 6/ Ready to level up? If you’re creating podcasts, interviews, or async team content — Chord.fm is what you've been waiting for. 🆓 Start for free: https://chord.fm You won't look back.
    • Who doesn't? 🤣 On topic. I would suggest you to work on Mobius files since there is a lot of space to work on things. @Mobius has done amazing job and deserves as match help as possible, this guy needs to be rewarded! Different type of packs since he has the most of the chronicles. I dont want to say that aCis hasn't done amazing job, it's one of the most stable and oldest projects around but I'm with mobius just because he supports way more clients. Working on either of projects will make you better.
  • 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