Welcome to the RaGEZONE - MMORPG development forums.

[Guide] Auto-Enchanter

This is a discussion on [Guide] Auto-Enchanter within the L2J Tools and Tutorials forums, part of the L2J Development category; ok guys i didnt made that guide. i just found it on net and its really good. so i wanted ...

Results 1 to 11 of 11
  1. #1
    Registered
    Rank
    Member
    Join Date
    Jul 2008
    Posts
    11
    Liked
    0

    [Guide] Auto-Enchanter

    ok guys i didnt made that guide. i just found it on net and its really good. so i wanted to share it. take a look:

    A player will talk to the NPC, select an item (weapon, armor, or jewel), and the NPC will safely (100% chance) enchant this item for some payment. By "enchant" I mean making the item +1 higher than the enchantment it already has.
    I will keep this script simple. People can customize it further. I shall explain everything one step at a time, but I will skip parts I believe to be "trivial"...

    Ok...so let's assume that we have a custom NPC with id 90000 whom we will use for this. Anybody can easily create the default htm for this NPC. At the bottom, instead of the typical "Quest" link, we could do:
    Line number On/Off | Expand/Contract | Select all
    Code:
    <a action="bypass -h npc_%objectId%_Quest safe_enchant">Enchant an Item</a>
    When a player clicks on that link, it will directly call the onTalk section of the script that we are about to write.

    So, let's go to the "data/scripts/custom" folder, create a new subdirectory called "safe_enchant" and create a new file in there, name __init__.py

    This file will follow the quest prototype, so let's start up with the usual quest stuff. For now, the file should look something like this:

    Code:
    import sys
    from net.sf.l2j.gameserver.model.quest import State
    from net.sf.l2j.gameserver.model.quest import QuestState
    from net.sf.l2j.gameserver.model.quest.jython import QuestJython as JQuest
    
    qn = "safe_enchant"
    
    ENCHANT_NPC = 90000
    
    class Quest (JQuest) :
    
      def __init__(self,id,name,descr): JQuest.__init__(self,id,name,descr)
    
      def onEvent (self,event,st) :
      return
    
      def onTalk (self,npc,player):
        htmltext = "<html><body>You are either not on a quest that involves this NPC, or you don't meet this NPC's minimum quest requirements.</body></html>"
        st = player.getQuestState(qn)
        if not st : return htmltext
        return htmltext
    
    QUEST    = Quest(9000,qn,"Custom")
    
    QUEST.addStartNpc(ENCHANT_NPC)
    QUEST.addTalkId(ENCHANT_NPC)
    This has set us up to start working with the script. Now, what we need next is some way for the player to see what items are available for enchanting among the items in the inventory, select the item, and get the enchantment...

    For the purposes of this simple sample, I will assume that all enchantments cost 1,000,000 adena. You can easily change this...So let's first create an htm where the NPC explains how enchantment works, and what it costs. It is best to not mess with equipped items, just due to some exploits that have existed in the past. So let's tell the player we will only do this for unequipped items. This will do:
    Code:
    <html><body>Enchanter:<br>
    Select an item you wish to enchant and I will add 1 to its enchantment level!  All enchantments cost 1,000,000 adena.  Please unequip the item that you wish to enchant, if you are currently wearing it.  Are you ready?<br>
    <a action="bypass -h Quest safe_enchant choose_item">"I would like to enchant an item."</a></body></html>
    Let's name this 1.htm and place it in the same folder with the __init__.py file that we just created. This htm will need to be returned as soon as the player clicks on the link from the default script, so we'll put code in onTalk to display this:
    Code:
        if npc.getNpcId() == ENCHANT_NPC :
          htmltext = "1.htm"
    Next, we want to make it such that, when a player clicks on the link, he gets a list of items from his inventory to choose from. So we'll have to add some code in onEvent and handle this...
    Code:
        if event == "choose_item" :
          htmltext = ""
          for Item in st.getPlayer().getInventory().getItems():
            #given an item instance, get the item template to check what type it is
            itemType = Item.getItem().getItemType().toString()
            if itemType in ['None','Light','Heavy','Magic','Shield','Sword','Blunt','Dagger','Bow','Pole','Etc','Fist','Dual Sword','Dual Fist','Big Sword','Big Blunt','Ancient','Crossbow','Rapier'] and item.getItem().getCrystalType() > 0 :
                htmltext += "<a action=\"bypass -h Quest safe_enchant enchantItem_" + str(Item.getObjectId()) +"\">" + Item.getItem().getName() + "+" + str(Item.getEnchantLevel()) + "</a><br>"
          if htmltext == "":
            htmltext = "You have no enchantable items in your inventory"
          htmltext = "<html><body>Enchanter:<br>Please choose which item you wish me to enchant, from the below list:<br>" + htmltext + "</body></html>"
    Notice that here selecting the enchantable items by item type is a bit of an overkill, but I purposely made it this way so you can more easily exclude jewels (None type), certain types of armor, or certain types of weapon (I can forsee people not wanting to allow safe enchanting of dual swords, for example). You can add similar checks for bodypart too, if you want...In addition, I added a check that the crystalType is not 0, meaning that only D Grade or higher can be enchanted. Each link shows the name of the item as well as the enchantment level, to help the player identify which weapon he/she is selecting. It uses the server-side item name, which actually includes the SA name, if any. However, it will not include info about the augmentations. You can add this info if you wish, but in general it should not be too important...Also, you could change this piece of code a little in order to show prices. That is, if you wish to have a different price for each item, next to each item you could also display the price. Of course, your script will need some way to identify what price to charge and the details of that are all for you to decide.
    When a player clicks on a link, the objectId of the selected item is passed back to the script, so we can guarantee that we grab exactly the item the user selected, not just any item of the same name ;)

    At the next step, we must be careful, we will identify that the player has selected an item, find that item from the inventory, and enchant it. We have to be careful here as players like to try to cheat and exploit by selecting an item and quickly getting rid of it, or such naughty actions ;)
    In addition, we must ensure that the player has enough adena (or otehr items) to pay for this exchange.
    This again needs to happen in onEvent
    Code:
        elif event.startswith("enchantItem_"):
          # get the object id out of the event string
          objId = int(event.replace("enchantItem_", ""))
          # to avoid exploitation, check if the stored objectId still corresponds to an existing item
          # and if that item is still not equipped
          Item = st.getPlayer().getInventory().getItemByObjectId(objId )
          if Item and not Item.isEquipped() :
            if st.getQuestItemsCount(57) >= 1000000 :
              Item.setEnchantLevel(Item.getEnchantLevel()+1)
              st.takeItems(57, 1000000)
              htmltext = "congratulations.htm"
            else :
              htmltext = "notEnoughItems.htm"
          else :
            htmltext = "cheater.htm"
    Here, we just checked if a link that started with "enchantItem_" was clicked, then we grabbed the remaining of the link as a number, the object id, found the item, checked if it's still in the inventory and not equipped...If any of this fails, the player is trying to cheat, so we return "cheater.htm". If all is good, we finally also check if the player has enough adena. If no, we return some dialog text to inform the player about "not enough adena" (or other items). If the player does have enough adena, we add 1 to the enchantment and take our 1,000,000 adena fee before returning a "congratulations.htm". Of course, you'll have to create those two htm files, but they can be pretty generic, so I'll leave those up to you.
    The line "st.takeItems(57,1000000)" could be changed if you wanted to charge a different amount or a different item than in my script and with some effort you could even make it charge a different amount for each input item...

    Finally, at your option, you may wish to keep your server's limits for enchantments. That is, you may wish to allow players to enchant their items beyond the server's max, or you may wish to limit them by your server's configs. If you wish not to impose a limit, everything we discussed above can be put together and the script will be done.

    So just putting together all the parts from above for the __init__.py script , the overall script will be as follows:
    Code:
    import sys
    from net.sf.l2j.gameserver.model.quest import State
    from net.sf.l2j.gameserver.model.quest import QuestState
    from net.sf.l2j.gameserver.model.quest.jython import QuestJython as JQuest
    
    qn = "safe_enchant"
    
    ENCHANT_NPC = 90000
    acceptableItemTypes = ['None','Light','Heavy','Magic','Shield','Sword','Blunt','Dagger','Bow','Pole','Etc','Fist','Dual Sword','Dual Fist','Big Sword','Big Blunt','Ancient','Crossbow','Rapier']
    
    class Quest (JQuest) :
    
      def __init__(self,id,name,descr): JQuest.__init__(self,id,name,descr)
    
      def onEvent (self,event,st) :
        if event == "choose_item" :
          htmltext = ""
          for Item in st.getPlayer().getInventory().getItems():
            #given an item instance, get the item template to check what type it is
            itemType = Item.getItem().getItemType().toString()
            if itemType in acceptableItemTypes and item.getItem().getCrystalType() > 0 :
                htmltext += "<a action=\"bypass -h Quest safe_enchant enchantItem_" + str(Item.getObjectId()) +"\">" + Item.getItem().getName() + "+" + str(Item.getEnchantLevel()) + "</a><br>"
          if htmltext == "":
            htmltext = "You have no enchantable items in your inventory"
          htmltext = "<html><body>Enchanter:<br>Please choose which item you wish me to enchant, from the below list:<br>" + htmltext + "</body></html>"
        elif event.startswith("enchantItem_"):
          # get the object id out of the event string
          objId = int(event.replace("enchantItem_", ""))
          # to avoid exploitation, check if the stored objectId still corresponds to an existing item
          # and if that item is still not equipped
          Item = st.getPlayer().getInventory().getItemByObjectId(objId )
          if Item and not Item.isEquipped() :
            if st.getQuestItemsCount(57) >= 1000000 :
              Item.setEnchantLevel(Item.getEnchantLevel()+1)
              st.takeItems(57, 1000000)
              htmltext = "congratulations.htm"
            else :
              htmltext = "notEnoughItems.htm"
          else :
            htmltext = "cheater.htm"
        return htmltext
    
      def onTalk (self,npc,player):
        htmltext = "<html><body>You are either not on a quest that involves this NPC, or you don't meet this NPC's minimum quest requirements.</body></html>"
        st = player.getQuestState(qn)
        if not st : return htmltext
        if npc.getNpcId() == ENCHANT_NPC :
           htmltext = "1.htm"
        return htmltext
    
    QUEST    = Quest(9000,qn,"Custom")
    
    QUEST.addStartNpc(ENCHANT_NPC)
    QUEST.addTalkId(ENCHANT_NPC)
    If you additionally wish to limit the max enchantment based on your server configs, you will need to first import the config class into your script. That is, at the top of the script you will need the line:
    Line number On/Off | Expand/Contract | Select all
    from from net.sf.l2j import Config
    Next, you will need to add some if/else statements where you check the item type, the config option for max-enchantment for that item type, and if the item is already at or above the max. Just before getting the adena, we can add these few lines:
    Code:
    itemType = Item.getItem().getItemType().toString()
    weapons = ['Sword','Blunt','Dagger','Bow','Pole','Etc','Fist','Dual Sword','Dual Fist','Big Sword','Big Blunt','Ancient','Crossbow','Rapier']
    armors = ['Light','Heavy','Magic','Shield']
    jewels = ['None']
    if (itemType in weapons and Item.getEnchantLevel >= Config.ENCHANT_MAX_WEAPON) or (IitemType in armors and Item.getEnchantLevel >= Config.ENCHANT_MAX_ARMOR) or (itemType in jewels and Item.getEnchantLevel >= Config.ENCHANT_MAX_JEWELRY) :
       htmltext = "reachedMaxEnchant.htm"
    else: #... take the adena, give the +1 enchant...
    So again, putting everything together, we have:
    Code:
    import sys
    from net.sf.l2j import Config
    from net.sf.l2j.gameserver.model.quest import State
    from net.sf.l2j.gameserver.model.quest import QuestState
    from net.sf.l2j.gameserver.model.quest.jython import QuestJython as JQuest
    
    qn = "safe_enchant"
    
    ENCHANT_NPC = 90000
    weapons = ['Sword','Blunt','Dagger','Bow','Pole','Etc','Fist','Dual Sword','Dual Fist','Big Sword','Big Blunt','Ancient','Crossbow','Rapier']
    armors = ['Light','Heavy','Magic','Shield']
    jewels = ['None']
    acceptableItemTypes = weapons+armors+jewels
    
    class Quest (JQuest) :
    
      def __init__(self,id,name,descr): JQuest.__init__(self,id,name,descr)
    
      def onEvent (self,event,st) :
        if event == "choose_item" :
          htmltext = ""
          for Item in st.getPlayer().getInventory().getItems():
            # given an item instance, get the item template to check what type it is
            itemType = Item.getItem().getItemType().toString()
            itemGrade = Item.getItem().getCrystalType()
            if itemType in acceptableItemTypes and itemGrade > 0 :
              htmltext += "<a action=\"bypass -h Quest safe_enchant enchantItem_" + str(Item.getObjectId()) +"\">" + Item.getItem().getName() + "+" + str(Item.getEnchantLevel()) + "</a><br>"
          if htmltext == "":
            htmltext = "You have no enchantable items in your inventory"
          htmltext = "<html><body>Enchanter:<br>Please choose which item you wish me to enchant, from the below list:<br>" + htmltext + "</body></html>"
        elif event.startswith("enchantItem_"):
          # get the object id out of the event string
          objId = int(event.replace("enchantItem_", ""))
          # to avoid exploitation, check if the stored objectId still corresponds to an existing item
          # and if that item is still not equipped
          Item = st.getPlayer().getInventory().getItemByObjectId(objId )
          if Item and not Item.isEquipped() :
            itemType = Item.getItem().getItemType().toString()
            itemEnchant = Item.getEnchantLevel()
            if st.getQuestItemsCount(7267) >= 10 :
               if (itemType in weapons and itemEnchant >= Config.ENCHANT_MAX_WEAPON) or (itemType in armors and itemEnchant >= Config.ENCHANT_MAX_ARMOR) or (itemType in jewels and itemEnchant >= Config.ENCHANT_MAX_JEWELRY) :
                  htmltext = "reachedMaxEnchant.htm"
               else :
                 Item.setEnchantLevel(itemEnchant+1)
                 st.takeItems(57, 1000000)
                 htmltext = "congratulations.htm"
            else :
              htmltext = "notEnoughItems.htm"
          else :
            htmltext = "cheater.htm"
        return htmltext
    
      def onTalk (self,npc,player):
        htmltext = "<html><body>You are either not on a quest that involves this NPC, or you don't meet this NPC's minimum quest requirements.</body></html>"
        st = player.getQuestState(qn)
        if not st : return htmltext
        if npc.getNpcId() == ENCHANT_NPC :
           htmltext = "1.htm"
        return htmltext
    
    QUEST    = Quest(9000,qn,"Custom")
    
    QUEST.addStartNpc(ENCHANT_NPC)
    QUEST.addTalkId(ENCHANT_NPC)
    Again, you will need to add the file reachedMaxEnchant.htm in the same directory and put some text to it, but that should be simple. Also, if you prefer, you can limit the max enchantment from this script to any other value (for example if your config allows up to +50 but you want people to get safe enchants for the script only up to +25) simply by replace the Config.ENCHANT_MAX_YYYYYY with the value you like...
    "I need to know God's Thoughts.. The Rest are details." - Albert Einstein

  2. #2
    Newbie
    Rank
    Member
    Join Date
    Nov 2007
    Posts
    3
    Liked
    0

    Re: Auto-Enchanter

    cool xD i go testing!

  3. #3
    ~ Java - MySQL~
    Rank
    Moderator
    Join Date
    Oct 2006
    Location
    Java_Home
    Posts
    6,197
    Liked
    99

    Re: Auto-Enchanter

    nice - moved to the right section


    **If you have any problem with anything feel free to pm me.**

  4. #4
    Bangin' my head
    Rank
    Member +
    Join Date
    Apr 2006
    Location
    Latvia
    Posts
    1,062
    Liked
    11

    Re: [Guide] Auto-Enchanter

    nice one :)

  5. #5
    Bendin' Over
    Rank
    Member +
    Join Date
    Oct 2006
    Location
    Athens ,Greece
    Posts
    787
    Liked
    0

    Re: [Guide] Auto-Enchanter

    Nice one,but I bet you didn't ask permission from Eyerobot...and that's rude...

  6. #6
    Bangin' my head
    Rank
    Member +
    Join Date
    Apr 2006
    Location
    Latvia
    Posts
    1,062
    Liked
    11

    Re: [Guide] Auto-Enchanter

    yes, there aren't any credits, but he added:
    ok guys i didnt made that guide. i just found it on net and its really good. so i wanted to share it. take a look:

  7. #7
    Member
    Rank
    Member
    Join Date
    Dec 2004
    Posts
    51
    Liked
    0

    Re: [Guide] Auto-Enchanter

    it works in l2 emu?

  8. #8
    Newbie
    Rank
    Member
    Join Date
    Nov 2007
    Location
    Lithuania
    Posts
    4
    Liked
    0

    Re: [Guide] Auto-Enchanter

    i made everything good in html, but when i am loading my server it drops this error:
    WARNING Failed executing script: C:\server\l2jfree-gameserver\dist\data\scripts\
    custom\safe_enchant\__init__.py. See __init__.py.error.log for details.


    i viewed the init py error log:
    Error on: C:\server\l2jfree-gameserver\dist\data\scripts\custom\safe_enchant\__init__.py.error.log
    Line: -1 - Column: -1

    Traceback (innermost last):
    File "__init__.py", line 2, in ?
    ImportError: no module named net

    but i cant understand where is the problem and how to fix that anybody can help me with that?
    sorry for my bad english

  9. #9
    Bangin' my head
    Rank
    Member +
    Join Date
    Apr 2006
    Location
    Latvia
    Posts
    1,062
    Liked
    11

    Re: [Guide] Auto-Enchanter

    1) there is an answer for your problem (it's posted in the forum)
    2) that script is for L2Emu not for L2jFree
    3) ... line 2... no module named net... it says where you should look, so why don't you go and look for the error there

  10. #10
    Member
    Rank
    Member
    Join Date
    Nov 2008
    Location
    Canada
    Posts
    81
    Liked
    0

    Re: [Guide] Auto-Enchanter

    Quote Originally Posted by estaZ View Post
    i made everything good in html, but when i am loading my server it drops this error:
    WARNING Failed executing script: C:\server\l2jfree-gameserver\dist\data\scripts\
    custom\safe_enchant\__init__.py. See __init__.py.error.log for details.


    i viewed the init py error log:
    Error on: C:\server\l2jfree-gameserver\dist\data\scripts\custom\safe_enchant\__init__.py.error.log
    Line: -1 - Column: -1

    Traceback (innermost last):
    File "__init__.py", line 2, in ?
    ImportError: no module named net

    but i cant understand where is the problem and how to fix that anybody can help me with that?
    sorry for my bad english
    Simply open L2JFree's core in Eclipse and find the correct imports.
    This script (if you look at the imports) was made for L2J but can easily be ported to L2JFree if you just change the imports

    On another note, I have an auto-enchanter on one of my servers, but I did it for equipped items only (jewels/armor/weapon) so that it's harder(if not impossible) to exploit. This is just my opinion, I am sure there will be people with other opinions about this.

  11. #11
    Newbie
    Rank
    Member
    Join Date
    Aug 2005
    Posts
    1
    Liked
    0

    Re: [Guide] Auto-Enchanter

    You are using L2JFree and the script is written fpr L2J !

    "from net.sf.l2j import Config"
    "from net.sf.l2j.gameserver.model.quest import State"
    "from net.sf.l2j.gameserver.model.quest import QuestState"
    "from net.sf.l2j.gameserver.model.quest.jython import QuestJython as JQuest"


    these lines has to changed to fit l2jfree

    "from com.l2jfree import Config"
    "from com.l2jfree.gameserver.model.quest import State"
    "from com.l2jfree.gameserver.model.quest import QuestState"
    "from com.l2jfree.gameserver.model.quest.jython import QuestJython as JQuest"

    Thats it :D

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •