Page 1 of 2
[HELP] DestroyItem
Posted: Wed Apr 14, 2010 8:36 pm
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.
Re: [HELP] DestroyItem
Posted: Wed Apr 14, 2010 8:51 pm
by hope
what you mean when in game just use the bin in your inventory
Re: [HELP] DestroyItem
Posted: Wed Apr 14, 2010 9:09 pm
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!"); } } } }
Re: [HELP] DestroyItem
Posted: Wed Apr 14, 2010 9:31 pm
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)
Re: [HELP] DestroyItem
Posted: Wed Apr 14, 2010 9:48 pm
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.
Re: [HELP] DestroyItem
Posted: Thu Apr 15, 2010 10:13 am
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.
Re: [HELP] DestroyItem
Posted: Thu Apr 15, 2010 11:07 am
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....
Re: [HELP] DestroyItem
Posted: Thu Apr 15, 2010 11:18 am
by Dae
denser, I dont understand you...
Re: [HELP] DestroyItem
Posted: Thu Apr 15, 2010 11:39 am
by JIV
2denser: no you cant do that, since client dont send action on sever.
Re: [HELP] DestroyItem
Posted: Thu Apr 15, 2010 11:43 am
by Dae
Please write ontopic... :/
Re: [HELP] DestroyItem
Posted: Thu Apr 15, 2010 12:08 pm
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).
Re: [HELP] DestroyItem
Posted: Thu Apr 15, 2010 3:31 pm
by Dae
Can u write me an example?
Re: [HELP] DestroyItem
Posted: Thu Apr 15, 2010 3:40 pm
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
...
Re: [HELP] DestroyItem
Posted: Thu Apr 15, 2010 4:14 pm
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?
Re: [HELP] DestroyItem
Posted: Thu Apr 15, 2010 4:50 pm
by jurchiks
if (!item.getItemId(ItemNeededId))