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.


  • Posts

    • I was looking for  server with a low rates,eventually i found l2 elixir.I Joined beta and after so many years since 2008 i found  a friend that we played together, memories came back. i cant wait for the grand oppening!. dont miss it!
    • Seems legit, for sure deserves a try!
    • SOCNET VERIFICATION SERVICE — is a universal solution for those who value security, convenience, and quality. We turn the verification process into a convenient, fast, and highly confidential experience. Thanks to our service, any of your accounts receive identity confirmation, an increased level of trust from platforms and users, as well as protection from bans, fraud, and risks.   Promotion: Pay for your first verification and get a 10% discount on the second one! 💎 We help with verification on Fragment, crypto exchanges ByBit, Gate, Bitget, OKX, Binance, PayPal, KuCoin, and social networks LinkedIn, Facebook, Instagram, Twitter (X) and many other platforms! 💎 Verification for any service: crypto exchanges, trading platforms, hosting providers, casinos and other websites. Why choose us:   Premium quality — we use the most advanced verification methods. High processing speed — accelerated verification on leading platforms, online services and social networks. Full confidentiality — your personal information is protected. Increased trust and status — a verified account boosts influence and improves conversion. Individual approach — we work with bloggers, brands, businesses, and private clients. Simplifying complexity — we handle issues when dealing with foreign services. Important! Services related to illegal activities are strictly prohibited! 💳 Service pricing   ✅ Verification of individuals — from $30 (the exact cost depends on the required location and service/app/website). Learn more 👨‍💼 The cost of business verification for companies or legal entities is discussed individually with the service administration. Learn more If you want us to register your account on the required service and verify it — you will need to additionally pay 10% of the transaction amount. Available payment methods: cryptocurrency, credit cards, PayPal, and other payment methods in our online store and Telegram bot.   ⭐ Our Online Store ⭐ SOCNET.STORE ⭐ Telegram Store ⭐ SOCNET.SHOP ⭐ Our SMS Service ⭐ SOCNET.APP ⭐ Our Telegram Bot for buying Telegram Stars ⭐ SOCNET.CC ⭐ Our SMM Panel ⭐ SOCNET.PRO   ✅ News Resources ➡ Telegram Channel ➡ WhatsApp Channel ➡ Discord Server     ⭐ We invite you to COOPERATE and EARN with us ⭐ Would you like to sell your product or service in our stores and earn money? Become our partner or offer mutually beneficial collaboration? You can contact us via the CONTACTS listed in this topic. ✅ Contacts & Support ➡ Telegram Support ➡ WhatsApp Support ➡ Discord Support: socnet_support ➡ Email Support: solomonbog@socnet.store   Terms of Use and Refund Policy If you have any questions or issues, our fast support service is ready to respond to your requests! A refund for a completed service that does not fully meet the requirements or the declared quality is possible only if the product description includes a warranty and a valid warranty period. In other cases, a full refund for the service will not be provided! By purchasing such a service, you automatically agree to our refund rules for non-provided services! Refunds for countries selected by mistake are not provided after verification. To complete verification, you must provide full access to your account. We currently accept cryptocurrency, credit cards, PayPal, and other payment methods in our online store and Telegram bot! We value every client and provide replacements in case of invalid accounts via our contact channels! Attention: Your order will be delivered to your personal Google Drive/Mega.nz via a link (check the link, click “View content”) within 24 hours after the order confirmation! If you purchased more than 1 item at once, your entire order will be delivered via the first link! The remaining links will be empty! You will automatically receive an email notification after delivery! If you pay on our website via PayPal, you must pay an additional 20% commission (minimum $1). To avoid this commission, you can pay me directly via PayPal — instructions are available on the website! Refunds for items purchased by mistake or due to “I chose the wrong product and did not use it” are not accepted! You are fully responsible for your actions before and after purchase.
    • SOCNET VERIFICATION SERVICE — is a universal solution for those who value security, convenience, and quality. We turn the verification process into a convenient, fast, and highly confidential experience. Thanks to our service, any of your accounts receive identity confirmation, an increased level of trust from platforms and users, as well as protection from bans, fraud, and risks.   Promotion: Pay for your first verification and get a 10% discount on the second one! 💎 We help with verification on Fragment, crypto exchanges ByBit, Gate, Bitget, OKX, Binance, PayPal, KuCoin, and social networks LinkedIn, Facebook, Instagram, Twitter (X) and many other platforms! 💎 Verification for any service: crypto exchanges, trading platforms, hosting providers, casinos and other websites. Why choose us:   Premium quality — we use the most advanced verification methods. High processing speed — accelerated verification on leading platforms, online services and social networks. Full confidentiality — your personal information is protected. Increased trust and status — a verified account boosts influence and improves conversion. Individual approach — we work with bloggers, brands, businesses, and private clients. Simplifying complexity — we handle issues when dealing with foreign services. Important! Services related to illegal activities are strictly prohibited! 💳 Service pricing   ✅ Verification of individuals — from $30 (the exact cost depends on the required location and service/app/website). Learn more 👨‍💼 The cost of business verification for companies or legal entities is discussed individually with the service administration. Learn more If you want us to register your account on the required service and verify it — you will need to additionally pay 10% of the transaction amount. Available payment methods: cryptocurrency, credit cards, PayPal, and other payment methods in our online store and Telegram bot.   ⭐ Our Online Store ⭐ SOCNET.STORE ⭐ Telegram Store ⭐ SOCNET.SHOP ⭐ Our SMS Service ⭐ SOCNET.APP ⭐ Our Telegram Bot for buying Telegram Stars ⭐ SOCNET.CC ⭐ Our SMM Panel ⭐ SOCNET.PRO   ✅ News Resources ➡ Telegram Channel ➡ WhatsApp Channel ➡ Discord Server     ⭐ We invite you to COOPERATE and EARN with us ⭐ Would you like to sell your product or service in our stores and earn money? Become our partner or offer mutually beneficial collaboration? You can contact us via the CONTACTS listed in this topic. ✅ Contacts & Support ➡ Telegram Support ➡ WhatsApp Support ➡ Discord Support: socnet_support ➡ Email Support: solomonbog@socnet.store   Terms of Use and Refund Policy If you have any questions or issues, our fast support service is ready to respond to your requests! A refund for a completed service that does not fully meet the requirements or the declared quality is possible only if the product description includes a warranty and a valid warranty period. In other cases, a full refund for the service will not be provided! By purchasing such a service, you automatically agree to our refund rules for non-provided services! Refunds for countries selected by mistake are not provided after verification. To complete verification, you must provide full access to your account. We currently accept cryptocurrency, credit cards, PayPal, and other payment methods in our online store and Telegram bot! We value every client and provide replacements in case of invalid accounts via our contact channels! Attention: Your order will be delivered to your personal Google Drive/Mega.nz via a link (check the link, click “View content”) within 24 hours after the order confirmation! If you purchased more than 1 item at once, your entire order will be delivered via the first link! The remaining links will be empty! You will automatically receive an email notification after delivery! If you pay on our website via PayPal, you must pay an additional 20% commission (minimum $1). To avoid this commission, you can pay me directly via PayPal — instructions are available on the website! Refunds for items purchased by mistake or due to “I chose the wrong product and did not use it” are not accepted! You are fully responsible for your actions before and after purchase.
  • Topics

×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock