Jump to content
  • 0

Question

Posted

Hello I created this system to drop enchanted items but it drops 2 item even putting the amount 1. What can I do to improve the code ?

 

Index: java/net/sf/l2j/gameserver/model/actor/Attackable.java
===================================================================
--- java/net/sf/l2j/gameserver/model/actor/Attackable.java    (revision 3)
+++ java/net/sf/l2j/gameserver/model/actor/Attackable.java    (working copy)
@@ -1184,6 +1184,28 @@
             }
         }
         
+        // Drop All Monsters Itens enchantados By Dev Williams
+        if ((Config.ENABLE_DROP_ITEM_ENCHANT) && ((this instanceof Monster)))
+        {
+            for (int i = 1; i < 81; i++)
+            {
+                if (i > 10)
+                {
+                    if (player.getLevel() == i && getLevel() < player.getLevel() - 8)
+                        return;
+                }
+            }
+            if (Rnd.get(100) < Config.DROP_ITEM_ENCHANT[3])
+            {
+                IntIntHolder item = new IntIntHolder(Config.DROP_ITEM_ENCHANT[0], Config.DROP_ITEM_ENCHANT[1]);
+                if (Config.AUTO_LOOT)
+                    player.doAutoLoot(this, item);
+                else
+                    dropItem(player, item);
+                    player.getInventory().addEnchantedItem("Reward Enchant: ", Config.DROP_ITEM_ENCHANT[0], Config.DROP_ITEM_ENCHANT[1], Config.DROP_ITEM_ENCHANT[2], player, null);
+            }
+        }
+        
Index: java/net/sf/l2j/gameserver/model/itemcontainer/PcInventory.java
===================================================================
--- java/net/sf/l2j/gameserver/model/itemcontainer/PcInventory.java    (revision 2)
+++ java/net/sf/l2j/gameserver/model/itemcontainer/PcInventory.java    (working copy)
@@ -17,9 +17,11 @@
 import net.sf.l2j.gameserver.model.itemcontainer.listeners.ItemPassiveSkillsListener;
 import net.sf.l2j.gameserver.model.tradelist.TradeItem;
 import net.sf.l2j.gameserver.model.tradelist.TradeList;
+import net.sf.l2j.gameserver.network.SystemMessageId;
 import net.sf.l2j.gameserver.network.serverpackets.InventoryUpdate;
 import net.sf.l2j.gameserver.network.serverpackets.ItemList;
 import net.sf.l2j.gameserver.network.serverpackets.StatusUpdate;
+import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
 import net.sf.l2j.gameserver.taskmanager.ShadowItemTaskManager;
 
 public class PcInventory extends Inventory
@@ -439,6 +441,43 @@
         
         return item;
     }
+
+    public ItemInstance addEnchantedItem(String process, int itemId, int itemCount, int enchantLevel, Player actor, WorldObject reference)
+    {
+        ItemInstance item = super.addItem(process, itemId, itemCount, actor, reference);
+        
+        if (item == null)
+            return null;
+        
+        if (enchantLevel > 0)
+            item.setEnchantLevel(enchantLevel);
+        
+        if (itemId == 57)
+        {
+            SystemMessage smsg = SystemMessage.getSystemMessage(SystemMessageId.EARNED_S1_ADENA);
+            smsg.addItemNumber(itemCount);
+            actor.sendPacket(smsg);
+        }
+        else if (itemCount > 1)
+        {
+            SystemMessage smsg = SystemMessage.getSystemMessage(SystemMessageId.EARNED_S2_S1_S);
+            smsg.addItemName(itemId);
+            smsg.addItemNumber(itemCount);
+            actor.sendPacket(smsg);
+        }
+        else
+        {
+            SystemMessage smsg = SystemMessage.getSystemMessage(SystemMessageId.ACQUIRED_S1_S2);
+            smsg.addNumber(enchantLevel);
+            smsg.addItemName(itemId);
+            actor.sendPacket(smsg);
+        }
+        StatusUpdate su = new StatusUpdate(actor);
+        su.addAttribute(14, actor.getCurrentLoad());
+        actor.sendPacket(su);
+        
+        return item;
+    }
     

11 answers to this question

Recommended Posts

  • 0
Posted

actor.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.ACQUIRED_S1_S2).addNumber(enchantLevel).addItemName(itemId));

  • Thanks 1
  • 0
Posted

sounds logic lol . look again what you did there 

 

+                if (Config.AUTO_LOOT)
+                    player.doAutoLoot(this, item);
+                else
+                    dropItem(player, item);
+                    player.getInventory().addEnchantedItem("Reward Enchant: ", Config.DROP_ITEM_ENCHANT[0], Config.DROP_ITEM_ENCHANT[1], Config.DROP_ITEM_ENCHANT[2], player, null);

 

you are adding an item with enchant value after the default drop. 1+1 = 2 :p

 

also what's the logic of this?

 

+            for (int i = 1; i < 81; i++)
+            {
+                if (i > 10)
+                {
+                    if (player.getLevel() == i && getLevel() < player.getLevel() - 8)
+                        return;
+                }
+            }

you can simple do one check

 

if (Config.ENABLE_DROP_ITEM_ENCHANT && this instanceof Monster && getLevel() < (player.getLevel() - 8))
	return;

 

also, in order to make enchant system for both loot cases you need a big rework. start by reading how the values from the drop xml are working and add one more value there

  • 0
Posted
2 hours ago, melron said:

sounds logic lol . look again what you did there 

 


+                if (Config.AUTO_LOOT)
+                    player.doAutoLoot(this, item);
+                else
+                    dropItem(player, item);
+                    player.getInventory().addEnchantedItem("Reward Enchant: ", Config.DROP_ITEM_ENCHANT[0], Config.DROP_ITEM_ENCHANT[1], Config.DROP_ITEM_ENCHANT[2], player, null);

 

you are adding an item with enchant value after the default drop. 1+1 = 2 :p

 

also what's the logic of this?

 


+            for (int i = 1; i < 81; i++)
+            {
+                if (i > 10)
+                {
+                    if (player.getLevel() == i && getLevel() < player.getLevel() - 8)
+                        return;
+                }
+            }

you can simple do one check

 


if (Config.ENABLE_DROP_ITEM_ENCHANT && this instanceof Monster && getLevel() < (player.getLevel() - 8))
	return;

 

also, in order to make enchant system for both loot cases you need a big rework. start by reading how the values from the drop xml are working and add one more value there

 

this is a verification for player lvl 81 does not win the item killing mobe lvl 1

 

The auto loot was stupid, my kk.

  • 0
Posted
3 minutes ago, l2jkain said:

 

this is a verification for player lvl 81 does not win the item killing mobe lvl 1

 

The auto loot was stupid, my kk.

 

heh actually the check itself will allow rewards from lvl 1 to 10 without checking the player's lvl :D

use the check i gave you. one line check is enough for this thing.

  • 0
Posted
30 minutes ago, melron said:

 

heh, na verdade, o cheque em si permitirá recompensas de lvl 1 a 10 sem verificar o jogador lvl : D

use o cheque que eu te dei. Uma verificação de linha é suficiente para essa coisa.

I did it your way and it did not work. I level 81 I won the mob level 1 award.

  • 0
Posted
5 minutes ago, l2jkain said:

I did it your way and it did not work. I level 81 I won the mob level 1 award.

just cant be. You won enchanted drop? I dont think so... probably you obtained retail drop but not the custom one

  • 0
Posted
5 minutes ago, melron said:

just cant be. You won enchanted drop? I dont think so... probably you obtained retail drop but not the custom one

 

only problem is if I put more than 1 item to dropa only comes 1 enchantado taking it ta 100% functional


        // Drop All Monsters Itens enchantados By Dev Williams
        if ((Config.ENABLE_DROP_ITEM_ENCHANT) && ((this instanceof Monster)))
        {
            for (int i = 1; i < 81; i++)
            {
                if (i > 10)
                {
                    if (player.getLevel() == i && getLevel() < player.getLevel() - 8)
                        return;
                }
            }
            if (Rnd.get(100) < Config.DROP_ITEM_ENCHANT[3])
            {
                if (Config.AUTO_LOOT)
                    player.getInventory().addEnchantedItem("Reward Enchant: ", Config.DROP_ITEM_ENCHANT[0], Config.DROP_ITEM_ENCHANT[1], Config.DROP_ITEM_ENCHANT[2], player, null);
            }
        }
        

  • 0
Posted

remove the for loop dude lol.. its rly useless...

what exactly are you trying to do? you need for example 5 db's + 16?

 

if ((Config.ENABLE_DROP_ITEM_ENCHANT) && ((this instanceof Monster)))
{
	if (Config.ENABLE_DROP_ITEM_ENCHANT && this instanceof Monster && getLevel() < (player.getLevel() - 8))
		return;
	if (Rnd.get(100) < Config.DROP_ITEM_ENCHANT[3])
	{
		if (Config.AUTO_LOOT)
			for (int i = 0; i < Config.DROP_ITEM_ENCHANT[1]; i++)
				player.getInventory().addEnchantedItem("Reward Enchant: ", Config.DROP_ITEM_ENCHANT[0], 1,
							Config.DROP_ITEM_ENCHANT[2], player, null);
		}
	}
}

 

  • 0
Posted
4 minutes ago, melron said:

remover o loop for dude rsrs .. é rly inútil ...

o que exatamente você está tentando fazer? você precisa, por exemplo, de 5 db's + 16?

 


 

 

I just want to leave enchanted items dropping

  • 0
Posted
1 minute ago, l2jkain said:

 

I just want to leave enchanted items dropping

Sorry i cant understand you.. if you want to drop on the floor enchanted items then you are moving wrong...

  • 0
Posted
4 minutes ago, melron said:

Desculpe eu não posso te entender .. se você quiser cair no chão itens encantados, então você está se movendo errado ...

thanks for the help I give up trying to do can close the topic

Guest
This topic is now closed to further replies.
×
×
  • Create New...