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

0 Members and 1 Guest are viewing this topic.

Offline CrisisTopic starter

  • Global Moderator
  • *
  • *
  • Posts: 3014
  • Activity:
    4.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: +206
  • Referrals: 2
    • View Profile
Okay so I am going to start this over. It has been a long time and I started out differently then I want to this time so rather than try to get people to ignore the beginning and work their way down, I am going to start fresh.

Step one for making a script:

Okay so looking at this from a purely noob and beginning aspect, we need to figure out what we are going to have the script  do. Then we need to figure out basic subs we may need to have in place. Now as I have learned with other scripts I have worked on with the help of others, there is always something that you have overlooked or though that you wouldn't need so the sub list will be very fluid so it can be changed.

Script: I want to train tinkering

Subs I will need (not in any specific order right now):

1.  Setup
2.  Check tools
3.  Check resources
3.  Find and set secures and possibly trashcan
4.  Move resources from secure
5.  Move items to secure
6.  Move items to trashcan
7.  Gump wait
8.  Crafting
9.  Menu
10. Make tinker tools
12. Training list of items to make and what skill to make them
13, Skill check sub

I am sure there are others that I may have missed off the bat plus there will need to be some for a menu if you want the menu to keep track of time and gains and what not.

Offline CrisisTopic starter

  • Global Moderator
  • *
  • *
  • Posts: 3014
  • Activity:
    4.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: +206
  • Referrals: 2
    • View Profile
Re: Anatomy of a crafting script Reloaded- A learn while you script journey
« Reply #1 on: January 04, 2015, 12:12:34 PM »
0
Script: I want to train tinkering

Subs I will need (not in any specific order right now):

1.  Setup
2.  Check tools
3.  Check resources
3.  Find and set secures and possibly trashcan
4.  Move resources from secure
5.  Move items to secure
6.  Move items to trashcan
7.  Gump wait
8.  Crafting
9.  Menu
10. Make tinker tools
12. Training list of items to make and what skill to make them
13, Skill check sub

Lets look at some of the subs:

Code: [Select]
sub ClearPackIngots
  finditem %ingots C_ , #backpackid
  if #findcnt < 1
    return
  for #findindex 1 #findcnt
  {
    exevent drag #findid #findstack
    wait 20
    exevent dropc %ResourceSecure
    wait 20
  }
return

This one checks in the character backpack for ingots "finditem %ingots C_ , #backpackid" and then if it can't locate any ingots the sub is done "if #findcnt < 1" If it finds ingots it moves them to the resource secure. "exevent drag #findid #findstack  exevent dropc %ResourceSecure"

Code: [Select]
sub ClearPackNotGarbage

  finditem %notgarbage C_ , #backpackid
  if #findcnt < 0
     return
  for #findindex 1 #findcnt
  {
    exevent drag #findid #findstack
    wait 20
    exevent dropc %StorageSecure
    wait 20
  }
return

This one works similarly, in your setup you will identify which items you may want to keep such as lockpicks and they will be in a list something like this "set %notgarbage NWH" If it does not find any it will move on, if it finds them then it drop them in the StorageSecure for safe keeping.

Code: [Select]
sub ClearPackGarbage
  _cleargarbageloop:
  {
  finditem %garbage C_ , #backpackid
  if #findcnt > 0
  }
  for %ItemToDump 1 #findcnt
  {
    Set #FindIndex %ItemToDump
    exevent drag #findid #findstack
    wait 20
    exevent dropc %trashbarrel
    wait 20
  }
return

This one looks for items predefined as garbage that would look something like this "set %garbage NQD_OBG_IJG_UJG_ZVH_CWH" If it does not find anything, then it moves on, if it does, then it sumps then on the trashbarrel.

Like I said earlier, sometimes when making a list you over look things and I overlooked these little babies. These same subs can be used at the beginning of the script and then while the script is going. I want the script to do these checks at the beginning so it clears the bag of any unwanted items. You could just skip it and have it do it later when you are getting overweight but it is up to you.
« Last Edit: January 04, 2015, 12:14:32 PM by Crisis »

Offline CrisisTopic starter

  • Global Moderator
  • *
  • *
  • Posts: 3014
  • Activity:
    4.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: +206
  • Referrals: 2
    • View Profile
Re: Anatomy of a crafting script Reloaded- A learn while you script journey
« Reply #2 on: January 04, 2015, 12:32:10 PM »
0
Script: I want to train tinkering

Subs I will need (not in any specific order right now):

1.  Setup
2.  Check tools
3.  Check resources
3.  Find and set secures and possibly trashcan
4.  Move resources from secure
5.  Move items to secure
6.  Move items to trashcan
7.  Gump wait
8.  Crafting
9.  Menu
10. Make tinker tools
12. Training list of items to make and what skill to make them
13, Skill check sub

Gump wait is another one I want to look at and you definitely need.


