Skip to content

[Request]Java Code

Featured Replies

Hello i need one java code which when you change subclass you put off the armor to avoid bugs

try adding it on L2PcInstance, addSubClass method

 

Index: java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java
===================================================================
--- java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java	(revision 268)
+++ java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java	(working copy)
@@ -11554,6 +11554,13 @@
			if (_transformation != null)
				return false;

+			this.getInventory().unEquipItemInSlot(Inventory.PAPERDOLL_GLOVES);
+			this.getInventory().unEquipItemInSlot(Inventory.PAPERDOLL_CHEST);
+			this.getInventory().unEquipItemInSlot(Inventory.PAPERDOLL_CLOAK);
+			this.getInventory().unEquipItemInSlot(Inventory.PAPERDOLL_FEET);
+			this.getInventory().unEquipItemInSlot(Inventory.PAPERDOLL_LEGS);
+			this.getInventory().unEquipItemInSlot(Inventory.PAPERDOLL_HEAD);
+			
			// Remove active item skills before saving char to database
			// because next time when choosing this class, weared items can
			// be different

try adding it on L2PcInstance, addSubClass method

 

Index: java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java
===================================================================
--- java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java	(revision 268)
+++ java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java	(working copy)
@@ -11554,6 +11554,13 @@
			if (_transformation != null)
				return false;

+			this.getInventory().unEquipItemInSlot(Inventory.PAPERDOLL_GLOVES);
+			this.getInventory().unEquipItemInSlot(Inventory.PAPERDOLL_CHEST);
+			this.getInventory().unEquipItemInSlot(Inventory.PAPERDOLL_CLOAK);
+			this.getInventory().unEquipItemInSlot(Inventory.PAPERDOLL_FEET);
+			this.getInventory().unEquipItemInSlot(Inventory.PAPERDOLL_LEGS);
+			this.getInventory().unEquipItemInSlot(Inventory.PAPERDOLL_HEAD);
+			
			// Remove active item skills before saving char to database
			// because next time when choosing this class, weared items can
			// be different

if i may suggest something, try to avoid L2PcInstance for such things, also, better would be something like that:

for(int i = 0;i<Inventory.PAPERDOLL_TOTALSLOTS;i++)
getInventory().unEquipItemInSlot(i);

 

also u can do thread to equip those items after some time for example:

 

private class EquipItems implements Runnable
{
@Override
public void run()
{
for(int i = 0;i<Inventory.PAPERDOLL_TOTALSLOTS;i++)
getInventory().equipItemInSlot(i);
}
}

and u apply it with:

ThreadPoolManager.getInstance.scheduleGeneral(new EquipItems(), timeInMilis);

hf :)

if i may suggest something, try to avoid L2PcInstance for such things, also, better would be something like that:

for(int i = 0;i<Inventory.PAPERDOLL_TOTALSLOTS;i++)
getInventory().unEquipItemInSlot(i);

 

also u can do thread to equip those items after some time for example:

 

private class EquipItems implements Runnable
{
@Override
public void run()
{
for(int i = 0;i<Inventory.PAPERDOLL_TOTALSLOTS;i++)
getInventory().equipItemInSlot(i);
}
}

and u apply it with:

ThreadPoolManager.getInstance.scheduleGeneral(new EquipItems(), timeInMilis);

hf :)

 

for(int i = 0;i<Inventory.PAPERDOLL_TOTALSLOTS;i++)

getInventory().equipItemInSlot(i);

 

It won't work since these items are not equiped. He must create a list type of L2ItemInstance and add these items in ( so it will need L2PcInstance ) , then after x time just equip the items from the list and clear the list.

^Wyatt solution is the most simple and accurate, you can drop "this." as it's optional, but else, it's the only decent solution.

 

- PAPERDOLL_TOTALSLOTS means you unequip the 20 slots, when we need to drop only main pieces.

- you equipItemInSlot( when it should be unEquipItemInSlot(... I guess you simply misread. Anyway.

- the task is useless as there is no need to delay.

Hello i need one java code which when you change subclass you put off the armor to avoid bugs

you can make this:
player.getInventory().reloadEquippedItems();

or you can make

if (player.getActiveWeaponInstance() != null || player.getActiveShieldInstance() != null)
					player.disarmWeapons();

				if (player.getActiveChestArmorItem() != null)
				{
					final L2ItemInstance chest = player.getInventory().getPaperdollItem(Inventory.PAPERDOLL_CHEST);
					if (chest != null)
			    	{
			    		final L2ItemInstance[] unequipped = player.getInventory().unEquipItemInBodySlotAndRecord(chest.getItem().getBodyPart());
			    		final InventoryUpdate iu = new InventoryUpdate();
			    		for (L2ItemInstance element : unequipped)
			    			iu.addModifiedItem(element);
			    		sendPacket(iu);
			    	}
				}

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.