AddComp with new parm system

A forum for macro code snippets to be used in writing other macros. Post routines or .inc files here only, completed macros go to the Macro Depot.

Moderator: MacroQuest Developers

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

AddComp with new parm system

Post by dont_know_at_all » Mon Apr 19, 2004 3:50 pm

This is the heart of the TS macros. You'll notice zero point zero delays are needed.

Code: Select all

sub AddComp
    /declare islot local
    /varset islot ${FindItem[@Param0].InvSlot}
    /newif @islot {
        /ctrl /itemnotify @islot leftmouseup
        /itemnotify world@Param1 leftmouseup
    } else {
      /echo Could not find << @Param0 >>
      /call EndCombines
      /return 1
    }
/return 0

Kaitain
a ghoul
a ghoul
Posts: 109
Joined: Fri Oct 10, 2003 1:49 pm

Well that's a lot better...

Post by Kaitain » Sun Apr 25, 2004 8:14 am

Well that's a lot simpler than my huge, cumbersome addcomponets sub I wrote... I'm converting my TS macro to use your sub now.

Kaitain
a ghoul
a ghoul
Posts: 109
Joined: Fri Oct 10, 2003 1:49 pm

Updated AddComp

Post by Kaitain » Sun Apr 25, 2004 10:42 am

I noticed a problem when using /itemnotify worldX - It only goes up to 8, if you try to do anything with the 9th or 10th slots you get an error, so I changed this to /itemnotify in enviro X

Also, things are changing, so the /ctrl is now /ctrlkey (ironically the command itself will tell you /ctrl <command> when done alone)

Here's an example of a fully realized add component macro with error checking and validation of empty slots. This of course is going to be slower than a barebones macro, you have to make the decision on the level of fault tolerance you want in your macros. I tend to go overboard.

WARNING:
A problem with this macro is the fact that it will find items in your combine pack if you are not using an enviromental container, e.g. a sewing pack.
You just have to check for that somewhere else or add checking for that in this. In my tradeskills macro I decided to forgo the use if ${FindItem} and do my own finding.

Code: Select all

#turbo 

Sub Main

	/call AddComp "@Param0" @Param1 @Param2
	
/return
 
 sub AddComp(ComponentName,CombinePackNumber,CombineSlotNumber) 
    | ComponentName		- Name of the component you want to add
    | CombinePackNumber - Destination pack number, e for enviro
    | CombineSlotNumber - Destination slot number
    
    /declare iSlot local	| The slot in which the item was found
    
    /if (!${Defined[ComponentName]} || !${Defined[CombinePackNumber]} || !${Defined[CombineSlotNumber]}) {
    	/echo AddComp Error: You must specify the component, the container number, and the container slot in which to put the compents
    	/echo Syntax: /call AddComp "<Component Name>" <Pack Number> <Slot Number in Pack>
    	/return FALSE
    }

	| Check container to see if it is full
	/if (${String[@CombinePackNumber].Equal[e]}) {
		| No way I know of to check enviro containers for space - but I'm ignorant so...
	} else {
		/if (${Me.Inventory[pack@CombinePackNumber].Container}-${Me.Inventory[pack@CombinePackNumber].Items}==0) {
			/echo AddComp Error: Unable to add this item to the container, it is full
			/return FALSE
		}
	}

    | Look for the item
    /varset iSlot ${FindItem[@ComponentName].InvSlot} 
    /if (@iSlot) {
 		:FindEmptySlot
		/echo CombineSlot = @CombineSlotNumber
        /if (${String[@CombinePackNumber].Equal[e]}) {
	    	/if (@CombineSlotNumber>10) {
	    		/echo AddComp Error: Unable to add this item to the container, it is full
	    		/return FALSE
	    	}
	    } else {
	    	/if (@CombineSlotNumber>${Me.Inventory[pack@CombinePackNumber].Container}) {
	    		/echo AddComp Error: Unable to add this item to the container, it is full
	    		/return FALSE
	    	}
	    }
        | See if there's anything in the slot we are trying to put stuff
        /if (${String[@CombinePackNumber].Equal[e]}) {
	        /itemnotify in enviro @CombineSlotNumber leftmouseup 
	        | Make sure the cursor is clear, otherwise something was in that slot
	        /if (${Cursor.ID}!=NULL) {
		        /itemnotify in enviro @CombineSlotNumber leftmouseup 
				/varadd CombineSlotNumber 1
				/varset CombineSlotNumber ${String[@CombineSlotNumber].Arg[0,.]}
		    	/goto :FindEmptySlot
	        }
        } else {
        	/if (${Me.Inventory[pack@CombinePackNumber].Item[@CombineSlotNumber].ID}!=NULL) {
 				/varadd CombineSlotNumber 1
				/varset CombineSlotNumber ${String[@CombineSlotNumber].Arg[0,.]}
		    	/goto :FindEmptySlot
        	}
        }
        
    	
    	| Slot is empty, so go ahead and put item into it
    	| Found it, pick it up and move it to the combine container
        /ctrlkey /itemnotify @iSlot leftmouseup 
        /echo ComponentName = @ComponentName
        /echo CombinePackNumber = @CombinePackNumber
        /if (${String[@CombinePackNumber].Equal[e]}) {
	        /itemnotify in enviro @CombineSlotNumber leftmouseup 
        } else {
        	/itemnotify in pack@CombinePackNumber @CombineSlotNumber leftmouseup
        }
        
    } else { 
      /echo AddComp Error: Could not find << @ComponentName >> 
      /return FALSE 
    } 
/return TRUE