Code: [Select]
;#######################
;SUB XIIxGumpWait
;#######################
; %1 = Required: Gumpname 1
; %2 = Required only if using Gumpsize: Gumpname 2
; %3 = Optional: Gumpsize
; Returns #TRUE if gump occured before timeout, #FALSE if timeout occured
sub XIIxGumpWait
   namespace push
   namespace local nsXIIxGumpWait
   wait 10
   set !gName1 %1
   set !gName2 %2
   set !gSize %3
   set !_time #SCNT
   while #SCNT <= !_time + 5
      {
      if %0 > 2
         {
         if ( #CONTNAME = !gName1 && #CONTSIZE = !gSize ) || ( #CONTNAME = !gName2 && #CONTSIZE = !gSize )
            {
            namespace pop
            return #TRUE
            }
         }
      else
         {
         if #CONTNAME = !gName1 || #CONTNAME = !gName2
            {
            namespace pop
            return #TRUE
            }
         }
      }
   namespace pop
return #FALSE

This is 12TimesOver's gump wait which he is allowing me to use. Many author's will share some of their basic subs, just make sure to note it in your script. I also leave any headers or anything that they have in place as well.

I am still learning about gump waits and 12X did a great job explaining it for me in another post:

A basic gump wait sub needs to follow some basic gump wait logic:

Code: [Select]
sub gumpwait
   1) tell me what gump to wait for via name and/or size
   2) set an amount of time to keep looking for the gump before deciding it ain't comin'
   3) keep looking for that gump until it either shows up or the amount of time has expired
   4) tell the rest of the script what happened
return

This is all my example sub above is doing.

Code: [Select]
;#######################
;SUB XIIxGumpWait
;#######################
; %1 = Required: Gumpname 1
; %2 = Required only if using Gumpsize: Gumpname 2
; %3 = Optional: Gumpsize
; Returns #TRUE if gump occured before timeout, #FALSE if timeout occured
sub XIIxGumpWait
   namespace push
   namespace local nsXIIxGumpWait
This is creating the sub and giving it a namespace so that none of it's variables will conflict with the rest of the variables in the script that's calling it

Code: [Select]
   set !gName1 %1
   set !gName2 %2
   set !gSize %3
   1) tell me what gump to wait for via name and/or size

Code: [Select]
   set !_time #SCNT
   while #SCNT <= !_time + 5
   2) set an amount of time to keep looking for the gump before deciding it ain't comin'

Code: [Select]
   while #SCNT <= !_time + 5
      {
      if %0 > 2
         {
         if ( #CONTNAME = !gName1 && #CONTSIZE = !gSize ) || ( #CONTNAME = !gName2 && #CONTSIZE = !gSize )
            {
            namespace clear
            namespace pop
            return #TRUE
            }
         }
      else
         {
         if #CONTNAME = !gName1 || #CONTNAME = !gName2
            {
            namespace clear
            namespace pop
            return #TRUE
            }
         }
      }
   3) keep looking for that gump until it either shows up or the amount of time has expired
   4) tell the rest of the script that it did come up

Code: [Select]
   namespace clear
   namespace pop
Cleanup my namespace

Code: [Select]
return #FALSE   4) tell the rest of the script that it DID NOT come up

Offline CrisisTopic starter

  • Global Moderator
  • *
  • *
  • Posts: 3014
  • Activity:
    4.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: +206
  • Referrals: 2
    • View Profile
Re: Anatomy of a crafting script Reloaded- A learn while you script journey
« Reply #3 on: January 04, 2015, 01:03:40 PM »
0
Script: I want to train tinkering

Subs I will need (not in any specific order right now):

1.  Setup
2.  Check tools
3.  Check resources
3.  Find and set secures and possibly trashcan
4.  Move resources from secure
5.  Move items to secure
6.  Move items to trashcan
7.  Gump wait
8.  Crafting
9.  Menu
10. Make tinker tools
12. Training list of items to make and what skill to make them
13, Skill check sub

Lets move onto the the check tools and craft tools subs:

Code: [Select]
sub CheckTinkerTools
  finditem %tinkertool C_ , #backpackid
  if #findcnt < 3
    gosub MakeTinkerTools
return

This one is super simple. It looks for tinkertools in your backpack " finditem %tinkertool C_ , #backpackid"  If it cannot find any or the count is less than 3, it will go to the MakeTinkerTools Sub.

Code: [Select]
sub MakeTinkerTools
  finditem %ingots C_ , #backpackid
  if #findstack >= 25
     goto _maketink
  set %_diff 25 - #findstack
  finditem %ingots C_ , %ResourceSecure
  if #findstack < 25
  {
    display You have used up most of your ingots. Halting...
    set *request END
  }
  gosub moveit #backpackid %ResourceSecure #findid %_diff

  _maketink:
  finditem %tinkertool C_ , #backpackid
  if #FindCnt = 0
  {
    display You are out of tinker tools. Get a tinker tool and restart script.
    set *request END
    halt
  }
  set #lobjectID #findid
  event macro 17 0
  gosub XIIxGumpWait
  gosub offsetclick 27 130  ; tools
  wait 20
  gosub XIIxGumpWait
  gosub offsetclick 230 130 ; tinker's tools
  wait 20
  gosub XIIxGumpWait
  gosub offsetclick 280 450   ; make last
  wait 20
  gosub gumpwait
  gosub offsetclick 280 450   ; make last
  wait 20
  gosub XIIxGumpWait
  gosub offsetclick 280 450   ; make last
  wait 20
  gosub XIIxGumpWait
  gosub offsetclick 30 450  ; exit
  wait 20
  gosub XIIxGumpWait
