Before learning anything about selecting and using... you have to know a couple of definitions.
Item TYPE = the KIND of item, either a 2 or 3 letter code.
Item ID = the SPECIFIC items identification.
Make sure you know the difference between these right now.
A group of 100 bandages will have an Item TYPE of ZJF. One bandage will have a TYPE of ZJF. A stack of 20,000 bandages will have an TYPE of ZJF.
A stack of bandages will have some unique Item ID (something like AQBBJHD). Each bandage will have a different ID.
Ok, got it?
Now we can learn how to use stuff. Lets put a bandage on ourselves. If you've already read the script flow post, and the first and second script posts, you'll see this stuff... if not it's no big deal, reading this first will help a little when you get to those posts.
1 - What do we want to do?
Apply a bandage to myself when I hit F10
2 - Define that a little more
Hit the F10 Key
Find a bandage in my pack - quit if not found
Use the bandage
Target Myself
SUO:
repeat
onhotkey F10
gosub UseBandage
until #CharGhost = YES
while #CharGhost = YES
wait 0
GoTo SUO
That's my now famous mainloop with a gosub in the main portion. The gosub is called whenever the F10 key is pressed. The command
onhotkey tells the script to react when it sees the F10 key press. Then the script will execute the code within the sub routine "UseBandage"
sub UseBandage
findItem ZJF C_ , #backpackID
if #findKind = -1
halt
set #lobjectID #findID
set #ltargetKind 1
event macro 17 0
target 3
event macro 23 0
wait 5
return
Ok, lets see whats happening in the sub.
findItem ZJF C_ , #backpackIDFinds an ITEM of ZJF (meaning ANY bandage or pile of bandages... remember ITEM TYPE) in a container (C_ , ) with the ID of your backpack.
It's worth noting, we're only interested in finding the item TYPE of bandages, we don't care what color, what stack, or anything else, we only care about finding ANY bandages.
if #findKind = -1
halt This line says, if you DON'T FIND ANY then execute the next line of code (halt).
set #lobjectID #findIDSince we're here, we know that at least one bandage type (ZJF) was found in our pack. When it (or they) were found, the system automatically got the ITEM ID from it (or them) and stored it in the #findID register. If you were to look at #findID on the right side of EUO right now, you'd see something like ERGJAR which would be the ID of the individual bandage (or stack) that was found.
We want that ID set as last target, so we can use a built in UO macro to use it. So this line sets the Last Object ID as the found bandage.
set #ltargetKind 1This sets the internal thinking of EUO to use the item type of an object. It's CRITICAL to do this as not to confuse EUO to thinking it's a tile or something.
event macro 17 0That line is the same thing as making a UO macro to "use last item" which was set as the found bandage.
target 3Waits up to 3 seconds for the target cursor to appear. If it comes up quicker the script simply continues then instead of waiting.
event macro 23 0This is the UO macro for "target self". This would be the same thing as clicking yourself now that the bandage has been used and the target cursor is up.
wait 5Short 1/4 second wait to allow the events to complete before going back through the cycle.
So there it is. Your completed "find a bandage and use it when I press F10" script:
;=================================================================
; Script Name: Cerveza's Hotkey Bandage
; Author: Cerveza
; Version: 1.0
; Shard OSI / FS: OSI / FS OK
; Revision Date: 2/24/2009
; Purpose: Use Bandage on Hotkey
; Globals: None
;=================================================================
;************************ Setup **********************************
;*********************** MainLoop ********************************
SUO:
repeat
onhotkey F10
gosub UseBandage
until #CharGhost = YES
while #CharGhost = YES
wait 0
GoTo SUO
;************************ Subs ***********************************
sub UseBandage
findItem ZJF C_ , #backpackID
if #findKind = -1
halt
set #lobjectID #findID
set #ltargetKind 1
event macro 17 0
target 3
event macro 23 0
wait 5
return