[HELP] DestroyItem

Support for the latest build of L2J Server, get help here with installations, upgrades, problems.
Do not post bugs reports here, use viewforum.php?f=77 instead.
There is no support for other server builds than the official provided by l2jserver.com
Forum rules
READ NOW: L2j Forums Rules of Conduct
Dae
Posts: 15
Joined: Sun Mar 07, 2010 9:35 pm

[HELP] DestroyItem

Post by Dae »

hey ppl, I want to know how to destroy item from inventory... I know how to add an item:

L2ItemInstance item = ItemTable.getInstance().createItem("Rebirth Item", itemId3, count3, player);
player.getInventory().addItem("Rebirth Item3", item.getItemId(), count3, player, null);

So please dont shout at me, I searched for this, but didint find anything.
hope
Posts: 1160
Joined: Thu Aug 30, 2007 5:17 pm

Re: [HELP] DestroyItem

Post by hope »

what you mean when in game just use the bin in your inventory
Dae
Posts: 15
Joined: Sun Mar 07, 2010 9:35 pm

Re: [HELP] DestroyItem

Post by Dae »

I am modifying RebirthMasterInstance code, and I dont know how to command server to destroy item in players inventory...
Code:

Code: Select all

package com.l2jserver.gameserver.model.actor.instance;   import com.l2jserver.gameserver.datatables.ItemTable;import com.l2jserver.gameserver.model.L2ItemInstance;import com.l2jserver.gameserver.model.L2Skill;import com.l2jserver.gameserver.model.base.ClassId;import com.l2jserver.gameserver.model.base.Experience;import com.l2jserver.gameserver.network.SystemMessageId;import com.l2jserver.gameserver.network.serverpackets.SystemMessage;import com.l2jserver.gameserver.templates.chars.L2NpcTemplate;  /**++ * Rebirth Npc's Instance++ * ++ * @author HanWik++ */   public class L2RebirthMasterInstance extends L2NpcInstance{	int itemId = 3470;	int itemId2 = 3470;	int itemId3 = 3470;	int count = 1;	int count2 = 10;	int count3 = 33;	int ItemNeededId = 57;	int ItemNeededId2 = 57;	int ItemNeededId3 = 57;	int ItemNeededAmount = 1000000000;	int ItemNeededAmount2 = 50000;	int ItemNeededAmount3 = 10000000;	int FirstReb = 0;	int SecondReb = 1;	int ThirdReb = 2;	int MaxReb = 3; 	public L2RebirthMasterInstance(int objectId, L2NpcTemplate template)	{		super(objectId, template);	} 	@Override	public void onBypassFeedback(L2PcInstance player, String command)	{		if (command.startsWith("Rebirth"))		{			ClassId classId = player.getClassId();			int jobLevel = classId.level();  			if (player.getLevel() >= 85 && jobLevel == 3 && player.getRebirths() == FirstReb)			{				L2ItemInstance ItemNeededId = player.getInventory().getItemByItemId(itemId);				player.getInventory().destroyItem("Rebirth Engine", ItemNeededId, ItemNeededAmount, player, null); 				L2ItemInstance item = ItemTable.getInstance().createItem("Rebirth Item", itemId, count, player);				player.getInventory().addItem("Rebirth Item", item.getItemId(), count, player, null);  				long pXp = player.getExp();				long tXp = Experience.LEVEL[1]; 				player.removeExpAndSp(pXp - tXp, 0);  				ClassId _baseClass = classId; 				for (ClassId child : ClassId.values())				{					if (classId.childOf(child))					{				    	_baseClass = child;						for (ClassId child2 : ClassId.values())						{					    	if (_baseClass.childOf(child2))							{								_baseClass = child2; 								for (ClassId child3 : ClassId.values())								{									if (_baseClass.childOf(child3)) 										_baseClass = child3; 								}							}						}					}				} 				for (L2Skill skill : player.getAllSkills()) 					player.removeSkill(skill); 				player.setClassId(_baseClass.getId());   				if (player.isSubClassActive()) player.getSubClasses().get(player.getClassIndex()).setClassId(player.getActiveClass()); 				else player.setBaseClass(player.getActiveClass());  				player.broadcastUserInfo();				player.rewardSkills();				player.sendSkillList(); 				// system sound for 1st and 2nd occupation				player.sendPacket(new SystemMessage(SystemMessageId.CLASS_TRANSFER));				// Update the overloaded status of the L2PcInstance				player.refreshOverloaded();				// Update the expertise status of the L2PcInstance				player.refreshExpertisePenalty();                 player.setRebirths(1);				player.sendMessage("You have completed your first rebirth");			}			else if (player.getLevel() >= 85 && jobLevel == 3 && player.getRebirths() == SecondReb)			{				L2ItemInstance item = ItemTable.getInstance().createItem("Rebirth Item", itemId2, count2, player);				player.getInventory().addItem("Rebirth Item2", item.getItemId(), count2, player, null); 				long pXp = player.getExp();				long tXp = Experience.LEVEL[1]; 				player.removeExpAndSp(pXp - tXp, 0);  				ClassId _baseClass = classId; 				for (ClassId child : ClassId.values())				{					if (classId.childOf(child))					{				    	_baseClass = child;						for (ClassId child2 : ClassId.values())						{					    	if (_baseClass.childOf(child2))							{								_baseClass = child2; 								for (ClassId child3 : ClassId.values())								{									if (_baseClass.childOf(child3)) 										_baseClass = child3; 								}							}						}					}				} 				for (L2Skill skill : player.getAllSkills()) 					player.removeSkill(skill); 				player.setClassId(_baseClass.getId());   				if (player.isSubClassActive()) player.getSubClasses().get(player.getClassIndex()).setClassId(player.getActiveClass()); 				else player.setBaseClass(player.getActiveClass());  				player.broadcastUserInfo();				player.rewardSkills();				player.sendSkillList(); 				// system sound for 1st and 2nd occupation				player.sendPacket(new SystemMessage(SystemMessageId.CLASS_TRANSFER));				// Update the overloaded status of the L2PcInstance				player.refreshOverloaded();				// Update the expertise status of the L2PcInstance				player.refreshExpertisePenalty();                 player.setRebirths(2);				player.sendMessage("You have completed your second rebirth"); 			}			else if (player.getLevel() >= 85 && jobLevel == 3 && player.getRebirths() == ThirdReb)			{				L2ItemInstance item = ItemTable.getInstance().createItem("Rebirth Item", itemId3, count3, player);				player.getInventory().addItem("Rebirth Item3", item.getItemId(), count3, player, null);  				long pXp = player.getExp();				long tXp = Experience.LEVEL[1]; 				player.removeExpAndSp(pXp - tXp, 0);  				ClassId _baseClass = classId; 				for (ClassId child : ClassId.values())				{					if (classId.childOf(child))					{				    	_baseClass = child;						for (ClassId child2 : ClassId.values())						{					    	if (_baseClass.childOf(child2))							{								_baseClass = child2; 								for (ClassId child3 : ClassId.values())								{									if (_baseClass.childOf(child3)) 										_baseClass = child3; 								}							}						}					}				} 				for (L2Skill skill : player.getAllSkills()) 					player.removeSkill(skill); 				player.setClassId(_baseClass.getId());   				if (player.isSubClassActive()) player.getSubClasses().get(player.getClassIndex()).setClassId(player.getActiveClass()); 				else player.setBaseClass(player.getActiveClass());  				player.broadcastUserInfo();				player.rewardSkills();				player.sendSkillList(); 				// system sound for 1st and 2nd occupation				player.sendPacket(new SystemMessage(SystemMessageId.CLASS_TRANSFER));				// Update the overloaded status of the L2PcInstance				player.refreshOverloaded();				// Update the expertise status of the L2PcInstance				player.refreshExpertisePenalty();                 player.setRebirths(3);				player.sendMessage("You have completed your third rebirth"); 			}			else if (player.getRebirths() == MaxReb)			{				player.sendMessage("You reached the maximum amount of rebirths");			}			else if (player.getLevel() < 85)			{				player.sendMessage("You are to low level, you need to atleast be 85");			}			else if (jobLevel < 3)			{				player.sendMessage("You can only be reborn when you have 3rd profession");			}			else			{				player.sendMessage("Something is wrong, FAIL!");			}	    }	} }
User avatar
jurchiks
Posts: 6769
Joined: Sat Sep 19, 2009 4:16 pm
Location: Eastern Europe

Re: [HELP] DestroyItem

Post by jurchiks »

public void destroyItem(String process, L2ItemInstance item, L2PcInstance actor, L2Object reference)

can't find any with count...

Edit:
public boolean destroyItemByItemId(String process, int itemId, int count, L2Object reference, boolean sendMessage)
If you have problems, FIRST TRY SOLVING THEM YOURSELF, and if you get errors, TRY TO ANALYZE THEM, and ONLY if you can't help it, THEN ask here.
Otherwise you will never learn anything if all you do is copy-paste!
Discussion breeds innovation.
User avatar
janiii
L2j Veteran
L2j Veteran
Posts: 4269
Joined: Wed May 28, 2008 3:15 pm
Location: Slovakia

Re: [HELP] DestroyItem

Post by janiii »

check L2PcInstance and all the methods destroyItem*
e.g.

Code: Select all

public boolean destroyItemByItemId(String process, int itemId, long count, L2Object reference, boolean sendMessage)public boolean destroyItemWithoutTrace(String process, int objectId, long count, L2Object reference, boolean sendMessage)public boolean destroyItem(String process, L2ItemInstance item, L2Object reference, boolean sendMessage)public boolean destroyItem(String process, L2ItemInstance item, long count, L2Object reference, boolean sendMessage)public boolean destroyItem(String process, int objectId, long count, L2Object reference, boolean sendMessage) 
or check PcInventory class for similar methods.
DO NOT EVEN TRY TO MESS WITH ME!
forum flOOder dancing dEVILoper
I don't give private support - PM will be ignored!
Dae
Posts: 15
Joined: Sun Mar 07, 2010 9:35 pm

Re: [HELP] DestroyItem

Post by Dae »

I know these methods, but I dont know how to make them work... ;/
If you checked my code, u saw that I tryed something with these methods, but that didint work.
User avatar
denser
Posts: 1392
Joined: Wed May 30, 2007 9:13 pm
Location: Russia
Contact:

Re: [HELP] DestroyItem

Post by denser »

interesting...is it possible, janiii, to pres alt_g, inventory and drag to trash players item and destroy it ?))) it would be more useful for gm....
Tiger, once tasted human flesh, will want to taste it again
L2J - the place where glad to see you any time!
Dae
Posts: 15
Joined: Sun Mar 07, 2010 9:35 pm

Re: [HELP] DestroyItem

Post by Dae »

denser, I dont understand you...
User avatar
JIV
L2j Veteran
L2j Veteran
Posts: 1882
Joined: Sun Jan 06, 2008 8:17 pm
Location: Slovakia
Contact:

Re: [HELP] DestroyItem

Post by JIV »

2denser: no you cant do that, since client dont send action on sever.
Dae
Posts: 15
Joined: Sun Mar 07, 2010 9:35 pm

Re: [HELP] DestroyItem

Post by Dae »

Please write ontopic... :/
User avatar
janiii
L2j Veteran
L2j Veteran
Posts: 4269
Joined: Wed May 28, 2008 3:15 pm
Location: Slovakia

Re: [HELP] DestroyItem

Post by janiii »

Dae wrote:Please write ontopic... :/
we already wrote you all the methods that exist to destroy an item. or just check other scripts (search all the scripts in your favourite file manager and search for "destroy" word in the files).
DO NOT EVEN TRY TO MESS WITH ME!
forum flOOder dancing dEVILoper
I don't give private support - PM will be ignored!
Dae
Posts: 15
Joined: Sun Mar 07, 2010 9:35 pm

Re: [HELP] DestroyItem

Post by Dae »

Can u write me an example?
User avatar
jurchiks
Posts: 6769
Joined: Sat Sep 19, 2009 4:16 pm
Location: Eastern Europe

Re: [HELP] DestroyItem

Post by jurchiks »

dude wtf? are you really that lazy? janiii just told you to search in existing scripts, there you will find more than enough examples!
data/scripts/custom/SkillTransfer/SkillTransfer.java
data/scripts/handlers/bypasshandlers/Loto.java
data/scripts/handlers/bypasshandlers/RideVyvern.java
data/scripts/handlers/bypasshandlers/TerritoryWar.java
...
If you have problems, FIRST TRY SOLVING THEM YOURSELF, and if you get errors, TRY TO ANALYZE THEM, and ONLY if you can't help it, THEN ask here.
Otherwise you will never learn anything if all you do is copy-paste!
Discussion breeds innovation.
Dae
Posts: 15
Joined: Sun Mar 07, 2010 9:35 pm

Re: [HELP] DestroyItem

Post by Dae »

I have another question, I found method that i needed:
player.destroyItemByItemId("rb", ItemNeededId, ItemNeededAmount, player, true);
Now when i press rebirth it destroys that item if I have it and rebirths me, but if i havent got that item he still rebirths me, my question would be how to make protection that if I dont have item i would not be reborned?
User avatar
jurchiks
Posts: 6769
Joined: Sat Sep 19, 2009 4:16 pm
Location: Eastern Europe

Re: [HELP] DestroyItem

Post by jurchiks »

if (!item.getItemId(ItemNeededId))
If you have problems, FIRST TRY SOLVING THEM YOURSELF, and if you get errors, TRY TO ANALYZE THEM, and ONLY if you can't help it, THEN ask here.
Otherwise you will never learn anything if all you do is copy-paste!
Discussion breeds innovation.
Post Reply