khi Tradeskills - Tradeskills Macro with Ini File Support

Post your completed (working) macros here. Only for macros using MQ2Data syntax!

Moderator: MacroQuest Developers

User avatar
Pax
a lesser mummy
a lesser mummy
Posts: 52
Joined: Fri Dec 19, 2003 11:04 am
Location: Denmark

if / when it hangs

Post by Pax » Sun Jun 13, 2004 7:15 am

if it hangs after 1st combine and tries to do a new combine without components just comment out this section and it should work again

Code: Select all

        |/if (!${bCombineDone}) {
        |    /goto :DoCombineLoop
        |}
 
Kaitain thanks for a wonderful macro :)
//Fuck waiting for us to cleanly exit... we're being unloaded!

Falco
orc pawn
orc pawn
Posts: 23
Joined: Fri Sep 26, 2003 5:25 am

as for inventory

Post by Falco » Sun Jun 13, 2004 2:22 pm

here's the responce i get for an inventory combine

[code] [MQ2]khiTS: Reading parameters
[MQ2]khiTS: Opening inventory containers
Usage: /windowstate <window> [open|close]
[MQ2]khiTS: Cleaning out pack: NULL
[MQ2]"Cleaning out NULL"
[MQ2]Pack is Empty
[MQ2]khiTS error: Unable to clean out pack (NULL)
The current macro has ended.
[/code]

thats it, and nomatter what inventory container i use i get the same responce, works well with enviromental combines though

