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...
  • 8 months later...
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
Link to comment
Share on other sites

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

    • DISCORD : utchiha_market telegram : https://t.me/utchiha_market SELLIX STORE : https://utchihamkt.mysellix.io/ Join our server for more products : https://discord.gg/hood-services https://campsite.bio/utchihaamkt  
    • Server Rates: » Xp 500x. » Sp 500x. » Aden 500x. » Drop 1x. » PartyXp 2x. » PartySp 2x. » Starting character level -61. Enchant rates: » Safe enchant +4. » Blessed and simple scrolls max enchant (+16). » Crystal scrolls max enchant (+20). » Simple enchant scrolls chance – 65%. » Blessed enchant scrolls chance – 100%. » Crystal enchant scrolls chance – 50% Augmentations: » Mid life stone skill chance – 5%. » High life stone skill chance – 10%. » Top life stone skill chance – 20%. » Augments 1+1 Unique features: » Main town – Giran » Automatic-Manual Potions. » Working 2 castle sieges. (Giran-Aden) » SPS cancel lasts 10 seconds and than buffs come back. » Stackable scrolls, lifestones, book of giants. » Unique pvp zone » More then 11 active raid bosses. » Wedding system. » Unique farming areas. » Npc skill enchanter. » Full npc buffer with auto buff. » Max count of buffs – 55. » Max subclasses – 4. » Free and no quest class change. » Free and no quest sub class. » Raid boss drop nobless item. » No weight limit. » Unique protection anti-hwy armor for archers/daggers etc. » Ingame password change. » Top pvp/pk/online ranks NPC. » Unique monsters & NPC. » Interlude retail skills. » Server up-time [24/7] [99]%. » Perfect class balance (all class can kill all class depending on players skill and setup knowledge,gear,augmentations). » Announcements on double kills triple kills etc. » Announcements on Grand Boss death , with the name of the killer as well as clan name of the player. » Information Npc in game with all servers infromations. Custom server gear : 1). Titanium Armor Lv.1 2). Epic Armor Lv.2 3). Epic Weapons-Kamikaze-Black S grade (Same Stats) 4). Demonic-Angelic Wings-Baium Hair-Custom Accessories (SameStats) 5). Custom Fighter/Mage tattoo Lv1-Lv2-Lv3 6). Shirt (STR,CON,INT +1) 7). Custom Shields Server Commands: .tvtjoin .tvtleave – Join or leave tvt event. .ctfjoin .ctfleave – Join or leave ctf event. .dmjoin .dmleave – Join of leave dm event. .online – current online players count. .repair – repairs stuck character in world. .menu – opens online menu panel. .exit – PVP zone exit in case you are bullied. .changepassword - Opens online menu then u can change ur password in game. .farm - Enable/disable autofarm Event system: » TVT event » CTF event » DM event » Tournament Event » Party Zone » Unique event shop. Olympiad game: » Retail olympiad game. » Competition period [1] week. » Olympiad start time [18:00] end [00:00] GMT+2. » New Heroes every Sunday.
    • Tomorrow grand opening lests go 🙂 
    • New season of Warfire X150 has been postponed to September 28th.
  • Topics

×
×
  • Create New...