Jump to content
  • 0

Npc Enchant Item


Question

Posted

Hello MxC

 

I have on my server a npc, what it does is increase your items +1, +2, +3 to SafeMax +20 ... (Default config)
I want to know if anyone can modify the code, to do the enchant directly to +20 (1 Click = +20)
 
thx so much

 

This is the code

package net.sf.l2j.gameserver.scripting.scripts.custom;

import java.util.logging.Logger;

import net.sf.l2j.gameserver.model.actor.L2Npc;
import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
import net.sf.l2j.gameserver.model.item.instance.ItemInstance;
import net.sf.l2j.gameserver.model.itemcontainer.Inventory;
import net.sf.l2j.gameserver.model.olympiad.OlympiadManager;
import net.sf.l2j.gameserver.network.serverpackets.CharInfo;
import net.sf.l2j.gameserver.network.serverpackets.InventoryUpdate;
import net.sf.l2j.gameserver.network.serverpackets.UserInfo;
import net.sf.l2j.gameserver.scripting.Quest;
import net.sf.l2j.gameserver.scripting.QuestState;

public class Enchant extends Quest
{
    public static final Logger _log = Logger.getLogger(Enchant.class.getName());
    
    int npcId = 9994;
    
    // Item required to enchant armor +1
    int itemRequiredArmor = 6393;
    int itemRequiredArmorCount = 50;
    
    // Item required to enchant jewels +1
    int itemRequiredJewels = 6393;
    int itemRequiredJewelsCount = 50;
    
    // Item required to enchant weapon +1
    int itemRequiredWeapon = 6393;
    int itemRequiredWeaponCount = 150;
    
    // Item required to enchant belt/shirt +1
    int itemRequiredBeltShirt = 6393;
    int itemRequiredBeltShirtCount = 100;
    
    public Enchant()
    {
        super(-1, "custom");
        
        addStartNpc(npcId);
        addFirstTalkId(npcId);
        addTalkId(npcId);
    }
    
    @Override
    public String onFirstTalk(L2Npc npc, L2PcInstance player)
    {
        String enchantType = "Enchant.htm";
        
        if (player.getQuestState(getName()) == null)
            newQuestState(player);
        
        else if (player.isInCombat())
            return drawHtml("You are in combat", "Don't fight if you want to talk with me!", enchantType);
        
        else if (player.getPvpFlag() == 1)
            return drawHtml("You are flagged", "Don't fight if you want to talk with me!", enchantType);
        
        else if (player.getKarma() != 0)
            return drawHtml("You are in chaotic state", "Don't fight if you want to talk with me!", enchantType);
        
        else if (OlympiadManager.getInstance().isRegistered(player))
            return drawHtml("You are registered for Olympiad", "You can't use my services<br1>while playing the Olympiad.", enchantType);
        
        return "Enchant.htm";
    }
    
    @Override
    public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
    {
        String htmlText = event;
        String enchantType = "Enchant.htm";
        int armorType = -1;
        
        // Armor parts
        if (event.equals("enchantHelmet"))
        {
            armorType = Inventory.PAPERDOLL_HEAD;
            enchantType = "EnchantArmor.htm";
            htmlText = enchant(enchantType, player, armorType, itemRequiredArmor, itemRequiredArmorCount);
        }
        else if (event.equals("enchantChest"))
        {
            armorType = Inventory.PAPERDOLL_CHEST;
            enchantType = "EnchantArmor.htm";
            htmlText = enchant(enchantType, player, armorType, itemRequiredArmor, itemRequiredArmorCount);
        }
        else if (event.equals("enchantLeggings"))
        {
            armorType = Inventory.PAPERDOLL_LEGS;
            enchantType = "EnchantArmor.htm";
            htmlText = enchant(enchantType, player, armorType, itemRequiredArmor, itemRequiredArmorCount);
        }
        else if (event.equals("enchantGloves"))
        {
            armorType = Inventory.PAPERDOLL_GLOVES;
            enchantType = "EnchantArmor.htm";
            htmlText = enchant(enchantType, player, armorType, itemRequiredArmor, itemRequiredArmorCount);
        }
        else if (event.equals("enchantBoots"))
        {
            armorType = Inventory.PAPERDOLL_FEET;
            enchantType = "EnchantArmor.htm";
            htmlText = enchant(enchantType, player, armorType, itemRequiredArmor, itemRequiredArmorCount);
        }
        else if (event.equals("enchantShieldOrSigil"))
        {
            armorType = Inventory.PAPERDOLL_LHAND;
            enchantType = "EnchantArmor.htm";
            htmlText = enchant(enchantType, player, armorType, itemRequiredArmor, itemRequiredArmorCount);
        }
        // Jewels
        else if (event.equals("enchantUpperEarring"))
        {
            armorType = Inventory.PAPERDOLL_LEAR;
            enchantType = "EnchantJewels.htm";
            
            htmlText = enchant(enchantType, player, armorType, itemRequiredJewels, itemRequiredJewelsCount);
        }
        else if (event.equals("enchantLowerEarring"))
        {
            armorType = Inventory.PAPERDOLL_REAR;
            enchantType = "EnchantJewels.htm";
            
            htmlText = enchant(enchantType, player, armorType, itemRequiredJewels, itemRequiredJewelsCount);
        }
        else if (event.equals("enchantNecklace"))
        {
            armorType = Inventory.PAPERDOLL_NECK;
            enchantType = "EnchantJewels.htm";
            
            htmlText = enchant(enchantType, player, armorType, itemRequiredJewels, itemRequiredJewelsCount);
        }
        else if (event.equals("enchantUpperRing"))
        {
            armorType = Inventory.PAPERDOLL_LFINGER;
            enchantType = "EnchantJewels.htm";
            
            htmlText = enchant(enchantType, player, armorType, itemRequiredJewels, itemRequiredJewelsCount);
        }
        else if (event.equals("enchantLowerRing"))
        {
            armorType = Inventory.PAPERDOLL_RFINGER;
            enchantType = "EnchantJewels.htm";
            
            htmlText = enchant(enchantType, player, armorType, itemRequiredJewels, itemRequiredJewelsCount);
        }
        else if (event.equals("enchantShirt"))
        {
            armorType = Inventory.PAPERDOLL_UNDER;
            enchantType = "EnchantBeltShirt.htm";
            
            htmlText = enchant(enchantType, player, armorType, itemRequiredBeltShirt, itemRequiredBeltShirtCount);
        }
        // Weapon
        else if (event.equals("enchantWeapon"))
        {
            armorType = Inventory.PAPERDOLL_RHAND;
            enchantType = "EnchantWeapon.htm";
            
            htmlText = enchant(enchantType, player, armorType, itemRequiredWeapon, itemRequiredWeaponCount);
        }
        
        return htmlText;
    }
    
    private String enchant(String enchantType, L2PcInstance player, int armorType, int itemRequired, int itemRequiredCount)
    {
        QuestState st = player.getQuestState(getName());
        
        int currentEnchant = 0;
        int newEnchantLevel = 0;
        
        if (st.getQuestItemsCount(itemRequired) >= itemRequiredCount)
        {
            try
            {
                ItemInstance item = getItemToEnchant(player, armorType);
                
                if (item != null)
                {
                    currentEnchant = item.getEnchantLevel();
                    
                    if (currentEnchant < 20)
                    {
                        newEnchantLevel = setEnchant(player, item, currentEnchant + 1, armorType);
                        
                        if (newEnchantLevel > 0)
                        {
                            st.takeItems(itemRequired, itemRequiredCount);
                            player.sendMessage("You successfully enchanted your " + item.getItem().getName() + " from +" + currentEnchant + " to +" + newEnchantLevel + "!");
                            
                            String htmlContent = "<center>You successfully enchanted your:<br>" + "<font color=\"FF7200\">" + item.getItem().getName() + "</font><br>" + "From: <font color=\"AEFF00\">+" + currentEnchant + "</font> to <font color=\"AEFF00\">+" + newEnchantLevel + "</font>" + "</center>";
                            
                            return drawHtml("Congratulations!", htmlContent, enchantType);
                        }
                    }
                    else
                    {
                        player.sendMessage("Your " + item.getItem().getName() + " is already +20!");
                        return drawHtml("It's already +20", "<center>Your <font color=\"FF7200\">" + item.getItem().getName() + "</font> is already +20!</center>", enchantType);
                    }
                }
            }
            catch (StringIndexOutOfBoundsException e)
            {
                player.sendMessage("Something went wrong. Are equiped with the item?");
                return drawHtml("Error Enchant", "<center>Something went wrong.<br>Are equiped with the item?</center>", enchantType);
            }
            catch (NumberFormatException e)
            {
                player.sendMessage("Something went wrong. Are equiped with the item?");
                return drawHtml("Error Enchant", "<center>Something went wrong.<br>Are equiped with the item?</center>", enchantType);
            }
            
            player.sendMessage("Something went wrong. Are equiped with the item?");
            return drawHtml("Error Enchant", "<center>Something went wrong.<br>Are equiped with the item?</center>", enchantType);
        }
        String content = "<center>" + "Not enough <font color=\"FF7200\">Event - Glitering Medals</font>!<br>";
        
        if (st.getQuestItemsCount(itemRequired) > 0)
            content += "You have " + st.getQuestItemsCount(itemRequired) + " Glittering Medals,<br1>" + "Need " + (itemRequiredCount - st.getQuestItemsCount(itemRequired)) + " more.";
        else
            content += "You need <font color=\"FF7200\">" + itemRequiredCount + " Event - Glitering Medals</font>!";
        content += "</center>";
        return drawHtml("Not Enough Items", content, enchantType);
    }
    
