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.



  • Posts

    • @Evie Frye this was the first 2 things iv tried but they didnt worked
    • i had to change all this because i was getting an error in party.java when i added new distrubeditem..here is what  i did and got this message when i tried to loot from the monster the drops are working fine and thanks for the help but i dont know how to solve this message @melron pcinventory.java   public static final int COIN_ID = 6577; public static final int ADENA_ID = 57; public static final int ANCIENT_ADENA_ID = 5575; private final Player _owner; private ItemInstance _coin; private ItemInstance _adena;     public int getCoin()     {         return _coin != null ? _coun.getCount() : 0;     }     public ItemInstance getCoinInstance()     {         return _count;     } public void addCoin(String process, int count, Player actor, WorldObject reference) { if (count > 0) addItem(process, COIN_ID, count, actor, reference); } public ItemInstance addItem(String process, ItemInstance item, Player actor, WorldObject reference) { item = super.addItem(process, item, actor, reference); if (item == null) return null; if (item.getItemId() == COIN_ID && !item.equals(_coin)) _coin = item; if (item.getItemId() == ADENA_ID && !item.equals(_adena)) _adena = item; public ItemInstance addItem(String process, int itemId, int count, Player actor, WorldObject reference) { ItemInstance item = super.addItem(process, itemId, count, actor, reference); if (item == null) return null; if (item.getItemId() == COIN_ID && !item.equals(_coin)) _coin = item; if (item.getItemId() == ADENA_ID && !item.equals(_adena)) _adena = item; public ItemInstance transferItem(String process, int objectId, int count, ItemContainer target, Player actor, WorldObject reference) { ItemInstance item = super.transferItem(process, objectId, count, target, actor, reference); if (_coin != null && (_coin.getCount() <= 0 || _coin.getOwnerId() != getOwnerId())) _coin = null; if (_adena != null && (_adena.getCount() <= 0 || _adena.getOwnerId() != getOwnerId())) _adena = null; public ItemInstance dropItem(String process, ItemInstance item, Player actor, WorldObject reference) { item = super.dropItem(process, item, actor, reference); if (_coin != null && (_coin.getCount() <= 0 || _coin.getOwnerId() != getOwnerId())) _coin = null; public ItemInstance dropItem(String process, int objectId, int count, Player actor, WorldObject reference) { ItemInstance item = super.dropItem(process, objectId, count, actor, reference); if (_coin != null && (_coin.getCount() <= 0 || _coin.getOwnerId() != getOwnerId())) _coin = null; if (_adena != null && (_adena.getCount() <= 0 || _adena.getOwnerId() != getOwnerId())) _adena = null; if (item.getItemId() == COIN_ID) _coin = null; if (item.getItemId() == ADENA_ID) _adena = null; public void restore() { super.restore(); _coin = getItemByItemId(COIN_ID); _adena = getItemByItemId(ADENA_ID); systemmessageid.java     public static final SystemMessageId EARNED_S1_COIN;   EARNED_S1_COIN = new SystemMessageId(2032); player.java     public int getCoin()     {         return _inventory.getCoin();     } public void addCoin(String process, int count, WorldObject reference, boolean sendMessage)     {         if (sendMessage)             sendPacket(SystemMessage.getSystemMessage(SystemMessageId.EARNED_S1_COIN).addNumber(count));                  if (count > 0)         {             _inventory.addCoin(process, count, this, reference);                          InventoryUpdate iu = new InventoryUpdate();                          if (_inventory.getCoinInstance() != null)                 iu.addModifiedItem(_inventory.getCoinInstance());             else                 iu.addItem(_inventory.getCoinInstance());                          sendPacket(iu);         }     }     public void doAutoLoot(Attackable target, IntIntHolder item)     {         if (isInParty())             getParty().distributeItem(this, item, false, target);         else if (item.getId() == 57)             addAdena("Loot", item.getValue(), target, true);         else if (item.getId() == 6577)             addCoin("Loot", item.getValue(), target, true);         else             addItem("Loot", item.getId(), item.getValue(), target, true);     } // Check if a Party is in progress             if (isInParty())                 getParty().distributeItem(this, item);             // Target is adena             else if (item.getItemId() == 57 && getInventory().getAdenaInstance() != null)             {                 addAdena("Pickup", item.getCount(), null, true);                 ItemTable.getInstance().destroyItem("Pickup", item, this, null);             }             else if (item.getItemId() == 6577 && getInventory().getCoinInstance() != null)             {                 addCoin("Pickup", item.getCount(), null, true);                 ItemTable.getInstance().destroyItem("Pickup", item, this, null);             }             // Target is regular item party.java     public void distributeItem(Player player, IntIntHolder item, boolean spoil, Attackable target)     {         if (item == null)             return;                  if (item.getId() == 57)         {             distributeAdena(player, item.getValue(), target);             return;         }         if (item.getId() == 6577)         {             distributeCoin(player, item.getValue(), target);             return;         }   public void distributeCoin(Player player, int Coin, Creature target)     {         List<Player> toReward = new ArrayList<>(_members.size());         for (Player member : _members)         {             if (!MathUtil.checkIfInRange(Config.PARTY_RANGE, target, member, true) || member.getCoin() == Integer.MAX_VALUE)                 continue;                          // Pass the check so will be rewarded.             toReward.add(member);         }                  // After all playes checked we got them in the list         // Avoid divisions by 0.         if (toReward.isEmpty())             return;                  // Calculation for drop in example of 1kk adena's. 1kk / 4 = 250k         final int count = Coin / toReward.size(); // 250k                  // Adding 250k for each player         for (Player member : toReward)             member.addCoin("Party", count, player, true);     } if (item.getItemId() == 6577)         {             distributeCoin(player, item.getCount(), player);             ItemTable.getInstance().destroyItem("Party", item, player, null);             return;         }  
    • OBT Will be accessible today

      http://iplay.gg/index.php?/topic/250-open-beta-19022018-today/
    • Dear god this coding... Use enums better...    public enum Spree { DOUBLE_KILL(2, "Double Kill"), TRIPLE_KILL(3, "Triple Kill"), ULTRA_KILL(4, "Ultra Kill"); final int kill; final String msg; private Spree(final int kill, final String msg) { this.kill = kill; this.msg = msg; } public void triggerBroadcast(final L2PcInstance player) { player.setSpreeKills(player.getSpreeKills() + 1); for (Spree s : Spree.values()) { if (s.kill == player.getSpreeKills()) { Broadcast.announceToOnlinePlayers("Player " + player.getName() + " got a " + s.msg); } } } } Took me 45 seconds and is 2000% better than 450 lines of code you did...
  • Topics