i am running the latest MQ2 and the most recent working version(that i've found) of khits, thnx again for the great macro

NBarnes
orc pawn
orc pawn
Posts: 19
Joined: Wed Jan 28, 2004 10:46 pm

Post by NBarnes » Sun Jun 13, 2004 9:14 pm

Thanks, Pax. The macro is working fine now (with the exception of the stat collecting, which doesn't seem to be noticing successes correctly, but I haven't looked to see if the part you had me comment out is the cause of that, and in any case it's not critical to the macro's basic functionality).

Falco
orc pawn
orc pawn
Posts: 23
Joined: Fri Sep 26, 2003 5:25 am

Post by Falco » Mon Jun 14, 2004 3:17 am

so am i the only one that it doesnt work on inventory combines for?



/tap tap tap, this thing on?
Last edited by Falco on Tue Jun 15, 2004 3:22 am, edited 1 time in total.

User avatar
Pax
a lesser mummy
a lesser mummy
Posts: 52
Joined: Fri Dec 19, 2003 11:04 am
Location: Denmark

Post by Pax » Mon Jun 14, 2004 6:32 am

to get the stat collection to work try this

Code: Select all

#event SkillTrivial "#*#You can no longer advance your skill from making this item#*#"
#event SkillUp "#*#You have become better at#*#"
#event SkillFailure "#*#You lacked the skills#*#"
#event SkillSuccess "#*#You have fashioned the items together to create something new#*#"
#event FullInventory "#*#There was no place to put that#*#"
#event CombineError "#*#You cannot combine these items in this container type!#*#"
#chat tell
//Fuck waiting for us to cleanly exit... we're being unloaded!

Falco
orc pawn
orc pawn
Posts: 23
Joined: Fri Sep 26, 2003 5:25 am

Post by Falco » Thu Jun 17, 2004 5:57 am

my issue is this, when i use this recipe

Code: Select all

[sswatch]
Cont=Collapsable Sewing Kit
Comp0=Spider Silk
Comp1=Spider Silk
i recieve the error Null(as posted before) is anyone else having this error? or is god being a mean kid sitting on an ant hill again...

Avanos
orc pawn
orc pawn
Posts: 14
Joined: Thu Jun 17, 2004 11:18 am

Post by Avanos » Tue Jun 22, 2004 1:28 am

Cont=Collapsable Sewing Kit
Might be the spelling error. It's spelled Collapsible.

exslam
orc pawn
orc pawn
Posts: 14
Joined: Wed Jun 23, 2004 6:19 am

Post by exslam » Wed Jun 23, 2004 6:30 am

I'm having some success with this.
1. It will run from 1-xx amount of times and then it just ends. no error or anything just stops like everything is fine...

Some things, it will succeed 1 time, then the second time it will populate the container pause a second then repopulate it it tries to loop but the container fills up and it restarts and continue on...

Has anyone had any problems with it looping while moving the components ?

Sorry for this post, tried to fix it myself but my coding skill is lacking..


Also i noticed.. if your components are not in a bag(in your main inventory) the macro wont see them... not asking for a fix or anything just pointing that out...

Slam

kellewic
a lesser mummy
a lesser mummy
Posts: 38
Joined: Tue Jun 08, 2004 2:27 am
Location: AZ

Post by kellewic » Mon Jun 28, 2004 1:51 am

NOTE: This is the include version of the macro code

First off, this is a great macro. Got my brewing up to 200 without major clicking pains. I did, however, find several bugs while doing this so I am posting the macro again with these fixes. There were so many minor and a few major fixes that I can't remember them all, but some are:

1- The macro would not read in any parameters passed the first one, so I re-wrote the parseArguments sub to read all parameters and not be dependant on the '=' sign with 1 digit afterwards like it was. So now all parameters work to include the 'make-this-many' and 'silent-mode' options.

2 - I added 2 new options:

a. stop-at-skill-level=### -- the macro will stop when you hit the desired skill level (i.e. 200). Defaults to 0 (no limit)

b. debug=1|0 -- Outputs useful information when changing the macro code, defaults to 0. This also sets silentMode=0.

This now works:

/macro my.mac RECIPE destroy-results=1 stop-at-skill-level=200 make-this-many=31 etc

3- Fixed errors in options in the help display as I found them

4- The destroy-results code was barfing due to bad variables so it is fixed now.

5- I removed most explicit casts that were useless. For example casting a string to a string via String[${stringVar}], explicit casting of BOOLs when used in a bool context (i.e. withing /if blocks) and casting of Ints to Strings for compares when they can simply be compared as Ints.

6- Made cleanPack a little faster by skipping empty slots so it won't try to clean out slots with nothing in them

7- All output should now be consistent in that it is prefixed with 'khiTS' so you can easily tell which output is coming from this code.

8- Removed AddComp() since it was only called once and just placed the code within addComonents since the single sub call seemed useless.

9- All but 3 delays have been removed. One delay is right after the combine and is the one you have to tweak. One delay is for the call to clearCursor() and the other is only hit once in Event_SkillSuccess to determine what it is you just made.

10- Added a new event to check for the "hands full" message and endmacro if it is seen.

In my tests this version runs about 35% faster than the previous one. The previous version (making Short Beer 80 times) took, on average, 3 seconds per combine. This version takes 2 seconds per combine and I think that is throttled at the server level since I tested manual combines and I could only combine once every 2 seconds.

I haven't had the chance to use this on inventory containers, so none of that code has been looked at or touched in any way.


Code: Select all

|**

    khiTS.mac

    Author:     Kaitain Heavy Industries
    Date:       30 Apr 04
    Version:    2.2.2.14

    Description:
    Performs tradeskill combines using recipes supplied in an ini file

    Credits:
    Inspired by Dont_Know_At_All's Trade Skills macro - The status report idea is completely stolen from him (but rewritten by me)
    Ini file uses the format created by Diggler (this will eventually being changed to a new format using item id's)

    Notes:
    * Updated to use MQ2DataVars
    * This is a complete overhaul of the whole macro in addition changing it to work with MQ2Data and MQ2DataVars
    * You should be able to simply rename "sub main" to "sub khiTS" if you want to use this as an included file.
    * No longer destroys tools or components used to do combines when destroy-results is enabled.
    * This is a BIG macro and may be slow as hell on older computers.

   Usage:
   #include khits.inc
   .
   .
   .
   /call Make  <recipe_name> <options>

   Example:
   /call Make khits bits "show-stats=0 destroy=0 abort-on-tell=0 end-on-trivial=0 silent-mode=0 stop-at-skill-level=200"
   Ported to Inc by Draco
**|

| ***** Tweak this to your computer, if you get a lot of an item in the combine container, increase this number ***** |
#define COMBINE_DELAY 3

| ***** CHANGE THIS TO MATCH YOUR INI FILE NAME IF NECESSARY ***** |
#define INIPATH "recipes.ini"


#event SkillTrivial "You can no longer advance your skill from making this item#*#"
#event SkillUp "You have become better at #1#! (#2#)"
#event SkillFailure "You lacked the skills#*#"
#event SkillSuccess "You have fashioned the items together to create something new#*#"
#event FullInventory "There was no place to put that#*#"
#event CombineError "You cannot combine these items in this container type!"
#event HandsFull	"You cannot combine items when your hands are full#*#"

#chat tell

#define COMBINE_SUCCESS			0
#define COMBINE_FAILED			1
#define COMBINE_ERROR			2
#define COMBINE_INVENTORY_FULL	3
#define COMBINE_TRIVIAL			4


| Main entry point
sub Make
    /echo
    /echo
    /echo *****************************************
    /echo khiTs: Tradeskills running : ${Time}
    /echo *****************************************
    /echo


    | Check for no parameters or help
    /if (!${Defined[Param0]} || ${Param0.Equal[HELP]}) {
        /call displayHelp
        /call clearCursor ${iDestroyResults}
        /endmacro
    }


    | The name of the combination being done, this is used to look up the recipe in the recipe.ini file
    /declare recipeName         string  local   NOT_SET
    
    | container in which the recipe will be made
    /declare containerName      string  local   NOT_SET
    
    | Loop variable, which component we are getting the name of
    /declare iCompLoop          int     local   1
    
    | The name of the current component we're getting
    /declare currentComp        string  local   NOT_SET
    
    | Make sure we have that recipe in the ini file
    /declare recipeCheck        string  local   NOT_SET

    | Settings (see end of this file for list of settings)
    | Stops the macro if someone sends you a tell
    /declare abortOnTell        int     local   0
    
    | How many itmes the user has requested be made
    /declare makeThisMany       int     local   0
    
    | Display when you succed, get skillups, fail, etc.
    /declare showStats          int     local   0

    | For looping through containers
    /declare slotNumber         int     local   1
    

   | Exit and Return Flags added by Draco
   /declare combineResult int outer 0
   /declare cleanUpAndExit int outer 0
   /declare combineErrorCounter int outer 0

    | Only declare outer variables once, this is in case you use this as an include    
	/if (!${Defined[components]}) {
        | Array of components used to make the recipe
        /declare components[10]     string  outer
        /declare activeSlots[10]	string	outer
        /declare compSlots[10]		string	outer
        
        | Container in which the recipe will be made
        /declare containerNum       string  outer   NOT_SET
        
        | The number of components in this recipe
        /declare iCompCount         int     outer   0

        | Flags
        /declare bCombineDone       bool    outer   FALSE
        /declare bSkillTrivial      bool    outer   FALSE

        | Destroys the results of a combine (but not any items used in the combine)
        /declare iDestroyResults     int     outer   0

        | Stops the macro when you can no longer get skillups from doing the combine
        /declare iEndOnTrivial       int     outer   0

        | How many times you've tried a combination
        /declare iSkillAttempts      int     outer   0
        
        | How many times it worked
        /declare iSkillSuccess       int     outer   0
        
        | How many times it didn't work
        /declare iSkillFailure       int     outer   0
        
        | How many skill points you have received
        /declare iSkillUps           int     outer   0
        
        | Skill level to stop at
        /declare iStopAtSkillLevel	 int 	 outer	 0

    	| Keeps MQ window spam to a minimum
    	/declare silentMode          int     outer   0
    	
    	| Output debugging information
    	/declare debug				 int	outer	 0
        
        | The results of what we are making
        /declare sResults           string  outer   NOT_SET
        
        | Skill we are using (i.e. Brewing, Smithing, etc)
        /declare sUsing				string	outer	NOT_SET
    } else {
        | Clean out the last components used, this is in case we have not cleared the variables or are using this as an include
        /deletevar components
        /deletevar activeSlots
        /deletevar compSlots
        /declare components[10]
        /declare activeSlots[10]
        /declare compSlots[10]
    }


    |Get requested recipe's name
    /varset recipeName ${Param0}

    | If there is only one parameter, then there are no options
    /if (${Defined[Param1]}) {
	    /declare tmp int local
	    /declare parms int local ${Macro.Params}
	    /declare parmString string local
	    /varcalc parms ${parms}-1
	    
		/for tmp 1 to ${parms}
			/varset parmString ${parmString} ${Param${tmp}}
		/next tmp
		
        /call parseArguments "abort-on-tell" "${parmString}"
        /varset abortOnTell ${Macro.Return}

        /call parseArguments "destroy-results" "${parmString}"
        /varset iDestroyResults ${Macro.Return}

        /call parseArguments "end-on-trivial" "${parmString}"
        /varset iEndOnTrivial ${Macro.Return}

        /call parseArguments "make-this-many" "${parmString}"
        /varset makeThisMany ${Macro.Return}

        /call parseArguments "show-stats" "${parmString}"
        /varset showStats ${Macro.Return}

        /call parseArguments "stop-at-skill-level" "${parmString}"
        /varset iStopAtSkillLevel ${Macro.Return}
        
        /call parseArguments "debug" "${parmString}"
        /varset debug ${Macro.Return}

        /if (!${debug}) {
        	/call parseArguments "silent-mode" "${parmString}"
        	/varset silentMode ${Macro.Return}
    	} else {
	    	/echo ***** DEBUGGING ON *****
    	}
    }

    | Make sure the recipe file exists (the recipes thing is a fix for a bug in the Ini function)
    /varset recipeCheck ${Ini[INIPATH,recipes]}
    /if (${recipeCheck.Equal[NULL]}) {
        /echo khiTS Error: Recipe file not found
        /echo Path = INIPATH
        /goto :khiTSreset
    }

    | Make sure this recipe exists in the recipe.ini file
    /varset recipeCheck ${Ini[INIPATH,${recipeName}]}
    /if (${recipeCheck.Equal[NULL]}) {
        /echo khiTS Error: Recipe not found
        /echo Recipe name = ${recipeName}
        /goto :khiTSreset
    }

    | Get the container name
    /varset containerName ${Ini[INIPATH,${recipeName},Cont]}
    /if (${containerName.Equal[NULL]}) {
        /echo khiTS Error: Error in ini file for this recipe, no container is specified
        /echo khiTS      : Recipe = ${RecipeName}
        /goto :khiTSreset
    }

    | Find the combine container number
    /if (${containerName.Equal[Enviro]}) {
        /if (!${Window[Enviro].Open}) {
            /echo khiTS Error: You must have the enviromental container open to begin
            /goto :khiTSreset
        }
        /varset containerNum e
    } else {
        | Not an enviromental container so find the container's pack number, this is how we will refer to it from now on
        /varset containerNum ${FindItem[=${containerName}].InvSlot.ID}
        /if (${containerNum}) {
            /varcalc containerNum ${containerNum}-21
            /varset containerNum ${containerNum.Arg[0,.]}
        } else {
            | Didn't find the container
            /echo khiTS Error: Could not find container in your inventory
            /echo khiTS      : Contanier name = ${containerName}
            /goto :khiTSreset
        }
    }
    
    
    | Read the ingredients for the recipe from the ini file
    /varset iCompLoop 0            
            
    :khiTSReadComponentsLoop
    /varset currentComp ${Ini[INIPATH,${recipeName},Comp${iCompLoop}]} 
	/if (${currentComp.NotEqual[NULL]}) {
        /varcalc iCompLoop ${iCompLoop}+1
        /varset components[${iCompLoop}] ${currentComp}
        
        | *** STORE SLOTS FOR EACH COMPONENT FOR QUICK LOOKUPS *** |
        /call FindSlotsForComp "${currentComp}" ${iCompLoop}
        
        | Couldn't find the item
        /if (!${activeSlots[${iCompLoop}]}) {
	        /echo khiTS Error: ***** You do not have any ${currentComp} *****
	        /goto :khiTSCleanUpMacro
        }
        
        /goto :khiTSReadComponentsLoop
    }
    /varset iCompCount ${iCompLoop}

    /if (!${silentMode})	/echo khiTS: Opening containers
    | Open all packs if they aren't already - you have to handle arranging them and you have to have "use ctrl-r-click" set properly - for now
    /for slotNumber 1 to 8
    	/if (!${Window[Pack${slotNumber}].Open}) {
            /itemnotify pack${slotNumber} rightmouseup
        }
    /next slotNumber

    | Remove anything from the cursor if needed
    /call clearCursor ${iDestroyResults}

    | Clear the combine pack
    /call cleanPack ${containerNum}
    /if (${cleanUpAndExit})	/goto :khiTSreset

	| Let's just do this here rather than through every iteration of combines
	/declare COMBINE_STRING string local
    /if (${containerNum.Equal[e]}) {
        /varset COMBINE_STRING enviro
    } else {
        /varset COMBINE_STRING pack${containerNum}
    }
    
    
    :khiTSCombineLoop
        | Delete or Save items depending on settings
        /call clearCursor ${iDestroyResults}

        /if (${sResults.Equal[NOT_SET]}) {
        	/echo khiTS: Making ${recipeName}
        } else {
            /echo khiTS: Making ${sResults} - Count = ${iSkillSuccess}
        }

        | Move ingredients to container
        /call addComponents
        /if (${cleanUpAndExit})	/goto :khiTSCleanUpMacro

        | Combine
        /varset bCombineDone FALSE
        /varcalc iSkillAttempts ${iSkillAttempts}+1
        
        :DoCombineLoop
        /combine ${COMBINE_STRING}

        | Need this delay here to make sure the combine is finished
        /delay COMBINE_DELAY

        | Call these events individually so they do not conflict with a parent macro if this macro is used as an included file
        /doevents SkillTrivial
        /doevents SkillUp
        /doevents SkillFailure
        /doevents SkillSuccess
        /doevents CombineError
        /doevents FullInventory
        /doevents tell
        /doevents HandsFull
      
      	/if (${cleanUpAndExit})	/goto :khiTSCleanUpMacro
        /if (!${bCombineDone})	/goto :DoCombineLoop

        /varset combineErrorCounter 0

        | See if we have made enough
        /if (${makeThisMany} && ${makeThisMany} == ${iSkillSuccess})	/goto :khiTSCleanUpMacro

        /goto :khiTSCombineLoop

    | The macro is ending, clean up
    :khiTSCleanUpMacro
      | Delete or Save items depending on settings - Just in case
      /call clearCursor ${iDestroyResults}
      /call cleanPack ${containerNum}
      /call DisplayStats
      
    :khiTSreset
      /call resetKhits
/return ${combineResult}



Sub FindSlotsForComp(String comp, int compNum)
	/declare iPack int local
	/declare iSlot int local
	
	/if (!${silentMode})	/echo khiTs FindSlotsForComp: Looking in packs for component #${compNum}: ${comp}
	
	/for iPack 1 to 8
		| Don't look in the container we are using to do the combine
		/if (${String[${iPack}].NotEqual[${containerNum}]}) {
			| Is this item a container?
			/if (${Me.Inventory[Pack${iPack}].Container}) {
				| Loop through container slots
				/for iSlot 1 to ${Me.Inventory[Pack${iPack}].Container}
					| Does the item match what we are looking for?
					/if (${components[${compNum}].Equal[${Me.Inventory[Pack${iPack}].Item[${iSlot}].Name}]}) {
						| Set the current active slot if not set
						/if (!${activeSlots[${compNum}]}) {
							/varset activeSlots[${compNum}] ${Me.Inventory[Pack${iPack}].Item[${iSlot}].InvSlot.ID}
						} else {
							| Store reference to this slot so we can 'grab' it later on
							/if (${compSlots[${compNum}].Length}) {
								/varset compSlots[${compNum}] ${compSlots[${compNum}]}:${Me.Inventory[Pack${iPack}].Item[${iSlot}].InvSlot.ID}
							} else {
								/varset compSlots[${compNum}] ${Me.Inventory[Pack${iPack}].Item[${iSlot}].InvSlot.ID}
							}
						}
					}
				/next iSlot
			} else {
				| Account for items not in containers
				/if (${components[${compNum}].Equal[${Me.Inventory[21+${iPack}]}]}) {		
					| Set the current active slot if not set
					/if (!${activeSlots[${compNum}]}) {
						/varset activeSlots[${compNum}] ${Me.Inventory[Pack${iPack}].Item[${iSlot}].InvSlot.ID}
					} else {
						| Store reference to this slot so we can 'grab' it later on
						/if (${compSlots[${compNum}].Length}) {
							/varset compSlots[${compNum}] ${compSlots[${compNum}]}:${Me.Inventory[Pack${iPack}].Item[${iSlot}].InvSlot.ID}
						} else {
							/varset compSlots[${compNum}] ${Me.Inventory[Pack${iPack}].Item[${iSlot}].InvSlot.ID}
						}
					}
				}
			}
		}
	/next iPack
	
	/if (${debug}) {
		/echo khiTs FindSlotsForComp: -- Active Slot: ${activeSlots[${compNum}]}
		/echo khiTs FindSlotsForComp: -- Other Slots: ${compSlots[${compNum}]}
	}
/return



Sub resetKhits
   |It would be more efficient to just initialize the var
   |rather than delete and re-declare everytime. But today is a lazy day.

   /deletevar combineResult
   /deletevar cleanUpAndExit
   /deletevar combineErrorCounter
   /deletevar containerNum
   /deletevar iCompCount
   /deletevar bCombineDone
   /deletevar bSkillTrivial
   /deletevar iDestroyResults
   /deletevar iEndOnTrivial
   /deletevar iSkillAttempts
   /deletevar iSkillSuccess
   /deletevar iSkillFailure
   /deletevar iSkillUps
   /deletevar sResults
   /deletevar components
   /deletevar iStopAtSkillLevel
   /deletevar activeSlots
   /deletevar compSlots
/return



| Removes anything on the cursor. If DestroyResults is 1, then it will destroy anything not in the components array
sub clearCursor(int DestroyResults)
	/declare saveCount int local

    :khiTSClearCursorLoop
    /delay 2 ${Cursor.ID}

    | Is there anything on the cursor?
    /if (${Cursor.ID}) {
        /if (${DestroyResults}) {
            | Make sure the item on the cursor is not something we want to save
            /for saveCount 1 to 10
                /if (${components[${saveCount}].Equal[${Cursor.Name}]}) {
	                /if (!${silentMode})	/echo -- Saving ${components[${saveCount}]} to inventory
                    /autoinv
                    /goto :khiTSClearCursorLoop
                }
            /next saveCount

            | Whatever is on the cursor wasn't in the save list
            /if (!${silentMode})	/echo -- Destroying ${Cursor.Name}
            /destroy
        } else {
            /autoinv
        }

        /goto :khiTSClearCursorLoop
    }
/return


| ** CHECKED **|
| Finds the value of an argument in a parameter string
sub parseArguments(string sArgument,string sParameters)
    /declare iArgNum    int     local
    /declare sArgValue  string  local

    /for iArgNum 1 to ${sParameters.Count[=]}
    	/if (${sParameters.Arg[${iArgNum}, ].Left[${sArgument.Length}].Equal[${sArgument}]}) {
	    	/declare tmp int local ${sArgument.Length}
	    	/varcalc tmp (${tmp}+1)*-1

	    	/varset sArgValue ${sParameters.Arg[${iArgNum}, ].Right[${tmp}]}
	    	/return ${sArgValue}
    	}
    /next iArgNum
/return ${sArgValue}



Sub DisplayStats
    /echo
    /echo khiTS: Stat display - Not Completely done
    /echo ================================
    /echo Attempts: ${iSkillAttempts}
    /echo Successes: ${iSkillSuccess}
    /echo Faliures: ${iSkillFailure}
    /echo Skill Ups: ${iSkillUps}

    /if (${Me.Skill[${sUsing}]}) {
	    /echo Skill Level: ${Me.Skill[${sUsing}]}
    } else {
	    /echo Skill Level: Unknown
    }
/return



Sub Event_Chat(string type, string sender, string text)
    /if (${String[${abt}].Equal[TRUE]} && ${type.Equal[tell]} ) {
        /echo khiTS Event_Chat: Got a tell, pausing.
        /if (!${Defined[pauseTimer]}) /declare pauseTimer timer outer
        /varset pauseTimer 600
      :TellPause
         /if (${Spawn[gm]}) {
	        /if (!${Me.Sitting})	/docommand /sit
        	/docommand /camp desktop
        	/call mqout "GM in Zone! Logging out"
        	/endmacro
         }

        /if (${pauseTimer<1}) /return
        /goto :TellPause
        /mqpause
    }
/return



Sub Event_HandsFull
	/echo khiTS Event_HandsFull Error: Unrecoverable error, ending macro
	/endmacro
/return



Sub Event_CombineError
    /varcalc combineErrorCounter ${combineErrorCounter}+1
    /if (!${silentMode})	/echo khiTS Event_CombineError: ${combineErrorCounter}

    /endmacro
    
    | *** FIXME *** |
    /if (${combineErrorCounter} < 3) {
       /call cleanPack ${containerNum}
       /call clearCursor ${iDestroyResults}
       /varset bCombineDone TRUE
   } else {
       /varset combineResult COMBINE_ERROR
       /varset cleanUpAndExit 1
   }
/return



Sub Event_FullInventory
    /echo khiTS Event_FullInventory Error: Your inventory is full, ending macro.
    /call DisplayStats
    /varset combineResult COMBINE_INVENTORY_FULL
    /varset cleanUpAndExit 1
/return


| ** CHECKED **|
Sub Event_SkillFailure
    /varcalc iSkillFailure ${iSkillFailure}+1
    /varset bCombineDone TRUE
    /varset combineResult COMBINE_FAILED
/return



Sub Event_SkillSuccess
    /if (${sResults.Equal[NOT_SET]}) {
	    /declare MaxWaitCount timer local 100
	    :WaitForIt
	    /delay 2 ${Cursor.ID}
	    /if (!${Cursor.ID} && !${MaxWaitCount} == 0)	/goto :WaitForIt
	    /varset sResults ${Cursor.Name}
    }

    /varcalc iSkillSuccess ${iSkillSuccess}+1
    /varset bCombineDone TRUE
    /varset combineResult COMBINE_SUCCESS
/return



Sub Event_SkillUp
	/varset sUsing ${Param1}
    /varcalc iSkillUps ${iSkillUps}+1

    /if (${iStopAtSkillLevel} && ${iStopAtSkillLevel} == ${Param2}) {
        /call DisplayStats
        /call cleanPack ${containerNum}
        /call clearCursor ${iDestroyResults}
        /varset cleanUpAndExit 1
    }
/return



Sub Event_SkillTrivial
    /if (!${bSkillTrivial}) {
        /echo khiTS Event_SkillTrivial: Skill is trivial
        /varset bSkillTrivial TRUE
    }

    /if (${iEndOnTrivial}) {
        /call DisplayStats
        /call cleanPack ${containerNum}
        /call clearCursor ${iDestroyResults}
        /varset cleanUpAndExit 1
    }

    /varset combineResult COMBINE_TRIVIAL
/return



| Remove everything from a pack and puts in in your inventory
sub cleanPack(string PackNumber)
    /if (!${silentMode})	/echo khiTS cleanPack: Cleaning out pack: ${PackNumber}
    
    | Used for looping through pack slots
    /declare iSlot      int local
    
    | How many freeslots are in the bag
    /declare iCount     int local

    /if (${PackNumber.Equal[e]}) {
       /if (!${silentMode})	 /echo khiTs cleanPack: Clearing enviro

        /for iSlot 1 to 10
        	/if (${InvSlot[enviro${iSlot}].Item.ID}) {
            	/shiftkey /itemnotify enviro${iSlot} leftmouseup
            	/call clearCursor ${iDestroyResults}
        	}
        /next iSlot
    } else {
      /if (!${silentMode})	/echo khiTs cleanPack: Cleaning out ${PackNumber}
        | Can't empty a non-pack duh!
        /if (!${Me.Inventory[Pack${PackNumber}].Container}) {
            /echo khiTs cleanPack Error: No pack in slot
            /varset cleanUpAndExit 1
            /return
        }

        /for iSlot 1 to ${Me.Inventory[Pack${PackNumber}].Container}
            | Quit if the pack is empty
            /if (!${Me.Inventory[Pack${PackNumber}].Container})	/return

         	/if (${debug})	/echo khiTs cleanPack: Clearing Pack: Pack${PackNumber}, Slot:${iSlot}, Item: ${Me.Inventory[Pack${PackNumber}].Item[${iSlot}]}

            /if (${Me.Inventory[Pack${PackNumber}].Item[${iSlot}].ID}) {
                /varset iCount ${Me.Inventory[Pack${PackNumber}].Items}

                /shiftkey /itemnotify in pack${PackNumber} ${iSlot} leftmouseup
                /call clearCursor ${iDestroyResults}

                | Make sure we aren't just putting it back in the same bag
                /if (${Me.Inventory[Pack${PackNumber}].Items} == ${iCount}) {
                    /echo khiTs cleanPack Error: Unable to empty pack
                    /varset cleanUpAndExit 1
                    /return
                }
            }
        /next iSlot
    }

    /if (!${silentMode})	/echo khiTs: Done Cleaning pack
/return TRUE



Sub addComponents
    /declare failCount	int		local	0
    /declare newLen		int		local
    /declare compNum    int		local
    
    | The slot number in the combine container to put the next item
    /declare combSlot   int      local	1

    /for compNum 1 to ${iCompCount}
        /if (!${silentMode})	/echo -- components[${compNum}] = ${components[${compNum}]} : Length = ${components[${compNum}].Length}
        /if (!${components[${compNum}].Length})	/return

        :AddComponent
        | Make sure there are still items in the inventory slot
        /if (${InvSlot[${activeSlots[${compNum}]}].Item.ID}) {        	
			| Check container to see if it is full
			/if (${containerNum.Equal[e]}) {
				| No way I know of to check enviro containers for space - but I'm ignorant so...
			} else {
				/if (!${Me.Inventory[pack${containerNum}].Container} - ${Me.Inventory[pack${containerNum}].Items}) {
					/echo khiTS AddComp Error: Unable to add this item to the container, it is full
					/varset cleanUpAndExit 1
					/return
				}
			}

			:FindEmptySlot
			/if (${containerNum.Equal[e]}) {
				/if (${combSlot} > 10) {
					/echo khiTS AddComp Error: No such slot ${combSlot} in container
					/varset cleanUpAndExit 1
					/return
				}
			} else {
				/if (${combSlot} > ${Me.Inventory[pack${combSlot}].Container}) {
					/echo khiTS AddComp Error: No such slot ${combSlot} in container
					/varset cleanUpAndExit 1
					/return
				}
			}

			| See if there's anything in the slot in which we are trying to put the combine component
			/if (${containerNum.Equal[e]}) {
				/itemnotify in enviro ${combSlot} leftmouseup
			
				| Make sure the cursor is clear, otherwise something was in that slot
				/if (${Cursor.ID}) {
					/itemnotify in enviro ${combSlot} leftmouseup
					/varcalc combSlot ${combSlot}+1
					/varset combSlot ${String[${combSlot}].Arg[0,.]}
					/goto :FindEmptySlot
				}
			} else {
				/if (${Me.Inventory[pack${containerNum}].Item[${combSlot}].ID}) {
					/varcalc combSlot ${combSlot}+1
					/varset combSlot ${String[${combSlot}].Arg[0,.]}
					/goto :FindEmptySlot
				}
			}
    
			:PickUpItem
			| Slot is empty, so go ahead and put item into it
			/ctrlkey /itemnotify ${activeSlots[${compNum}]} leftmouseup
    
			|Check to see if cursor has multiple a stack.
			/if (${Cursor.Stack} > 1 && ${failCount} < 3) {
				/autoinv
				/varcalc failCount ${failCount}+1
				/goto :PickUpItem
			}

			/if (${containerNum.Equal[e]}) {
				/itemnotify in enviro ${combSlot} leftmouseup
			} else {
				/itemnotify in pack${containerNum} ${combSlot} leftmouseup
			}
        
        	/varcalc combSlot ${combSlot}+1
    	} else {
	    	/if (${compSlots[${compNum}].NotEqual[NULL]}) {	    	
		    	| Go to next slot with this item in it
		    	/varset activeSlots[${compNum}] ${compSlots[${compNum}].Arg[0,:]}
		    	
		    	| Strip off the active slot from available slots
		    	/varcalc newLen ${compSlots[${compNum}].Length} - (${activeSlots[${compNum}].Length} + 1)
	    		/if (${newLen} < 0) {
		    		/varset compSlots[${compNum}] NULL
	    		} else {
		    		/varset compSlots[${compNum}] ${compSlots[${compNum}].Right[${newLen}]}
	    		}
	
		    	/goto :AddComponent
	    	} else {
		    	/echo khiTS addComponents Error: You are out of ${components[${compNum}]}
		    	/varset cleanUpAndExit 1
		    	/return
	    	}
    	}
    /next compNum
/return



sub displayHelp
    /echo Syntax:   /macro khiTS "<recipe name>" "<options>"
    /echo Example:  /macro khiTS "bits" "show-stats=0 destroy=0 abort-on-tell=0 end-on-trivial=0"
    /echo -
    /echo MAKE SURE THAT
    /echo * Recipe.ini is in your macro folder, or INIPATH points to your recipe.ini file
    /echo * Inventory is open.
    /echo * All your containers are open.
    /echo * Nothing crosses over each other, all windows (bags, inventory, buttons) must be free.
    /echo * Your windos positions are saved (by closing them and opening them again after they have been moved).
    /echo -
    /echo Options:
    /echo --------
    /echo * show-stats
    /echo -- Syntax: show-stats=1|0
    /echo -- Example: show-stats=0
    /echo -- Shows combine statistics.
    /echo -- Set to 1 for show showing stats, 0 to leave out the stats.
    /echo -- Default set to 1 (show stats).
    /echo -
    /echo * destroy-results
    /echo -- Syntax: destroy-results=1|0
    /echo -- Example: destroy-results=1
    /echo -- Tells the macro wether end-result is destroyed or kept.
    /echo -- Set to 1 for destroying end-result, 1 to keep end-result.
    /echo -- Default set to 0 (keep end-result).
    /echo -
    /echo * abort-on-tell
    /echo -- Syntax: abort-on-tell=1|0
    /echo -- Example: abort-on-tell=1
    /echo -- Tell the macro wether it should /endmacro when recieving a tell.
    /echo -- Set to 1 for ending macro on tells, 0 to ignore tells.
    /echo -- Default set to 0 (ignore tells).
    /echo -
    /echo * end-on-trivial
    /echo -- Syntax: end-on-trivial=1|0
    /echo -- Example: end-on-trivial=1
    /echo -- Tell the macro wether it should stop when recieving a trivial message.
    /echo -- Set to 1 for ending macro on trivial, 0 to ignore trivial.
    /echo -- Default set to 0 (ignore trivial).
    /echo -
    /echo * make-this-many
    /echo -- Syntax: make-this-many=#
    /echo -- Example: make-this-many=100
    /echo -- The number of successfull combines you want made (or till no more components are available).
    /echo -- Set to 0 for unlimited combines (or till no more components are available), or to the wanted amount.
    /echo -- Default set to 0 (unlimited).
    /echo -
    /echo * stop-at-skill-level
    /echo -- Syntax: stop-at-skill-level=###
    /echo -- Example: stop-at-skill-level=123
    /echo -- Tell the macro to stop when a certain skill level is reached.
    /echo -- Default set to 0 (do not stop at any skill level)
    /echo -
    /echo * silent-mode
    /echo -- Syntax: silent-mode=1|0
    /echo -- Example: silent-mode=1
    /echo -- Tell the macro to only output errors
    /echo -- Default set to 0 (output everything)
    /echo -
    /echo * debug
    /echo -- Syntax: debug=1|0
    /echo -- Example: debug=1
    /echo -- Tell the macro to only everything. This also sets silent-mode=0
    /echo -- Default set to 0 (do not output debugging information)
/return
[/code]
Last edited by kellewic on Tue Jun 29, 2004 1:36 pm, edited 1 time in total.

draco
a ghoul
a ghoul
Posts: 145
Joined: Thu Jan 29, 2004 7:06 pm
Contact:

Post by draco » Mon Jun 28, 2004 8:13 am

Can't wait to try this out. I was actually sitting here combining this and a skill up macro I found when. I noticed your post. Thanks.

kellewic
a lesser mummy
a lesser mummy
Posts: 38
Joined: Tue Jun 08, 2004 2:27 am
Location: AZ

Post by kellewic » Mon Jun 28, 2004 1:40 pm

Actually after I posted this last night I started playing with ways to speed up the putting of items in the tradeskill container (in my case a Brew Barrel). I basically changed the code to take longer at initialization to save time during the actual run.

Currently the code loops through the inventory every single time it goes to put items in the tradeskill container, which gets to be very slow over time as it has to start looking in slots it's looked in throughout the whole process anyway since it starts at Pack1, Slot1 and goes to Pack8, SlotX but does skip the tradeskill container you are using (in cases where you are using something like a Sewing Kit).

Basically what I've done so far is created 2 extra arrays (compSlots[10] and activeSlots[10]) and during initialization (after the INI file is read) the macro loops through all inventory slots and finds every slot that has components for what you are making and matches them up against the components[10] array (it also still skips the tradeskill container if it is in your inventory).

The activeSlots[] array is basically a slot number to use for a given component. The compSlots[] array lists all other slots where that component was found in the format ###:###:###

It works pretty well in that it definitely sped up the insertion of items into the tradeskill container (I was testing with Mino Hero Brew which has 9 items and I scattered them all around my packs). The only problem I am having to tweak is that it goes so much faster than the original that the delays in the original no longer suffice and I occasionally get the "You can't combine while hands are full..." message.

I will work with it more tonight and see if I can't get it working a bit better. I'll probably test it with a 1,000 combines of Short Beer or something that won't take my skill past its current point. If I can get it to successfully combine that many times, then I'll be happy.

Btw, what's the skill up macro you found? Does it add additional functionality to this one or is it different functionality? I ask because my next skill is going to be smithing and anything to speed that process up would be great. After running to the merchants so many times and buying the same exact amount of each component for brewing, I seriously considered whipping out advpath.inc and getting my toon to go buy the crap his self :)

kellewic
a lesser mummy
a lesser mummy
Posts: 38
Joined: Tue Jun 08, 2004 2:27 am
Location: AZ

Post by kellewic » Tue Jun 29, 2004 1:45 pm

I finished the code I was working on and saw a definite speed increase so I edited my post about 3 posts up to reflect the changes and new code. The code changed quite a bit so if you have code that called any subs directly, I probably broke it since I removed a few subs and combined them.

draco
a ghoul
a ghoul
Posts: 145
Joined: Thu Jan 29, 2004 7:06 pm
Contact:

Post by draco » Wed Jun 30, 2004 4:07 pm

Basically the code would buy each item in a recipe. Combine and Sell. I replaced it combine with this. For example, replacing the call to do combine in the Hero Brew Macro, in order to use this combine.

Simply, replace ther docombine with a /call Make .....

Also, if you exec khits.mac with the original style for parameters.
i.e. /mac khits "[recipe name]" "[options]"
the khits.mac becomes the following.

Code: Select all

|khits.mac v 3.1

#include khits.inc


Sub Main(string recipe, string options)
	/call Make ${recipe} ${options}
	/call ClosePacks
/endmacro
I am at work right now. The vesion I have at home has the proper credits,etc. I'll edit this post when I get home. Also, will be an updated resetKhits routine. need to include sResults and sUsing. I wrote those yesterday. So, I'll just post the snipet.

Edit inserting subroutine


Code: Select all



Sub resetKhits
	|It would be more efficient to just initialize the var
	|rather than delete and re-declare everytime. But today is a lazy day.

	/varset combineResult 0
	/varset cleanUpAndExit 0
	/varset combineErrorCounter 0

	/deletevar components
	/declare components[10]
	| Container in which the recipe will be made
	/varset containerNum  NOT_SET

	| The number of components in this recipe
	/varset iCompCount     0

	/varset bCombineDone   FALSE
	/varset bSkillTrivial  FALSE

	| Settings
	| Destroys the results of a combine (but not any items used in the combine)
	/varset iDestroyResults  0

	| Stops the macro when you can no longer get skillups from doing the combine
	/varset iEndOnTrivial  0

	| Skillup info
	| How many times you've tried a combination
	/varset iSkillAttempts  0

	| How many times it worked
	/varset iSkillSuccess    0

	| How many times it didn't work
	/varset iSkillFailure 0

	| How many skill points you have received
	/varset iSkillUps   0

	| Skill level to stop at
	/varset iStopAtSkillLevel  0

	| The results of what we are making
	/varset sResults   NOT_SET
	/varset sUsing   NOT_SET

/return

Last edited by draco on Wed Jun 30, 2004 10:35 pm, edited 1 time in total.

User avatar
dont_know_at_all
Developer
Developer
Posts: 5450
Joined: Sun Dec 01, 2002 4:15 am
Location: Florida, USA
Contact:

Post by dont_know_at_all » Wed Jun 30, 2004 5:10 pm

For all of you having problems with this macro, put a five second delay after /autoinv.

rasor
orc pawn
orc pawn
Posts: 15
Joined: Fri May 14, 2004 12:46 am

not sure why...

Post by rasor » Sun Jul 04, 2004 11:54 am

I run the macro and it keeps saying unable to clean out bag # whatever. Doesn't matter what slot i have with empty bags it just goes on to the next one that has something in it and says unable to clean out that one. ANy ideas?