Jump to content

[Guide][Auto-Enchanter]


Recommended Posts

All Credits of this guide to g13h4ck3r:

 

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

 

<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:

 

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:

 

<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:

 

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...

 

 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

 

  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:

 

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)

 

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:

 

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:

 

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...

 

##############################################################################

 

Well Its Not So DIficul , u just need time  ::)

Link to comment
Share on other sites

nah, the credits are WRONG !

 

This has been made By FULMINIUS ! From L2JDP !

 

Proof => http://l2jdp.com/forum/viewtopic.php?f=13&t=8468

 

on : 30-jan-2008

 

XD

Link to comment
Share on other sites

:P.....

 

Its very Nice Share and Guide...Thx GrisoM!!

 

Keep Up....

 

 

(I have a small idea! If you can do this npc to spawn after kill one rb(your choice raid)!

And Spawn for only 1 minute!!

But this 1 min you can give +3 free in your weapon.....) :D

 

 

I try to think him how it could become this Script!!

 

Nice Again...Great Guide!

Link to comment
Share on other sites

nah, the credits are WRONG !

 

Rofl how shouold i know if the guy from where i read this from didnt give any credits and start the post saying :

 

Here I will share bla bla bla xD

 

(I have a small idea! If you can do this npc to spawn after kill one rb(your choice raid)!

And Spawn for only 1 minute!!

But this 1 min you can give +3 free in your weapon.....) :D

 

That would be crazy ;P

 

It is a really nice share! I will test it myself and if I will post results ;) Thanks GriSsS

 

Hope it works Cos for what i have seen this could be really cool

Link to comment
Share on other sites

  • 5 months later...
  • 2 months later...

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
Reply to this topic...

×   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

    • 2 Factor Authentication Code for 100% secure login. Account provided with full information (email, password, dob, gender, etc).
    • ready server for sale, also available for testing with ready and beautiful npc zone pvp with custom 2 epic core orfen lvl2 with all maps ready all quests work at 100% ready comm  board with buffer teleport gm shop service anyone interested send me a pm many more that I forget  Exp/Sp : x30 (Premium: x40)    Adena : x7 (Premium: x10)   Drop : x7 (Premium: 10)   Spoil : x7 (Premium: 10)   Seal Stones : x7 (Premium: 10)   Raid Boss EXP/SP : x10   Raid Boss Drop : x3 (Premium: x5)   Epic Boss Drop : x1 Enchants   Safe Enchant : +3   Max Enchant : +16   Normal Scroll of Enchant Chance : 55%   Blessed Scroll of Enchant Chance : 60% Game Features   GMShop (Max. B-Grade)   Mana Potions (1000 MP, 10 sec Cooldown)   NPC Buffer (Include all buffs, 2h duration)   Auto-learn skills (Except Divine Inspiration)   Global Gatekeeper   Skill Escape: 15 seconds or /unstuck   1st Class Transfer (Free)   2nd Class Transfer (Free)   3rd Class Transfer (700 halisha mark)   Subclass (Items required from Cabrio / Hallate / Kernon / Golkonda + Top B Weapon + 984 Cry B)   Subclass 5 Subclasses + Main (Previous subclasses to level 75 to add new one)   Noblesse (Full Retail Quest)   Buff Slots: 24 (28 with Divine Inspiration LVL 4)   Skill Sweeper Festival added (Scavenger level 36)   Skill Block Buff added   Maximum delevel to keep Skills: 10 Levels   Shift + Click to see Droplist   Global Shout & Trade Chat   Retail Geodata and Pathnodes   Seven Signs Retail   Merchant and Blacksmith of Mammon at towns   Dimensional Rift (Min. 3 people in party to enter - Instance)   Tyrannosaurus drop Top LS with fixed 50% chance   Fast Augmentation System (Using Life Stones from Inventory)   Chance of getting skills (Normal 1%, Mid 3%, High 5%, Top 10%)   Wedding System with 30 seconds teleport to husband/wife Olympiad & Siege   Olympiad circle 14 days. (Maximum Enchant +6)   Olympiads time 18:00 - 00:00 (GMT +3)   Non-class 5 minimum participants to begin   Class based disabled   Siege every week.   To gain the reward you need to keep the Castle 2 times. Clans, Alliances & Limits   Max Clients/PC: 2   Max Clan Members: 36   Alliances allowed (Max 1 Clans)   24H Clan Penalties   Alliance penalty reset at daily restart (3-5 AM)   To bid for a Clan Hall required Clan Level 6 Quests x3   Alliance with the Ketra Orcs   Alliance with the Varka Silenos   War with Ketra Orcs   War with the Varka Silenos   The Finest Food   A Powerful Primeval Creature   Legacy of Insolence   Exploration of Giants Cave Part 1   Exploration of Giants Cave Part 2   Seekers of the Holy Grail   Guardians of the Holy Grail   Hunt of the Golden Ram Mercenary Force   The Zero Hour   Delicious Top Choice Meat   Heart in Search of Power   Rise and Fall of the Elroki Tribe   Yoke of the Past     Renegade Boss (Monday to Friday 20:00)   All Raid Boss 18+1 hours random respawn   Core (Jewel +1 STR +1 DEX) Monday, Wednesday and Friday 20:00 - 21:00 (Maximum level allowed to enter Cruma Tower: 80)   Orfen (Jewel +1 INT +1 WIT) Monday to Friday, 20:00 - 21:00 (Maximum level allowed to enter Sea of Spores: 80)   Ant Queen Monday and Friday 21:00 - 22:00 (Maximum level allowed to enter Ant Nest: 80)   Zaken Monday,Wednesday,Friday 22:00 - 23:00 (Maximum level allowed to enter Devil's Isle: 80)   Frintezza Tuesday, Thursday and Sunday 22:00 – 23:00 (Need CC of 4 party and 7 people in each party min to join the lair, max is 8 party of 9 people each)   Baium (lvl80) Saturday 22:00 – 23:00   Antharas Every 2 Saturdays 22:00 - 23:00 Every 2 Sundays (alternating with Valakas) 22:00 – 23:00   Valakas Every 2 Saturdays 22:00 - 23:00 Every 2 Sundays (alternating with Antharas) 22:00 – 23:00   Subclass Raids (Cabrio, Kernon, Hallate, Golkonda) 18hours + 1 random   Noblesse Raid (Barakiel) 6 hours + 15min random   Varka’s Hero Shadith 8 hours + 30 mins random (4th lvl of alliance with Ketra)   Ketra’s Hero Hekaton 8 hours + 30 mins random (4th lvl of alliance with Varka)   Varka’s Commander Mos 8 hours + 30 mins random (5th lvl of alliance with Ketra)   Ketra’s Commander Tayr 8 hours + 30 mins random (5th lvl of alliance with Varka)
    • Have a great day! Unfortunately, we can not give you the codes at the moment, but they will be distributed as soon as trial is back online, thanks for understanding! Other users also can reply there for codes, we will send them out some time after.
    • Ok mates i would like to play a pridestyle server (interluide, gracie w/ever) Is there any such server online and worth playing?
  • Topics

×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock