Author Topic: Anatomy of a crafting script - A learn while you script journey  (Read 4292 times)

0 Members and 1 Guest are viewing this topic.

Offline CrisisTopic starter

  • Global Moderator
  • *
  • *
  • Posts: 2998
  • Activity:
    3.2%
  • Reputation Power: 41
  • Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.
  • Gender: Male
  • Scripting well enough to break things!
  • Respect: +205
  • Referrals: 2
    • View Profile
0
Greetings! I will make the introduction short. I made a carpentry crafting script a while back based off of another crafting script that a friend helped me with. He plays runuo and helped me get it working but I did not understand a lot of the tweaks and timings that he added. My goal here is to remake the carpentry script from scratch and to dissect each sub so that I understand (or hopefully understand) everything that goes into it. My scripting skills are on the lower end while my knowledge has been gaining. I invite everyone from the most novice scripter to the most legendary scripter to follow along, learn, encourage, and explain. I am sure that there will be a lot of "aha' moments along with a lot of "DOH" moments as well. This will hopefully help everyone whether you are just learning to write, whethere you are not planning on writing scripts but want to learn to tweak them, or even more advanced scripters that might learn something new.

Since this is for my learning benefit, I will ask one thing. Please do not be negative. If you don't have something constructive to say, please don't post. I have never had that problem here at SUO but I do want to say it. I know that I will make a lot of newbie mistakes and might completely miss the most obvious things but I want to learn. I know that this could benefit others as well. With that being said, thank you for reading and hopefully this will be a great learning tool for some and entertaining for others!  ;)



EDIT: This will be an ongoing work in progress and how quickly it goes will depend on my free time and how quickly I understand a step before moving on the next step. Please have patience.  8)
« Last Edit: April 18, 2014, 05:15:49 AM by Crisis »

Offline CrisisTopic starter

  • Global Moderator
  • *
  • *
  • Posts: 2998
  • Activity:
    3.2%
  • Reputation Power: 41
  • Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.
  • Gender: Male
  • Scripting well enough to break things!
  • Respect: +205
  • Referrals: 2
    • View Profile
Re: Anatomy of a crafting script - A learn while you script journey
« Reply #1 on: April 18, 2014, 05:13:33 AM »
0
Step 1: Menu

A crafting script should really have a menu in my opinion. While you can just use the pause and the play button on easyuo itself, a menu makes it so much easier and quicker. I am not going to go into much detail for a menu at this moment but will link this great write up from the EUO website. There are 2 tutorials, once you understand the first then you can go onto the second which uses a menu designer program. These really helped me in figuring out how to make a menu.

Tutorial 1: http://www.easyuo.com/forum/viewtopic.php?t=1672&sid=2182fb338c924e519bdea1dd9309f242

Once you have an understanding, go to this next one and try this :)

Tutorial 2: http://www.easyuo.com/forum/viewtopic.php?f=9&t=8422

I also like to take scripts that have menus and play around with them to make adjustments and get a better understanding.

C2 and Guadah have written a lot of scripts with menu's and are a great source for understanding.

C2 Script Library: http://www.scriptuo.com/index.php?board=80.0

Guahdah's Alchemy Assistant: http://www.scriptuo.com/index.php?topic=8254.0

IMPORTANT!! I am in no means saying to use their menu's, just to look and see how they did things to help you craft your own!!

I found that menu's were actually fun once you got the hang of it and LordSid's menu designer is a great aid in setting it up. You can find it and how to use it on Tutorial 2 link.

Offline CrisisTopic starter

  • Global Moderator
  • *
  • *
  • Posts: 2998
  • Activity:
    3.2%
  • Reputation Power: 41
  • Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.
  • Gender: Male
  • Scripting well enough to break things!
  • Respect: +205
  • Referrals: 2
    • View Profile
Re: Anatomy of a crafting script - A learn while you script journey
« Reply #2 on: April 18, 2014, 05:51:29 AM »
0
Step 2: Startup

Once you have a menu in place, you need to have a start up so that the script knows what to do and where to start.

I plan on having my scripts flow as much as possible in the same order that the script moves. This makes it easier for me to set them up and hopefully makes it easier for others wanting to learn from my scripts or adjust them to fit their needs. I know that I get frustrated looking at some scripts because I have to hop all over the script looking for things that seem to placed in there randomly. I am also willing to concede that as I progress, I may find that it is near impossible to write a script in an easy to follow order.   :P

