Skip to content

Common patterns

Most scripts are built from the same few moves. Each one here is a whole script you can run and change. The item types (ZLF, POF), IDs and journal texts in them are only examples: yours are different, and Finding IDs and types shows how to read them.

  • Objects have an ID and a type. An ID (6 to 8 letters, YKLMNOP) is one object. A type (2 or 3 letters, POF) is a kind of object. Both are text, never numbers.
  • finditem is how a script sees objects. It fills the #Find… variables. When nothing matched, #FindCnt is 0 and #FindID reads X: always test #FindCnt.
  • event macro runs the client’s own macros: speech, skills, spells, gumps, last object, last target. Look the numbers up on its page.
  • Commands that act on the client need one. Without a client they do nothing, and the variables that describe it read N/A.

log writes a line to the editor’s Output panel and the script goes on. It needs no client and the lines stay, so it is the way to follow a script while it runs. It is new in EasyUO Reforged. event sysmessage shows a line in the game window instead. display opens a message box and the script waits until you close it: use it for a final result or a question, not inside a loop.

log Counting the gold...
finditem POF C_ , #BackpackID
log finditem found #FindCnt stacks
display ok Stacks of gold in the backpack: #FindCnt
halt

Using an object is two lines: put its ID in #LObjectID and run the client’s Last Object macro.

finditem ZLF C_ , #BackpackID ; bandages, in the backpack
if #FindCnt = 0
{
event sysmessage No bandages left
halt
}
set #LObjectID #FindID
event macro 17 0 ; use it
target 3s
if #TargCurs = 1
event macro 23 0 ; target yourself
halt

Set #FindIndex to look at the matches one after the other. Test #FindCnt first: for counts down when its end is smaller than its start, so with no match it would run for 1 and for 0.

finditem POF G_3 ; gold on the ground, within 3 tiles
if #FindCnt > 0
{
for #FindIndex 1 #FindCnt
{
exevent drag #FindID #FindStack
wait 10
exevent dropc #BackpackID
wait 10
}
}
halt

Wait for the target cursor with target, check that it came, say what to target and run the Last Target macro. Set #LTargetKind every time.

set %bandages ABCDEFG ; the ID of your bandages
set %pet HIJKLMN ; the ID of your pet
set #LObjectID %bandages
event macro 17 0 ; use the bandages
target 3s
if #TargCurs = 1
{
set #LTargetID %pet
set #LTargetKind 1 ; 1: an object
event macro 22 0 ; target it
}
halt

moveitem moves an item into a container in one line: it picks it up, drops it, waits, tries again when that is safe, and says in #MoveRes whether it arrived (ok). Without an amount it moves the whole stack. moveitem is new in EasyUO Reforged. A container outside your backpack must have been opened, or the result is left even when the move worked.

set %bag ABCDEFG ; the ID of a bag in your backpack
finditem POF C_ , #BackpackID
if #FindCnt > 0
{
moveitem #FindID %bag
if #MoveRes <> ok
event sysmessage The gold did not arrive: #MoveRes
}
halt

In EasyUO 1.5, exevent drag picks an item up and exevent dropc drops it into a container, with no check. The amount is 1 unless you give one, so pass #FindStack to move a whole stack. Don’t mix event drag with the exevent drop… commands.

set %bag ABCDEFG ; the ID of the bag to fill; it has to be open
finditem POF C_ , #BackpackID
if #FindCnt > 0
{
exevent drag #FindID #FindStack
wait 10
exevent dropc %bag
wait 10
}
halt

After an action, the client needs time. waitfor waits until a condition is true or a timeout passes, and #WaitRes says which happened. It is new in EasyUO Reforged: the original EasyUO needs a loop with wait.

event macro 8 7 ; open the backpack
waitfor #ContName = container_gump 3s
if #WaitRes = #false
display ok The backpack did not open.
halt

Save #JIndex before you act, then let findjournal look through everything that came in after it. The journal writes spaces as _. findjournal is new in EasyUO Reforged too.

set %j #JIndex ; where the journal is now
event macro 15 28 ; cast Greater Heal
findjournal %j * 3s fizzles you_must_wait
if #JFound = 0
event sysmessage No answer in 3 seconds
if fizzles in #Journal
event sysmessage Fizzled
halt

A gump the server sends (a menu, a confirmation) is recognised by its type ID, which is the same every time it opens: read it once with scangumps (Finding IDs has a probe). In EasyUO Reforged, exevent GumpReply presses one of its buttons without a click, with the checkboxes and text fields it needs, and closes the window. Wait for the gump with scangumps T_, and read #GumpReplyRes afterwards: nogump means it was not open, and nothing was sent. The button numbers come from the shard, not from the client.

set %confirm JHEIIPI ; the gump's #GumpTypeID on your shard
set %t #SCnt + 5
repeat
scangumps T_ , %confirm
wait 2
until #GumpCnt > 0 || #SCnt > %t
exevent GumpReply %confirm 1 ; button 1: OKAY
if #GumpReplyRes <> sent
event sysmessage The confirmation did not open.
halt

path go plans a route around walls and water and walks it. Always read #PathState afterwards. In the original EasyUO, move walks in a straight line and event pathfind lets the client find a short way.

path go 1434 1699
if #PathState <> arrived
display ok Did not get there: #PathState
halt

str puts its result in #StrRes, and the next str replaces it: copy the result first.

set %list iron_gold_agapite
str count %list _
set %fields #StrRes + 1 ; => %fields = 3
str part %list _ 2
set %second #StrRes ; => %second = gold
str len %second
set %length #StrRes ; => %length = 4
halt

menu builds a window of your own. A click on a button puts its name in #MenuButton, so set that to something else before you wait for it. There are two menu systems, EasyUO 1.5’s and 1.6’s, and a script runs under one of them: read MENU: EasyUO 1.5 and 1.6 before you write or change menu lines, and don’t mix their sub-commands.

menu Clear
menu Window Size 160 45
menu Button ok 10 10 60 25 OK
menu Show
set #MenuButton N/A
while #MenuButton = N/A
wait 1
if #MenuButton = closed
display ok You closed the window.
else
display ok You clicked #MenuButton
halt

A script that keeps working is a label, the work, a wait and a goto back. Keep the work in subs, after the loop.

set %rounds 0
mainloop:
gosub oneRound
wait 1s
goto mainloop
sub oneRound
set %rounds %rounds + 1
event sysmessage Round %rounds
return

A * variable keeps its value when the script and EasyUO Reforged are closed. For more than a few values, sql keeps them in a database file. SQL or * variables? compares the two.

if *runs = N/A
set *runs 0
set *runs *runs + 1
display ok This script has run *runs times.
halt