return

Now here is where I can use really use some help. Should the Make tools be set up like this or should I have it set up differently. I am looking for something quick but efficient. Am I using the gump wait properly? I will stop here and let some people respond to what I have posted before continuing.

Offline CrisisTopic starter

  • Global Moderator
  • *
  • *
  • Posts: 3014
  • Activity:
    4.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: +206
  • Referrals: 2
    • View Profile
Re: Anatomy of a crafting script Reloaded- A learn while you script journey
« Reply #4 on: January 31, 2015, 04:34:16 AM »
0
I could use some help here, this is a learning journey for me and hopefully others can learn from my successes and mistakes. I am going to have questions as I go and I am hoping others can give me input on mistakes that I make or ways to improve on what I have. I believe that I am on the brink between guessing through trial and error and understanding what I am doing.

Looking at the create tinker tools, is there a better way to do that? I have it set to craft one tool and then to click make last 3 more times. Did I use the gump wait correctly and does the timing okay? I want to make sure that this is good before going on to the next part.  8)

Offline manwinc

  • Elite
  • *
  • *
  • Posts: 2556
  • Activity:
    0%
  • Reputation Power: 32
  • manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!
  • Gender: Male
  • "The Devs Hard at Work"
  • Respect: +123
  • Referrals: 1
    • View Profile
Re: Anatomy of a crafting script Reloaded- A learn while you script journey
« Reply #5 on: January 31, 2015, 10:20:18 PM »
0
You are going to want to Incorporate some sort of "Wait for Gump Sub"

An example of what I use is Gosub ContTimer. Its a sub that you enter and it just loops a Check that waits for a # Variable in EUO to  be Equal to a specific Value. You can Set a Timeout Value for it as well (I usually do a max of 3s in case of extreme lag) but usually it will let you know as soon as the gump is available to be handled.

Think of it like the Target Command

Target 40 (Waits a max of 2s for a target cursor to appear)

But For # Variables

The Sub WOrks like This

Gosub Cont_Timer ( Max Time for it to scan, 10 = 1s) ( # Variable - the # ) ( Value You are waiting for it to be )

So an Example of how to use this for opening your backpack. This comes in a lot of handy because you can base your Object timers off when the action actually happens.


set %Start #Systime
set #lobjectid #Backpackid
Event Macro 17 0
Gosub Cont_Timer 30 Contid #Backpackid
set %End #Systime - %Start
Display Your Backpack is Ready in %End ms
Halt

Code: [Select]
Sub Cont_Timer
; Gosub Cont_Timer (Timer) ( Var ) ( Value )
Namespace Push
Namespace Local Mwinc_Cont_Timer
set !Lpc #Lpc
set #lpc 9999 ; Can be slowed down Depending on how many you are running
set !Time_Limit #scnt2 + %1
set !Cont_Check # . %2
While !Cont_Check <> %3 && !Time_Limit > #scnt2
{
set !Cont_Check # . %2

wait 1
}
if !Time_Limit <= #scnt2
set #Result #True
Else
set #Result #False
set #Lpc !Lpc
Namespace Pop
Return #Result
« Last Edit: January 31, 2015, 10:22:57 PM by manwinc »
Monkeys and Typewriters!

" Oh I know, We'll make a Boss Encounter that requires 3 keys per player to enter, Then we'll make it not a closed instance so you never know if you are going to pop into a fresh room or a boss that has 1% Health left with 20 dudes smashing its face in, wasting your time and effort"

Offline manwinc

  • Elite
  • *
  • *
  • Posts: 2556
  • Activity:
    0%
  • Reputation Power: 32
  • manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!
  • Gender: Male
  • "The Devs Hard at Work"
  • Respect: +123
  • Referrals: 1
    • View Profile
Re: Anatomy of a crafting script Reloaded- A learn while you script journey
« Reply #6 on: January 31, 2015, 10:25:24 PM »
0
Oh, ha, yeah you already posted 12x's version. yes, definitely Something to look into. Going to be necessary if you want to successfully write a crafting script or else it will just be slow and glitchy.
Monkeys and Typewriters!

" Oh I know, We'll make a Boss Encounter that requires 3 keys per player to enter, Then we'll make it not a closed instance so you never know if you are going to pop into a fresh room or a boss that has 1% Health left with 20 dudes smashing its face in, wasting your time and effort"

Tags: