Jump to content
Kishin

Code Delete Item From Inventory aCis 374

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

Share this post


Link to post
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).

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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

  • Recently Browsing   0 members

    No registered users viewing this page.



  • Posts

    • Grand Opening 1st of March
      19:00 UTC +2 [Europe] 
      13:00 UTC -3 [Brazil] 
      13:00 UTC -3 [Argentina] Website: http://l2flector.com/   Why you should play on our servers:         Unique custom Java platform.  Best defenses against DDOS attacks.  Protection from bots. SGuard  Game wthout wipe more than 6 months!  Comfortable game without freezes and delays.                                            

      Xp/Sp - 3000x
      Aden/Drop - 300x
      Rate Party Xp/Sp -1.5x
      OLYMPIAD
      Retail olympiad game.
      Olympiad Starts: 18:00 [+2GMT]
      Olympiad Ends: 24:00 [+2GMT]
      Hero Changes: Every Friday 14:00 [+2GMT]
      Period: 1 week


      Simple / Blessed Max Enchant (Weapon / Armor): +15 | (Jewelery): +15
      Crystal Max Enchant (Weapon / Armor): +20 | (Jewelery):+20
      Safe Enchant: +4
      Blessed: 90% | Crystal: 100%




      Mid Skill Chance: 5% | High: 10% | Top: 15%
      Max 1 active and 1 passive Augment at a time
      CASTLE SIEGE TIME
      Aden, Dion, 
      Giran, Goddard

                                                                                    Main town - Giran. Unique monsters. Unique pvp system. Unique aden balance. Unique farming areas. Unique L2Flector tattoos. Wedding system. Npc skill enchanter. Auto learn skills A grade items - free. Shops till top S grade. Full npc buffer with auto buff and scheme. 64 Buff Slots. Buff Time 3 hours. Max subclasses - 5. Free class change. Free sub class. Free nobless status. Stackable scrolls/ls/bog. No weight limit. No grade limit. Pvp/pk show on title. Top 20 pvp/pk in game. Offline trade system. Interlude retail skills. Perfect class balance. More then 18 active raid bosses. Without custom items. Server is secured with Sguard. SERVER COMMANDS .menu - Personal config. .siege - Sieges Info. .online - How many players online. .join .leave - Join or leave tvt event. .repair - Repair your char if you been stucked             Grand Opening 1st of March
      19:00 UTC +2 [Europe] 
      13:00 UTC -3 [Brazil] 
      13:00 UTC -3 [Argentina] Website: http://l2flector.com/
  • Topics

×