Here goes nothing! *dives in head first*

Code: [Select]
;===================================================================

sub setup
  menu delete scriptstatus
  Menu Font BGColor Black
  menu Font Color Lime
  menu text scriptstatus 95 100 Setting Up Script
  
  ;open backpack
  Finditem * C_ , #BackpackID
  event macro 8 7
  wait 10 #BackpackID
  contpos %backpackx %backpacky  ;This will be at the top of the script set for manual adjustments
  wait 20

  ; hiding option
  chooseskill Hidi
   finditem #charid
   if #skill >= 200 || #findtype notin AV_XU_OCB_NCB ;Human JOAT = 20 Hiding
      {
      display yesno Hide while training?$
      if #dispRes = yes
         set %ToHide yes
      if #dispRes = no
         set %ToHide no
      }
  wait 10
  
    ; locate/open resource secure
  str len %ResourceSecure
  if ( N/A notin %ResourceSecure ) && ( #strres > 0 )
  {
    finditem %ResourceSecure
    if #findkind <> -1
      goto _openres
  }
  _selres:
  display Ok Select your Resource Container.
  set #targcurs 1
  while #targcurs = 1
   wait 10
  set %ResourceSecure #ltargetid
  _openres:
  set #lobjectid %ResourceSecure
  event macro 17 0
   wait 10
  contpos %resourcex %resourcey  ;This will be at the top of the script set for manual adjustments
  
  ; locate/open storage secure
  str len %StorageSecure
  if ( N/A notin %StorageSecure ) && ( #strres > 0 )
  {
    finditem %StorageSecure
    if #findkind <> -1
      goto _openstore
  }
  _selstore:
  display Ok Select your Storage Container.
  set #targcurs 1
  while #targcurs = 1
    wait 10
  set %StorageSecure #ltargetid
  _openstore:
  set #lobjectid %StorageSecure
  event macro 17 0
  wait 10
  contpos %storex %storey  ;This will be at the top of the script set for manual adjustments

  ; locate trash barrel
   str len %Trashbarrel
  if ( N/A notin %Trashbarrel ) && ( #strres > 0 )
  {
    finditem %Trashbarrel
    if #findkind <> -1
      goto _openbar
  }
 _selbar:
  Display Ok Select the Trash Barrel.
  set #targcurs 1
  while #targcurs = 1
    wait 10
  set %Trashbarrel #ltargetID
    wait 10
  contpos %trashx %trashy  ;This will be at the top of the script set for manual adjustment

  set %initialized #true
return

;===================================================================

This is my beginning to set the containers, and hide. I looked at a lot of different codes to open containers and I made this quite a while ago. I do not remember or maybe I never knew what this one part meant and did and I am hoping someone can help me out with it. I know and understand all the other commands

Code: [Select]
 str len %ResourceSecure
  if ( N/A notin %ResourceSecure ) && ( #strres > 0 )

What does the str len do? Is it just telling the script that it is going to set that?

 if ( N/A notin %ResourceSecure ) does this say if there is no resource secure selcted?

&& ( #strres > 0 ) The && stands for OR correct and it says or the container is not found?

What else can you tell me about what I have? Is it good, bad, better way of doing it?



EDIT: I found that str len is to start a string and how long it will be http://wiki.easyuo.com/index.php?title=Str_(command)

I still don't quite understand that though on why it would be there for a setting and opening a secure or bag. The strres seems to help line up the string maybe?
« Last Edit: April 18, 2014, 05:59:33 AM by Crisis »

Offline freddy

  • Sr. Member
  • *
  • Posts: 271
  • Activity:
    0%
  • Reputation Power: 4
  • freddy has no influence.
  • Gender: Male
  • Respect: +37
  • Referrals: 1
    • View Profile
Re: Anatomy of a crafting script - A learn while you script journey
« Reply #3 on: April 18, 2014, 05:52:52 AM »
0
Step 1: Menu

A crafting script should really have a menu in my opinion. While you can just use the pause and the play button on easyuo itself, a menu makes it so much easier and quicker. I am not going to go into much detail for a menu at this moment but will link this great write up from the EUO website. There are 2 tutorials, once you understand the first then you can go onto the second which uses a menu designer program. These really helped me in figuring out how to make a menu.

Tutorial 1: http://www.easyuo.com/forum/viewtopic.php?t=1672&sid=2182fb338c924e519bdea1dd9309f242

Once you have an understanding, go to this next one and try this :)

Tutorial 2: http://www.easyuo.com/forum/viewtopic.php?f=9&t=8422

I also like to take scripts that have menus and play around with them to make adjustments and get a better understanding.

C2 and Guadah have written a lot of scripts with menu's and are a great source for understanding.

C2 Script Library: http://www.scriptuo.com/index.php?board=80.0

Guahdah's Alchemy Assistant: http://www.scriptuo.com/index.php?topic=8254.0

IMPORTANT!! I am in no means saying to use their menu's, just to look and see how they did things to help you craft your own!!

I found that menu's were actually fun once you got the hang of it and LordSid's menu designer is a great aid in setting it up. You can find it and how to use it on Tutorial 2 link.

IMO, the menu should be the last thing to worry about. Make a clear outline of what stats you want to keep track of and make sure you keep up with the variables. Menus look confusing, but they are very easy to integrate into a script.

When it comes to a craft script there are a few things you should know. You need the sub that controls the menus, waste disposal (like smelting with smithing, axe with carpentry, trash can, etc), resource management, skill tracking so the script knows when to advance to a higher lvl item, weight checks, tool tracker, and lots of other small details.

I posted a carpentry script awhile back ( http://www.scriptuo.com/index.php?topic=11230.msg96742#msg96742 ) you can check it out if you need to.

I like to keep my subs modular; basically all my craft scripts use the same code, there are just minor things that i have to edit or add.

Offline Tidus

  • Lazy
  • Administrator
  • *
  • *
  • Posts: 1291
  • Activity:
    0%
  • Reputation Power: 15
  • Tidus is working their way up.Tidus is working their way up.Tidus is working their way up.
  • Gender: Male
  • Mind Blown
  • Respect: +151
  • Referrals: 2
    • View Profile
    • Ultimate Apparel
Re: Anatomy of a crafting script - A learn while you script journey
« Reply #4 on: April 18, 2014, 06:59:11 AM »
0

Code: [Select]
 str len %ResourceSecure
  if ( N/A notin %ResourceSecure ) && ( #strres > 0 )

What does the str len do? Is it just telling the script that it is going to set that?

 if ( N/A notin %ResourceSecure ) does this say if there is no resource secure selcted?

&& ( #strres > 0 ) The && stands for OR correct and it says or the container is not found?

What else can you tell me about what I have? Is it good, bad, better way of doing it?



EDIT: I found that str len is to start a string and how long it will be http://wiki.easyuo.com/index.php?title=Str_(command)

I still don't quite understand that though on why it would be there for a setting and opening a secure or bag. The strres seems to help line up the string maybe?


You need to look at this.  http://wiki.easyuo.com/index.php?title=StrRes   Str Len means string length.
For those who have fought for it, freedom has a taste the protected will never know ~ Anonymous, Vietnam, 1968

Offline 12TimesOver

  • Another Day, Another Vendetta
  • Global Moderator
  • *
  • *
  • Posts: 3694
  • Activity:
    0%
  • Reputation Power: 41
  • 12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.
  • Gender: Male
  • Respect: +321
  • Referrals: 2
    • View Profile
Re: Anatomy of a crafting script - A learn while you script journey
« Reply #5 on: April 18, 2014, 10:13:16 AM »
0
IMO, the menu should be the last thing to worry about. Make a clear outline of what stats you want to keep track of and make sure you keep up with the variables. Menus look confusing, but they are very easy to integrate into a script.

When it comes to a craft script there are a few things you should know. You need the sub that controls the menus, waste disposal (like smelting with smithing, axe with carpentry, trash can, etc), resource management, skill tracking so the script knows when to advance to a higher lvl item, weight checks, tool tracker, and lots of other small details.

I posted a carpentry script awhile back ( http://www.scriptuo.com/index.php?topic=11230.msg96742#msg96742 ) you can check it out if you need to.

I like to keep my subs modular; basically all my craft scripts use the same code, there are just minor things that i have to edit or add.
THIS. All of it :)
When they come for me I'll be sitting at my desk
     with a gun in my hand wearing a bulletproof vest
My, my, my how the time does fly
     when you know you're gonna die by the end of the night

Offline CrisisTopic starter

  • Global Moderator
  • *
  • *
  • Posts: 2998
  • Activity:
    3.2%
  • Reputation Power: 41
  • Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.
  • Gender: Male
  • Scripting well enough to break things!
  • Respect: +205
  • Referrals: 2
    • View Profile
Re: Anatomy of a crafting script - A learn while you script journey
« Reply #6 on: June 23, 2014, 08:07:05 PM »
0
Time always has a way of getting away from me. I am going to pick up where I left off. I will now wait for the menu until after making the script and then fit it in so that I don't miss anything that I may want to add into it.

Basically I need to plan out my script and in what order I want to do it, correct?

1. Choose to hide Y or N
2. Set secures/garbage as needed
3. Clear bag of unwanted resources and left over crafting garbage (if not recyclable or chop-able)
4. Check for tinkertool (grab from secure/use tinkering skill if less than 2)
Begin Crafting Loop Here:
5. Check for carptool (grab from secure/use tinkering skill if none)
6. Check which item to make and check and grab appropriate resources if needed
7. Craft (click make last unless threshold met and making next item)
8. Check for weight or item quantity in backpack
9. Continue loop until goal skill level met

Does this cover it? Do I need to add anything or take anything away?
(I do know that I need to set the items to be made including offset clicks and the thresholds at which to switch from one item to another but I will cover that in the subs which is next.)


If this is okay then I start working on the subs.

opening/selecting resource/drop off/garbage containers:

Code: [Select]
; locate/open resource secure
  str len %ResourceSecure
  if ( N/A notin %ResourceSecure ) && ( #strres > 0 )
  {
    finditem %ResourceSecure
    if #findkind <> -1
      goto _openres
  }
  _selres:
  display Ok Select your Resource Container.
  set #targcurs 1
  while #targcurs = 1
    wait 5
  set %ResourceSecure #ltargetid
  _openres:
  set #lobjectid %ResourceSecure
  event macro 17 0
  wait 5
  contpos %resourcex %resourcey
  wait 5
  
  ; locate/open storage secure
  str len %StorageSecure
  if ( N/A notin %StorageSecure ) && ( #strres > 0 )
  {
    finditem %StorageSecure
    if #findkind <> -1
      goto _openstore
  }
  _selstore:
  display Ok Select your Storage Container.
  set #targcurs 1
  while #targcurs = 1
    wait 5
  set %StorageSecure #ltargetid
  _openstore:
  set #lobjectid %StorageSecure
  event macro 17 0
  wait 5
  contpos %storex %storey
  wait 5

 ; locate/open Trash Barrel
  str len %TrashBarrel
  if ( N/A notin %TrashBarrel ) && ( #strres > 0 )
  {
    finditem %TrashBarrel
    if #findkind <> -1
      goto _opentrash
  }
  _seltrash
  Display Ok Select the trash barrel.
  set #targcurs 1
  while #targcurs = 1
    wait 5
  set %TrashBarrel #ltargetID
_opentrash:
  set #lobjectid %TrashBarrel
  event macro 17 0
  wait 5
  contpos %storex %storey
  wait 5

Now that I have had time to really look at the code for this:
Code: [Select]
str len %ResourceSecure
  if ( N/A notin %ResourceSecure ) && ( #strres > 0 )

I think it is telling the script to look and see if the itemid has been listed such as set %Resource Secure ABCDEF, if it finds it then it will open it, if not it tells the script to have the user select it, right?

« Last Edit: June 23, 2014, 08:12:05 PM by Crisis »

Offline The Ghost

  • Elite
  • *
  • *
  • Posts: 1917
  • Activity:
    0%
  • Reputation Power: 25
  • The Ghost is on the verge of being accepted.The Ghost is on the verge of being accepted.The Ghost is on the verge of being accepted.The Ghost is on the verge of being accepted.The Ghost is on the verge of being accepted.
  • Respect: +245
  • Referrals: 0
    • View Profile
Re: Anatomy of a crafting script - A learn while you script journey
« Reply #7 on: November 18, 2014, 07:27:02 PM »
0
So Crisis   What next , been a while since you put ur thoughts into paper. 

Tags: