Jump to content
  • 0

Npc Enchant


Question

Posted

Who can tell me how i can edit npc enchant with different enchant?

i mean i have one npc for max enchant +150. This item need to be +0 to enchant it.

and i want the secound one to be from 150 (not from +0) to +300. 

Now, the problem is it in .JAVA file. How i can duplicate npc to work both?

I can change just id? (i try this and doesn;t work).

Thank's

7 answers to this question

Recommended Posts

  • 0
Posted

Well, i paste here java file from npc enchant. 

package custom.Enchant;

import java.util.logging.Logger;

import com.l2jserver.gameserver.model.actor.L2Npc;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.model.itemcontainer.Inventory;
import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
import com.l2jserver.gameserver.model.olympiad.OlympiadManager;
import com.l2jserver.gameserver.model.quest.Quest;
import com.l2jserver.gameserver.model.quest.QuestState;
import com.l2jserver.gameserver.network.serverpackets.CharInfo;
import com.l2jserver.gameserver.network.serverpackets.ExBrExtraUserInfo;
import com.l2jserver.gameserver.network.serverpackets.InventoryUpdate;
import com.l2jserver.gameserver.network.serverpackets.UserInfo;

public class Enchant extends Quest
{
    public static final Logger _log = Logger.getLogger(Enchant.class.getName());

    int npcId = 99942;

    // Item required to enchant armor +20
    int itemRequiredArmor = 8284;
    int itemRequiredArmorCount = 10;

    // Item required to enchant jewels +20
    int itemRequiredJewels = 8284;
    int itemRequiredJewelsCount = 10;

    // Item required to enchant weapon +20
    int itemRequiredWeapon = 8284;
    int itemRequiredWeaponCount = 10;

    // Item required to enchant belt/shirt +20
    int itemRequiredBeltShirt = 8284;
    int itemRequiredBeltShirtCount = 100;

    public Enchant(int questId, String name, String descr)
    {
        super(questId, name, descr);
       
        addStartNpc(npcId);
        addFirstTalkId(npcId);
        addTalkId(npcId);
    }
    
    public static void main(String[] args)
    {
        new Enchant(-1, Enchant.class.getSimpleName(), "custom");
    }
    
    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";
    }

    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);
        }
        // Belt/Shirt
        else if (event.equals("enchantBelt"))
        {
            armorType = Inventory.PAPERDOLL_BELT;
            enchantType = "EnchantBeltShirt.htm";
            
            htmlText = enchant(enchantType, player, armorType, itemRequiredBeltShirt, itemRequiredBeltShirtCount);
        }
        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
            {
                L2ItemInstance item = getItemToEnchant(player, armorType);

                if (item != null)
                {
                    currentEnchant = item.getEnchantLevel();

                    if ( currentEnchant < 100 )
                    {
                        newEnchantLevel = setEnchant(player, item, currentEnchant+10, 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 +100!");
                        return drawHtml("It's already +100", "<center>Your <font color=\"FF7200\">" + item.getItem().getName() +"</font> is already +100!</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);
        }
        else
        {
            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);
        }
    }

    private L2ItemInstance getItemToEnchant(L2PcInstance player, int armorType)
    {
        L2ItemInstance itemInstance = null;
        L2ItemInstance parmorInstance = player.getInventory().getPaperdollItem(armorType);

        if ((parmorInstance != null) && (parmorInstance.getLocationSlot() == armorType))
        {
            itemInstance = parmorInstance;

            if (itemInstance != null)
            {
                return itemInstance;
            }
        }

        return null;
    }

    private int setEnchant(L2PcInstance player, L2ItemInstance 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));
            player.broadcastPacket(new ExBrExtraUserInfo(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;
    }
}

What i need to change here ?

  • 0
Posted

If you cant understand and edit a simple code, you should learn the language first. at least the basics. If not, you are doing a bad job trying to open a server without knowledge about editing stuff... What will you do when you find a bug? Will you come with it to the forum and hope people will help you out? ... Google stuff, try to understand what you are doing... 

  • 0
Posted (edited)

You should re-write your code buddy.. Your logic about packets/unequip and then enchant and again equip it's totally wrong.. This can be done with only 1/7 of this code.

 

example like:


                item.setEnchantLevel(enchant);
                item.updateDatabase();
                player.sendPacket(new ItemList(player, false));
                player.broadcastUserInfo();
                player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S1_S2_SUCCESSFULLY_ENCHANTED).addNumber(item.getEnchantLevel()).addItemName(item.getItemId()));

 

Make your method:

 

    public static void Enchant(L2PcInstance player, int enchant, int type)
    {
        L2ItemInstance item = player.getInventory().getPaperdollItem(type);
        
        if (item != null)
        {
            if (item.getEnchantLevel() < 150)
                player.sendMessage("Move to another enchant npc!");
            else if (item.getEnchantLevel() == 300)
                player.sendMessage("Your " + item.getItemName() + " is already on maximun enchant!");
            else if (item.getItem().getCrystalType().getId() == 0)
                player.sendMessage("You can't Enchant under " + item.getItem().getCrystalType() + " Grade Items!");
            else if (item.isHeroItem())
                player.sendMessage("You Cannot be Enchant On " + item.getItemName() + " !");
            else if (player.destroyItemByItemId("Consume", 57, 100, player, true))
            {
                item.setEnchantLevel(enchant);
                item.updateDatabase();
                player.sendPacket(new ItemList(player, false));
                player.broadcastUserInfo();
                player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S1_S2_SUCCESSFULLY_ENCHANTED).addNumber(item.getEnchantLevel()).addItemName(item.getItemId()));
            }
            else
                player.sendMessage("You do not have enough adena.");
        }
        else
            player.sendMessage("That item doesn't exist in your inventory.");
    }

 

 

        if (command.startsWith("enchant"))
        {
            StringTokenizer st = new StringTokenizer(command);
            st.nextToken();
            try
            {
                String type = st.nextToken();
                switch (type)
                {
                    case "Weapon":
                        Enchant(player, 300, Inventory.PAPERDOLL_RHAND);
                        break;

                }
            }
            catch (Exception e)
            {
            }
        }

 

That's all you need.. Create a html, name the bypass "enchant" and done.. Your wep from +150 to +300. 

Edited by 'Baggos'
  • 0
Posted

I like how it's look new code, but i can't to edit my code (even if it's wrong) because mby , and i am sure, i'll broke all code. And i don;t want to spam maxcheaters.com with errors. I post here the code. Maybe someone wants to help me. I post here all code. I want to know what i must change.

Thanks Guys

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Posts

    • Where I can buy a cheap domain .com? cheapest I found was on Godaddy for 12 euro and Hostinger for 10 euro.
    • Hello everyone, here's a simple and useful idea for any type of server.   This code applies a discount when a player makes a purchase inside a clan’s castle or clan hall, offering a benefit to clan members who own a castle or clan hall. Important: Merchant transactions must be handled through multisell, not buylist. The discount is directly applied within the multisell, so the price shown is already reduced.   "For example, if a scroll costs 1000 Adena and you set a 20% discount in the config, the final price when purchasing inside a castle or clan hall will be 800 Adena."   This code is developed on the public aCis 401 revision.   public static int CLAN_BASE_OWNERSHIP_MERCHANT_DISCOUNT; CLAN_BASE_OWNERSHIP_MERCHANT_DISCOUNT = clans.getProperty("ClanBaseOwnershipMechantDiscount", 20); # If clan owns a clan hall or castle, all members have a discount of X% at merchant transactions (multisell). # Discount applies only inside the base (castle or clan hall). ClanBaseOwnershipMechantDiscount = 20   /** diff --git a/aCis_gameserver/java/net/sf/l2j/gameserver/data/xml/MultisellData.java b/aCis_gameserver/java/net/sf/l2j/gameserver/data/xml/MultisellData.java index 556e111..bbf8e69 100644 --- a/aCis_gameserver/java/net/sf/l2j/gameserver/data/xml/MultisellData.java +++ b/aCis_gameserver/java/net/sf/l2j/gameserver/data/xml/MultisellData.java @@ -101,7 +101,7 @@ do { // send list at least once even if size = 0 - player.sendPacket(new MultiSellList(list, index)); + player.sendPacket(new MultiSellList(list, index, player)); index += PAGE_SIZE; } while (index < list.getEntries().size()); diff --git a/aCis_gameserver/java/net/sf/l2j/gameserver/network/clientpackets/MultiSellChoose.java b/aCis_gameserver/java/net/sf/l2j/gameserver/network/clientpackets/MultiSellChoose.java index 7c82c5b..1654abc 100644 --- a/aCis_gameserver/java/net/sf/l2j/gameserver/network/clientpackets/MultiSellChoose.java +++ b/aCis_gameserver/java/net/sf/l2j/gameserver/network/clientpackets/MultiSellChoose.java @@ -6,6 +6,7 @@ import net.sf.l2j.Config; import net.sf.l2j.gameserver.enums.FloodProtector; import net.sf.l2j.gameserver.enums.StatusType; +import net.sf.l2j.gameserver.enums.ZoneId; import net.sf.l2j.gameserver.enums.items.CrystalType; import net.sf.l2j.gameserver.model.Augmentation; import net.sf.l2j.gameserver.model.actor.Player; @@ -225,6 +226,20 @@ return; } + if (player.isInsideZone(ZoneId.CLAN_HALL) && player.getClan() != null && player.getClan().hasClanHall()) + { + e.setItemCount(e.getItemCount() * (100 - Config.CLAN_BASE_OWNERSHIP_MERCHANT_DISCOUNT) / 100); + if (e.getItemCount() == 0) + e.setItemCount(1); + } + + if (player.isInsideZone(ZoneId.CASTLE) && player.getClan() != null && player.getClan().hasCastle()) + { + e.setItemCount(e.getItemCount() * (100 - Config.CLAN_BASE_OWNERSHIP_MERCHANT_DISCOUNT) / 100); + if (e.getItemCount() == 0) + e.setItemCount(1); + } + if (Config.BLACKSMITH_USE_RECIPES || !e.getMaintainIngredient()) { // if it's a stackable item, just reduce the amount from the first (only) instance that is found in the inventory diff --git a/aCis_gameserver/java/net/sf/l2j/gameserver/network/serverpackets/MultiSellList.java b/aCis_gameserver/java/net/sf/l2j/gameserver/network/serverpackets/MultiSellList.java index 9269b06..c6102a0 100644 --- a/aCis_gameserver/java/net/sf/l2j/gameserver/network/serverpackets/MultiSellList.java +++ b/aCis_gameserver/java/net/sf/l2j/gameserver/network/serverpackets/MultiSellList.java @@ -2,6 +2,9 @@ import static net.sf.l2j.gameserver.data.xml.MultisellData.PAGE_SIZE; +import net.sf.l2j.Config; +import net.sf.l2j.gameserver.enums.ZoneId; +import net.sf.l2j.gameserver.model.actor.Player; import net.sf.l2j.gameserver.model.multisell.Entry; import net.sf.l2j.gameserver.model.multisell.Ingredient; import net.sf.l2j.gameserver.model.multisell.ListContainer; @@ -15,7 +18,9 @@ private boolean _finished; - public MultiSellList(ListContainer list, int index) + private Player _player; + + public MultiSellList(ListContainer list, int index, Player player) { _list = list; _index = index; @@ -28,6 +33,8 @@ } else _finished = true; + + _player = player; } @Override @@ -74,7 +81,14 @@ { writeH(ing.getItemId()); writeH(ing.getTemplate() != null ? ing.getTemplate().getType2() : 65535); - writeD(ing.getItemCount()); + + if (_player.isInsideZone(ZoneId.CLAN_HALL) && _player.getClan() != null && _player.getClan().hasClanHall()) + writeD((ing.getItemCount() * (100 - Config.CLAN_BASE_OWNERSHIP_MERCHANT_DISCOUNT) / 100) < 1 ? 1 : ing.getItemCount() * 80 / 100); + else if (_player.isInsideZone(ZoneId.CASTLE) && _player.getClan() != null && _player.getClan().hasCastle()) + writeD((ing.getItemCount() * (100 - Config.CLAN_BASE_OWNERSHIP_MERCHANT_DISCOUNT) / 100) < 1 ? 1 : ing.getItemCount() * 80 / 100); + else + writeD(ing.getItemCount()); + writeH(ing.getEnchantLevel()); writeD(0x00); // TODO: i.getAugmentId() writeD(0x00); // TODO: i.getManaLeft()  
    • DISCORD : utchiha_market telegram : https://t.me/utchiha_market SELLIX STORE : https://utchihamkt.mysellix.io/ Join our server for more products : https://discord.gg/uthciha-services https://campsite.bio/utchihaamkt
    • WTB EXP ETERNAL 10x new dm.
    • This project is based on the latest public aCis sources (revision 401) and supports a multi-client system (C4 & IL), making it suitable for custom usage but not for retail.   You can configure the SelectedClient option in server.properties and loginserver.properties to switch between C4 and IL.  Both clients are fully synchronized, including login, server selection, packets, and geodata.   Notable Features: - Completed the login and server selection phase for both clients. - Synchronized all packets to support both clients (including some specific features). - Reworked the datapack and SQL files (excluding HTML files) to work seamlessly with both clients. - Added geodata support for both clients. - Adapted nearly all AI, scripts, bosses, HTML, and MULTISELL files to match C4 functionality. - Reduced the maximum clan level from 8 to 5 (C4 feature). - Rewrote clan HTML to remove C5-C6 features.   Disabled the following C5 and C6 features: - Divine Inspiration (C6 feature). - Clan skills and clan reputation points (C5 feature). - Pledge class (C5 feature). - Hero skills (C5 feature). - Dueling system (C6 feature). - Augmentations (C6 feature). - Cursed weapons (C5-C6 feature).   General Improvements: - Performed a general HTML cleanup and optimized features based on the client version. - Added an option to display the remaining time of disabled skills. - Skill timestamps now update when using the skill list.   This flexibility allows you to create a unique progression system tailored to your needs. The price for the diff patch, which can be applied to aCis public sources, is €150. For inquiries, please contact me via PM or Discord (ID: @Luminous).
  • Topics

×
×
  • Create New...