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.
How a script sees and acts
Section titled “How a script sees and acts”- 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. finditemis how a script sees objects. It fills the#Find…variables. When nothing matched,#FindCntis0and#FindIDreadsX: always test#FindCnt.event macroruns 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.
Report what the script is doing
Section titled “Report what the script is doing”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_ , #BackpackIDlog finditem found #FindCnt stacksdisplay ok Stacks of gold in the backpack: #FindCnthaltFind an item and use it
Section titled “Find an item and use it”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 backpackif #FindCnt = 0{ event sysmessage No bandages left halt}set #LObjectID #FindIDevent macro 17 0 ; use ittarget 3sif #TargCurs = 1 event macro 23 0 ; target yourselfhaltGo through every match
Section titled “Go through every match”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 tilesif #FindCnt > 0{ for #FindIndex 1 #FindCnt { exevent drag #FindID #FindStack wait 10 exevent dropc #BackpackID wait 10 }}haltTarget something
Section titled “Target something”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 bandagesset %pet HIJKLMN ; the ID of your petset #LObjectID %bandagesevent macro 17 0 ; use the bandagestarget 3sif #TargCurs = 1{ set #LTargetID %pet set #LTargetKind 1 ; 1: an object event macro 22 0 ; target it}haltMove items
Section titled “Move items”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 backpackfinditem POF C_ , #BackpackIDif #FindCnt > 0{ moveitem #FindID %bag if #MoveRes <> ok event sysmessage The gold did not arrive: #MoveRes}haltIn 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 openfinditem POF C_ , #BackpackIDif #FindCnt > 0{ exevent drag #FindID #FindStack wait 10 exevent dropc %bag wait 10}haltWait for the client instead of guessing
Section titled “Wait for the client instead of guessing”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 backpackwaitfor #ContName = container_gump 3sif #WaitRes = #false display ok The backpack did not open.haltWait for a journal line
Section titled “Wait for a journal line”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 nowevent macro 15 28 ; cast Greater Healfindjournal %j * 3s fizzles you_must_waitif #JFound = 0 event sysmessage No answer in 3 secondsif fizzles in #Journal event sysmessage FizzledhaltAnswer a gump the server sent
Section titled “Answer a gump the server sent”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 shardset %t #SCnt + 5repeat scangumps T_ , %confirm wait 2until #GumpCnt > 0 || #SCnt > %texevent GumpReply %confirm 1 ; button 1: OKAYif #GumpReplyRes <> sent event sysmessage The confirmation did not open.haltWalk somewhere
Section titled “Walk somewhere”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 1699if #PathState <> arrived display ok Did not get there: #PathStatehaltWork on a text
Section titled “Work on a text”str puts its result in #StrRes, and the next str replaces it:
copy the result first.
set %list iron_gold_agapitestr count %list _set %fields #StrRes + 1 ; => %fields = 3str part %list _ 2set %second #StrRes ; => %second = goldstr len %secondset %length #StrRes ; => %length = 4haltAsk with a window
Section titled “Ask with a window”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 Clearmenu Window Size 160 45menu Button ok 10 10 60 25 OKmenu Showset #MenuButton N/Awhile #MenuButton = N/A wait 1if #MenuButton = closed display ok You closed the window.else display ok You clicked #MenuButtonhaltRun until you stop it
Section titled “Run until you stop it”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 0mainloop: gosub oneRound wait 1sgoto mainloop
sub oneRound set %rounds %rounds + 1 event sysmessage Round %roundsreturnKeep data between runs
Section titled “Keep data between runs”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 0set *runs *runs + 1display ok This script has run *runs times.halt