    @SuppressWarnings("null")
    private static ItemInstance getItemToEnchant(L2PcInstance player, int armorType)
    {
        ItemInstance itemInstance = null;
        ItemInstance parmorInstance = player.getInventory().getPaperdollItem(armorType);
        
        if ((parmorInstance != null) && (parmorInstance.getLocationSlot() == armorType))
        {
            itemInstance = parmorInstance;
            if (itemInstance != null)
            {
                return itemInstance;
            }
        }
        return null;
    }
    
    private static int setEnchant(L2PcInstance player, ItemInstance item, int newEnchantLevel, int armorType)
    {
        if (item != null)
        {
            // set enchant value
            player.getInventory().unEquipItemInSlot(armorType);
            item.setEnchantLevel(newEnchantLevel);
            player.getInventory().equipItem(item);
            
            // send packets
            InventoryUpdate iu = new InventoryUpdate();
            iu.addModifiedItem(item);
            player.sendPacket(iu);
            player.broadcastPacket(new CharInfo(player));
            player.sendPacket(new UserInfo(player));
            
            return newEnchantLevel;
        }
        return -1;
    }
    
    public String drawHtml(String title, String content, String enchantType)
    {
        String html = "<html>" + "<title>L2Mondial Enchanter</title>" + "<body>" + "<center><img src=\"L2UI_CH3.herotower_deco\" width=256 height=32><br>" + "<font color=\"FF9900\">" + title + "</font></center><br>" + content + "<br><br>" + "<center><a action=\"bypass -h Quest Enchant " + enchantType + "\">Go Back</a></center>" + "</body>" + "</html>";
        return html;
    }
}

3 answers to this question

Recommended Posts

  • 0
Posted

I guess I have nothing more to say, now it's all about your logic.

 

 

newEnchantLevel = setEnchant(player, item, currentEnchant + 1, armorType);
  • 0
Posted

 

I guess I have nothing more to say, now it's all about your logic.

newEnchantLevel = setEnchant(player, item, currentEnchant + 1, armorType);

 

  :dat:   you are da best :D +20 for you)))

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


  • Posts

    • https://web.archive.org/web/20260306183214/https://maxcheaters.com/topic/241828-l2j-l2damage/page/3/ https://l2topzone.com/forum/l2-server-support-problems/9/l2damage-stopped/30514 Also we will try to push longer seasons ever ! (1135-100)/9 = 115 online
    • ONE SIDE – AND EVERYTHING BREAKS ▪ Looks like a simple case: Florida DL, back side, barcode – “clean and minimal”. ▪ In reality, these are exactly the tasks that fail most often. – data provided as plain text – request only for the back side – focus on the barcode (PDF417) ▪ And here’s the key point: ▪ A barcode is not just a “picture on the back”. It’s compressed logic of the entire document. ▪ If it doesn’t match the front, format, and data structure – the system flags it instantly. ▪ Many create a “similar-looking” code. But systems don’t read “similar” – they read by specification. ▪ In cases like this, it’s not about design. It’s about correct data assembly and how it behaves inside the format. ▪ Today only – 15% off for verification cases. ▪ Want it to pass, not just look right? Describe your case – we’ll show where even clean files break. › TG: @mustang_service ( https:// t.me/ mustang_service ) › Channel: Mustang Service ( https:// t.me/ +JPpJCETg-xM1NjNl ) #editing #photoshop #documents #verification #case
    • Your anonymity is a corpse. Blockchain forgets nothing. Your transactions are direct footprints in the hands of anyone who takes an interest. [✘] Still believe in "mixing"? Forget it. Classic Bitcoin mixers are an illusion of security. For Chainalysis and Elliptic algorithms, any attempt to hide tracks in the ledger is transparent. Your "mixing" is an artifact that gets filtered out in seconds. Every transaction leaves a trail that leads to frozen assets or unwanted questions from exchanges.  We don't mix. We break the link. [-] Input: Your "dirty" coins (Dirty BTC/ETH) with all their history and digital markers stay with us. [+] Output: You receive absolutely clean assets (Clean Crypto) from our reserves, which have never intersected with your past. This isn't a game of hide and seek. This is the surgical removal of your financial history from the system.   ------------------------------------------------------------------- Technical indexing: Bitcoin Mixer, Crypto Mixer, Clean BTC, Clean ETH, Anti-Chainalysis, Best Bitcoin Mixer, Anonymous Crypto Exchange, NoLog Mixing Service.
    • Here you are: https://l2crypt.com/l2-tools/l2editor-source/
  • Topics

×
×
  • Create New...

Important Information

This community uses essential cookies to function properly. Non-essential cookies and third-party services are used only with your consent. Read our Privacy Policy and We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue..