Jump to content

Recommended Posts

Posted

dude

imports... -.-'

I know that, but others don't as you see.. :P You ask them to show the error, given line where is error and they don't get it and they give you random shit.. It's really frustrating sometimes.. :D

Posted

this code is hardcode.

 

the html is better to define them as such and not within the code.

 

execution times is better to write this as follows

        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;
 
TextBuilder _td = new TextBuilder();
_td.append("<html>");
        _td.append("<title>L2Mondial Enchanter</title>");
        _td.append("<body>");
        _td.append("<center><img src=\"L2UI_CH3.herotower_deco\" width=256 height=32><br>");
        _td.append("<font color=\"FF9900\">" + title + "</font></center><br>" + content + "<br><br>");
        _td.append("<center><a action=\"bypass -h Quest Enchant " + enchantType + "\">Go Back</a></center>");
        _td.append("</body>");
        _td.append("</html>");


        return _td.toString();
Posted (edited)

 

    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;
 
all should be private final static
 
Overall a cool code, but imo its very poor

 

 

Disagree, the variables in this class are only being accessed by it's own class/itself. It is not being called by any other outside class or instance.

 

Why would you want to make all the variables global? This will keep them in memory even when this instance/class is unloaded/not in use.

 

Having them as non static, dynamic, will only access them and keep them in memory while the instance of that class is still being used/in memory.

 

You should only use static methods/variables etc when you need to access them from other classes/instances, and dont need to initiate a new instance of the class holding the needed variables/methods. Hope I explained it well, try the example program and you should see.

 

They Should be -> private final int

 

Example:

void main(){
{
dynamic int a = 1;
static int b = 1;
}
// a deleted from memory but b still is there
cout << b;
cout << a; // error occured because a deleted
} 
Edited by MlDNlGHT
Posted

 

Disagree, the variables in this class are only being accessed by it's own class/itself. It is not being called by any other outside class or instance.

 

Why would you want to make all the variables global? This will keep them in memory even when this instance/class is unloaded/not in use.

 

Having them as non static, dynamic, will only access them and keep them in memory while the instance of that class is still being used/in memory.

 

You should only use static methods/variables etc when you need to access them from other classes/instances, and dont need to initiate a new instance of the class holding the needed variables/methods. Hope I explained it well, try the example program and you should see.

 

They Should be -> private final int

 

Example:

void main(){
{
dynamic int a = 1;
static int b = 1;
}
// a deleted from memory but b still is there
cout << b;
cout << a; // error occured because a deleted
} 

 

Good explanation and i thank you for taking the time!

Posted (edited)

 

Disagree, the variables in this class are only being accessed by it's own class/itself. It is not being called by any other outside class or instance.

 

Why would you want to make all the variables global? This will keep them in memory even when this instance/class is unloaded/not in use.

 

Having them as non static, dynamic, will only access them and keep them in memory while the instance of that class is still being used/in memory.

 

You should only use static methods/variables etc when you need to access them from other classes/instances, and dont need to initiate a new instance of the class holding the needed variables/methods. Hope I explained it well, try the example program and you should see.

 

They Should be -> private final int

 

Example:

void main(){
{
dynamic int a = 1;
static int b = 1;
}
// a deleted from memory but b still is there
cout << b;
cout << a; // error occured because a deleted
} 

 

 

it should be static since the variable belongs to the class and not neceserly to the object, just like config variables... Static variables have better perfomance than non-static, for example they are faster.

I find no reason for them to be nonstatic since I see no OOP here

 

However I will neither argue with you, your argument is valid, since the "perfomance" while alocating memory is nowaday useless due to the modern JVMs

Edited by xdem
Posted

Error. Help. http://postimg.org/image/r28k0kbw1/ For all items he say is no't encantable!!!

Here is the code what i make for freya. Some help plz thx

 

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.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());
 
    private final static int npcId = 9994;
 
    // Item required to enchant armor +1
    private final static int itemRequiredArmor = 6393;
    private final static int itemRequiredArmorCount = 50;
 
    // Item required to enchant jewels +1
    private final static int itemRequiredJewels = 6393;
    private final static int itemRequiredJewelsCount = 50;
 
    // Item required to enchant weapon +1
    private final static int itemRequiredWeapon = 6393;
    private final static int itemRequiredWeaponCount = 150;
 
    // Item required to enchant belt/shirt +1
    private final static int itemRequiredBeltShirt = 6393;
    private final static 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)
                {
                    if ( item.isCommonItem() && item.isEquipable() && !item.isConsumable() && !item.isCommonItem() && !item.isOlyRestrictedItem() && !item.isShadowItem() && !item.isQuestItem() )
                    {
                        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);
                        }
                    }
                    else
                    {
                        player.sendMessage("Your " + item.getItem().getName() + " is not enchantable!");
                        return drawHtml("Not enchantable item!", "<center>Your <font color=\"FF7200\">" + item.getItem().getName() +"</font> is not enchantable!</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;
    }
}
Posted (edited)


-- if ( item.isCommonItem() && item.isEquipable() && !item.isConsumable() && !item.isCommonItem() && !item.isOlyRestrictedItem() && !item.isShadowItem() && !item.isQuestItem() )

++ if ( item.isEquipable() && !item.isConsumable() && !item.isCommonItem() && !item.isOlyRestrictedItem() && !item.isShadowItem() && !item.isQuestItem() )

 

Edited by HappyLDE
  • 2 weeks later...
Posted (edited)

it should be static since the variable belongs to the class and not neceserly to the object, just like config variables... Static variables have better perfomance than non-static, for example they are faster.

I find no reason for them to be nonstatic since I see no OOP here

 

However I will neither argue with you, your argument is valid, since the "perfomance" while alocating memory is nowaday useless due to the modern JVMs

 

It doesn't make 1 ioata of a difference if they belong to the class or the object, in the same class. All the objects in that class are in that class. It would make a difference if the objects are in a different class.

 

As for faster processing , I would sacrafic a few ms loading/processing time for less total memory usage of the entire application.  I don't believe the "change off" is worth it.

 

Guess it's all about one's coding style..

Edited by MlDNlGHT
  • 3 weeks later...
  • 2 weeks later...
Posted

Hello,

I tried using your updated enchant manager npc (V2) in my H5 server but keep getting this L2ItemInstance error. I haven't changed any of your code.

 

post-135436-0-69473800-1388430360_thumb.png

 

I haven't got much experience with this and am still trying to learn, any help would be appreciated :D

Guest
This topic is now closed to further replies.



  • Posts

    • From Salvation onwards I think you need a patched nwindow.dll that allows such modifications, try to see if you get what you need here: https://drive.google.com/drive/u/1/folders/1LLbQFGf8KlR-O0Iv5umfF-pwZgrDh9bd
    • hello everyone! I am wanting to save the files (Ini. - Data - ) of the EP5 Client: Salvation... But they generate the error "corrupt files"... I tried several versions of L2FileEditor without good results. I need help! Thank you!
    • Opening December 6th at 19:00 (GMT +3)! Open Beta Test from November 30th!   https://l2soe.com/   🌟 Introducing L2 Saga of Eternia: A Revolution in Lineage 2 High Five! 🌟   Dear Lineage 2 enthusiasts, Prepare to witness the future of private servers! L2 Saga of Eternia is not just another High Five project—it’s a game-changing experience designed to compete with the giants of the Lineage 2 private server scene. Built for the community, by the community, we’re here to raise the bar in quality, innovation, and longevity. What Sets Us Apart? 💎 No Wipes, Ever Say goodbye to the fear of losing your progress. Our server is built to last and will never close. Stability and consistency are our promises to you. ⚔️ Weekly New Content Our dedicated development team ensures fresh challenges, events, and updates every week. From custom quests to exclusive features, there will always be something exciting to explore. 💰 No Pay-to-Win Skill and strategy matter most here. Enjoy a balanced gameplay environment where your achievements come from effort, not your wallet. 🌍 A Massive Community With 2000+ players expected, join a vibrant and active community of like-minded adventurers ready to conquer the world of Aden. 🏆 Fair and Competitive Gameplay Our systems are designed to promote healthy competition while avoiding abusive mechanics and exploits. 🔧 Professional Development From advanced bug fixes to carefully curated content, we pride ourselves on smooth performance, no lag, and unparalleled server quality. Key Features Chronicle: High Five with unique interface Rate: Dynamic x10 rates Class Balance: Carefully fine-tuned for a fair experience PvP Focused: PvP Ranking & aura display effect for 3 Top PvPers every week Custom Events: Seasonal and permanent events to keep you engaged Additional Features:   Custom Endgame Content: Introduce unique dungeons, raids, or zones unavailable in other servers. Player-Driven Economy: Implement a strong market system and avoid overinflated drops or rewards. Epic Siege Battles: Announce special large-scale sieges and PvP events. Incentives for Streamers and Clans: Attract influencers and big clans to boost server publicity. Roadmap Transparency: Share a public roadmap of planned updates to build trust and excitemen   Here you can read all the features: https://l2soe.com/features   Video preview: Join the Revolution! This is your chance to be part of something legendary. L2 Saga of Eternia is not just a server; it’s a movement to redefine what Lineage 2 can be. Whether you’re a seasoned veteran or a newcomer to the world of Aden, we invite you to experience Lineage 2 at its finest.   Official Launch Date: December 6th 2024 Website: https://l2soe.com/ Facebook: https://www.facebook.com/l2soe Discord: https://discord.com/invite/l2eternia   Let’s build the ultimate Lineage 2 experience together. See you in-game! 🎮
    • That's like a tutorial on how to run l2 on MacOS Xd but good job for the investigation. 
  • Topics

×
×
  • Create New...