Sign in to follow this  
Kounto

Code No Enchant Near WH (L2jFrozen)

9 posts in this topic

Kounto    0

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

Share this post


Link to post
Share on other sites
Tryskell    8

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.

Share this post


Link to post
Share on other sites
Kounto    0
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.

Share this post


Link to post
Share on other sites
melron    38

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.