Legion-Scripting
Legion Scripting
Section titled “Legion Scripting”TazUO has implemented a scripting engine directly into the client.
You can access Legion Scripting by going to Top menu -> Legion Script
Introduction
Section titled “Introduction”Public Script Library set up here for people to contribute to.
ZIP Script Packages — bundle a script and its assets into a single .zip.
Running scripts from a hotkey
Section titled “Running scripts from a hotkey”You can bind a Legion script directly to a hotkey. Right-click the script and choose Set Hotkey, then press the key combination you want. The binding is saved per script path and persists globally (across characters), and pressing the key toggles that script on and off. See Hotkeys.
You can also drive a script from an Action Bar Script slot, which toggles the script and highlights green while it runs.
The Script Manager window remembers its size and position and restores them when reopened.
Recent API additions
Section titled “Recent API additions”API.Virtue("justice")— the virtue API now supports justice in addition to honor, sacrifice, and valor.API.OpenQuestLog()— opens the quest log gump.API.OpenHelp()— opens the help menu.API.Pathfind(x, y, z, distance, wait, timeout, run)andAPI.PathfindEntity(entity, distance, wait, timeout, run)— a new run parameter controls whether the character runs (default true) or walks along the path..IsParalyzed— a boolean property on mobile objects.API.UpdateCooldown(name, maxValue, currentValue),API.RestartCooldown(name),API.DeleteCooldown(name)andAPI.CooldownExists(name)— manage cooldown bars created withAPI.CreateCooldownBar.API.Gumps.CreateGumpTextBox(text, width, height, multiline, fontSize)— a new fontSize parameter (default 20) sizes the TTF font of the text input field, andApiUiTtfTextInputField.FontSizeexposes it as a property.API.ActiveSpells(),API.ActiveSpellNames()andAPI.IsSpellActive(spell)— see which toggle spells/moves are currently active (the same ones action bars highlight).API.ListRunningScripts()andAPI.IsScriptRunning(path).API.PlayScript,API.StopScriptandAPI.ToggleScriptnow match scripts by their path relative to theLegionScriptsfolder, so scripts that share a file name are no longer ambiguous.API.ContextMenu(serial, entry)— a string-based overload that selects a context menu entry by its text.SetTooltip(text),SetEntityTooltip(serial)andClearTooltip()on the base UI control, so scripts can attach plain-text or entity-property tooltips to any control. Setting a tooltip enables mouse input automatically, and a dedicatedSetAcceptMouseInput(enabled)is also available.Highlight(hue)on game objects and mobiles — sets a highlight hue (remembering the original so it can be restored withHighlight(None)); on mobiles it also recolors all equipped items.API.GetAllMobiles(graphic, distance, notoriety, sortby)— a new sortby parameter (case-insensitive) orders the result by"Distance"(default),"Hits"(current hits, lowest first), or"MaxHits". It also accepts optional filters, each ignored unless supplied:name(case-insensitive partial match),graphics,hues,minDistance,isHuman,isFemale,isGhost(dead mobiles),isFriend(friends list),poisoned,paralyzed, andhasLineOfSight; the boolean ones acceptTrue/Falseto include or exclude.API.TargetRel(xOffset, yOffset, tilesOnly=True)— targets the topmost visible object (entity, static/multi, or land) at a tile offset from the player, resolved the same way a click would. WithtilesOnlytrue (the default) entities are ignored.Target()andTargetRel(xOffset, yOffset, tilesOnly=True)on entity objects — target the entity itself, or a tile relative to its position.API.SetLastTarget(serial=None, x=None, y=None, z=None, graphic=None)— overrides the client’s last target. Pass an entityserial, or a location (x,y,z) for a land tile; includegraphicto set it as a static instead.API.TargetTileRel(xOffset, yOffset, graphic, tilesOnly=True)— now targets the highest non-land object at the location (instead of the base land tile) and acceptstilesOnly(default true) to ignore entities.API.GetSpellsInSpellbook(serial)— returns the names of all spells in a spellbook, given the spellbook’s serial.API.Gumps.CreateGumpRenderedMapArea(...)— builds a rendered area of the world map inside a gump (ApiUiRenderedMapArea).API.Pause()— the previous hard 30-second pause limit was removed.API.IsKeyPressed("CTRL+SHIFT+F1")— returns whether the given key or key combination (modifiers + key) is currently held down.API.RequestHotkey(prompt, timeout)— pops up the in-game hotkey capture window and returns the chosen key combination as a string (e.g."CTRL+SHIFT+F1"), ready to pass straight toAPI.OnHotKey()orAPI.IsKeyPressed(). Only keyboard bindings are accepted, and it returns an empty string if the window is cancelled or the timeout elapses.ApiItem.GetContainerGump()— now reliably finds the container window for a ground item whose overhead name is also showing (previously the name-overhead gump could be returned instead of the container window).
Script warnings
Section titled “Script warnings”TazUO prints warnings to the journal/chat when a script is likely to misbehave:
- Unbounded
whileloop — starting a script that containswhile True,while (true)orwhile(true)warns you, because a pure CPU loop never blocks and cannot be interrupted byAPI.StopScript. Usewhile API.StopRequested:(Python) orwhile (API.StopRequested)(C#) instead. - Script did not stop — if a script ignores the stop request (e.g. it is stuck in a loop), it is detached after a short grace period and keeps running in the background. It is inert (its API is disposed) and exits when the client closes, but it cannot be restarted until that background thread exits.
- Deprecated gump helpers — the legacy top-level gump methods (
API.CreateGump,API.CreateGumpButton,API.CreateGumpLabel,API.AddGump,API.AddControlOnClick, and the rest of theAPI.Create*family) are deprecated and will be removed after 11-1-26. Using them now prints a warning. Move to the equivalentAPI.Gumps.*methods (e.g.API.Gumps.CreateGumpButton).
Screenshots
Section titled “Screenshots”Bonus, Github Copilot can create scripts for you
Section titled “Bonus, Github Copilot can create scripts for you”-
Head over to the documentation you want to use(Links above)
-
Login to Github
-
Click this little copilot icon on the file:
-
Ask it to create a script:
Script Recording:
Section titled “Script Recording:”To start recording a script just hit Record Button, once you’re recording you will see each action under Recorded actions
You can pause and resume recording under your needs, move up/down or delete actions.
To finish script recording click Stop button.
You can choose to copy script or save it directly. Saved scripts will be displayed at Script manager: