Jump to content

No Enchant Near WH (L2jFrozen)


Kounto

Recommended Posts

Hello guys! I adapted the code about "Cannot Enchant near Warehouse"

I found the code by Prince*

I adapted this code for Frozen...

Try it and tell me if it's working good because i didn't check it.

Thank you :)

 

"I know it wasn't hard to adapt it but i wanted to share it for frozen because some guys don't know how to do it... Peace :)"

 

--- head-src/com/l2jfrozen/gameserver/clientpackets/RequestEnchantItem.java
+++ head-src/com/l2jfrozen/gameserver/clientpackets/RequestEnchantItem.java

@@ 20,1 @@

import com.l2jfrozen.Collection;
import com.l2jfrozen.Logger;

import com.l2jfrozen.gameserver.model.Inventory;
+import com.l2jfrozen.gameserver.model.L2Character;
import com.l2jfrozen.gameserver.model.L2ItemInstance;


import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
+import com.l2jfrozen.gameserver.model.actor.instance.L2WarehouseInstance;
import com.l2jfrozen.gameserver.network.SystemMessageId;


import com.l2jfrozen.gameserver.model.L2ItemInstance;
+import com.l2jfrozen.gameserver.model.L2Object;
import com.l2jfrozen.gameserver.model.L2World;


@@ -61,7 +61,15 @@
     {
         L2PcInstance activeChar = getClient().getActiveChar();
+               Collection<L2Character> knowns  = activeChar.getKnownList().getKnownCharactersInRadius(400);
         if (activeChar == null || _objectId == 0)
                        return;
+              
+               for (L2Object wh : knowns)
+               {
+                       if (wh instanceof L2WarehouseInstance)
+                       {
+                               activeChar.sendMessage("You cannot enchant near warehouse.");
+                               return;
+                       }
+               }
         L2ItemInstance item = activeChar.getInventory().getItemByObjectId(_objectId);
         L2ItemInstance scroll = activeChar.getActiveEnchantItem();

 

 

Edited by Kounto
Link to comment
Share on other sites

Put that

activeChar.getKnownList().getKnownCharactersInRadius(400)

directly in the for loop . First because it's a good writting style to write things in the shortest range possible (faster ready for garbage collection), second because you put it before a activeChar == null check, so it will throw a NPE if activeChar is null.

Link to comment
Share on other sites

7 hours ago, L2DragonWind said:

Why need this?

You cannot enchant near warehouse... Before some years it was a bug. Now i don't know if you can use this bug but i think this code is useful about your safety.

Link to comment
Share on other sites

About the coding style you can just add after the null activechar check the following:

 

if (activeChar.getKnownList().getKnownCharactersInRadius(400).stream().filter(obj -> obj instanceof L2WarehouseInstance).findFirst())
{
	activeChar.sendMessage("You cannot enchant near warehouse.");
	return;
}

About the results.. In order someone to use this code must have old sources that missing important fixes

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now


×
×
  • Create New...