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”LegionPy Scripting setup guide
Public Script Library set up here for people to contribute to.
Visual Studio Code Extension for legion script for easier script writing.
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:
Documentation:
Section titled “Documentation:”Commands
Section titled “Commands”togglescript
Section titled “togglescript”Toggle another script playing
Example:
togglescript 'myscript.lscript'
or togglescript myscript.py
msg
text
Make your player say something in game
Example:
msg I banish thee!
togglefly
Section titled “togglefly”If your player is a gargoyle this will send a toggle fly request
useprimaryability
Section titled “useprimaryability”Use your primary ability
usesecondaryability
Section titled “usesecondaryability”Use your secondary ability
clickobject
Section titled “clickobject”clickobject
‘serial’
Example:
clickobject 'self'
or clickobject '0x1234567'
attack
Section titled “attack”attack
‘serial’
Example:
attack 'self'
or attack '0x1234567'
bandageself
Section titled “bandageself”Attempt to bandage yourself
useobject
Section titled “useobject”Use an object(Double click)
useobject | ’serial' | 'true/false’ |
---|---|---|
Object serial | Use double click queue (Not required, default true) |
Example:
useobject '0x1234567'
or useobject '0x1234567' false
target
Section titled “target”Target an object or mobile
target
‘serial’
Example:
target 'self'
waitfortarget
Section titled “waitfortarget”waitfortarget | ’0/1/2' | '10000’ |
---|---|---|
0 = Any target type, 1 = harmful, 2 = beneficial | Timeout, 10000 is default(10 seconds) |
Example:
waitfortarget '0'
usetype
Section titled “usetype”usetype | ’container' | 'objtype(graphic)' | 'hue(optional)‘ |
---|---|---|---|
Container serial | Object type | Hue(If not included, any hue will match) |
Example:
usetype 'backpack' '0x456'
or usetype 'backpack' '0x456' '32'
Pause the script for a duration of time in milliseconds
pause
‘duration in ms’
Example: pause 1000
useskill
Section titled “useskill”Use a skill from skill name
useskill
‘skillname(Can be a partial name)‘
Example: useskill 'evaluate'
walk
or run
Section titled “walk or run”Send a walk or run request to the server
walk
/run
‘direction’
Directions |
---|
north |
right |
east |
down |
south |
left |
west |
up |
Example: run 'north'
canceltarget
Section titled “canceltarget”Clear a target cursor if there is one
sysmsg
Section titled “sysmsg”Display a message in your system messages(Not sent to the server)
sysmsg | msg | hue |
---|---|---|
required | optional |
Example: sysmsg 'No more tools!' '33'
moveitem
Section titled “moveitem”Move an item to a container
moveitem
‘item’ ‘container’ ‘amount(optional)‘
If amount is 0 or not used it will attempt to move the entire stack
Add ! to move items without stacking them: moveitem!
Example: moveitem '0x23553221' 'backpack'
moveitemoffset
Section titled “moveitemoffset”Move an item to the ground near you
| moveitemoffset
| ‘item’ | ‘amt’ | ‘x offset’ | ‘y offset’ | ‘z offset’ |
| - | - | - | - | - |
| | | Use 0 to grab the full stack | | | |
Example: moveitemoffset '0x32323535' '0' '1' '0' '0'
Cast a spell by name
cast
‘spell name’
Spell name can be a partial match
Example: cast 'greater he'
waitforjournal
Section titled “waitforjournal”Wait for text to appear in journal
waitforjournal
‘the text’ ‘duration in ms’
Example: waitforjournal 'you begin' '15000'
<- this waits for up to 15 seconds
settimer
Section titled “settimer”Create a timer. If the timer already exists, this is ignored until the timer expires.
settimer
‘name’ ‘duration’
Note: Timers are shared between scripts so make sure to name them uniquely.
Example: settimer '123bandage' '10000'
//Create a timer named 123bandage with a duration of 10 seconds
removetimer
Section titled “removetimer”Remove a timer
removetimer 'name'
Example: removetimer '123bandage'
setalias
Section titled “setalias”Set an alias to a serial
setalias
‘name’ ‘serial’
Example: setalias 'pet' '0x1234567'
unsetalias
Section titled “unsetalias”Unset an alias
unsetalias 'pet'
movetype
Section titled “movetype”Move any object matching the type
movetype 'graphic' 'source' 'destination' [amount] [color] [range]
Amount and color are optional
Example: movetype 0x55 'backpack' 'bank'
toggleautoloot
Section titled “toggleautoloot”Toggle the built in simple auto loot system
toggleautoloot
Create a target cursor to show info about an object
info
setskill
Section titled “setskill”Set skill locked/up/down
setskill 'name' 'up/down/locked
Example: setskill 'hiding' 'locked'
getproperties
Section titled “getproperties”Request item props from the server
getproperties 'serial'
Example: getproperties 'found'
Note: This will pause the script until we have received the properties unless you add ! modifier
getproperties 'found' #Script will pause here until we have the propertiesif properties 'found' 'some text' sysmsg 'we found the holy grail'endif
Turn your character in a direction
turn 'direction'
Example: turn 'north'
createlist
Section titled “createlist”Create a list
createlist 'name'
Example: createlist 'pets'
pushlist
Section titled “pushlist”Add a value to a list
pushlist 'name' 'value' ['front']
Example: pushlist 'pets' '0x8768766' 'front'
Note: front
is optional, it will be added to the back of the list by default
Add !
modifier(pushlist!
) to only add the item if it is not already in the list
clearlist
Section titled “clearlist”Clear a list of it’s items
clearlist 'name'
removelist
Section titled “removelist”Remove a list
removelist 'name'
rename
Section titled “rename”Rename a pet
rename 'serial' 'name'
Example: rename '0x3435345' 'KillMe'
logout
Section titled “logout”Logout of the game
logout
shownames
Section titled “shownames”Show all names of mobiles
shownames
togglehands
Section titled “togglehands”Equip/Unequip items in hand
togglehands 'left|right
Example: togglehands 'left'
equipitem
Section titled “equipitem”Equip an item using its serial number.
equipitem 'serial'
Example: equipitem '0x40001234'
togglemounted
Section titled “togglemounted”Toggle mounted state for the player.
togglemounted
Example: togglemounted
promptalias
Section titled “promptalias”Prompt the user to set an alias for a targeted object.
promptalias 'name'
Example: promptalias 'myAlias'
waitforgump
Section titled “waitforgump”Wait for a gump to appear.
waitforgump 'gumpID' 'timeout'
Example: waitforgump '1234' '5000'
Gumpid and timeout are both optional. Can use ‘lastgump’ to get the last gump id after using this command.
replygump
Section titled “replygump”Reply to a gump with a specific button ID.
replygump 'buttonid' 'gumpid'
Example: replygump '12' '1234'
Gumpid is optional
closegump
Section titled “closegump”Close a gump.
closegump 'gumpid'
Example: closegump '1234'
This command closes a gump by its ID. If no ID is provided, it defaults to the last gump ID.
clearjournal
Section titled “clearjournal”Clear the journal.
clearjournal
Example: clearjournal
poplist
Section titled “poplist”Remove an item from a list.
poplist 'name' 'value'
Example: poplist 'myList' 'item1'
targettilerel
Section titled “targettilerel”Target a tile relative to the player’s position.
targettilerel 'x' 'y' ['graphic']
Example: targettilerel '1' '2'
or targettilerel '1' '2' '0x1234'
targetlandrel
Section titled “targetlandrel”Target the land relative to the player’s position.
targettilerel 'x' 'y'
Example: targetlandrel '1' '1'
virtue
Section titled “virtue”Invoke a specific virtue.
virtue 'honor|sacrifice|valor'
Example: virtue 'honor'
playmacro
Section titled “playmacro”Play a specified macro.
playmacro 'macroname'
Example: playmacro 'myMacro'
headmsg
Section titled “headmsg”Display a message above an entity’s head.
headmsg 'serial' 'msg'
Example: headmsg 'self' 'Hello, world!'
partymsg
Section titled “partymsg”Send a message to the party chat.
partymsg 'msg'
Example: partymsg 'Hello, party!'
guildmsg
Section titled “guildmsg”Send a message to the guild chat.
guildmsg 'msg'
Example: guildmsg 'Hello, guild!'
allymsg
Section titled “allymsg”Send a message to the alliance chat.
allymsg 'msg'
Example: allymsg 'Hello, allies!'
whispermsg
Section titled “whispermsg”Send a whisper message.
whispermsg 'msg'
Example: whispermsg 'Hello, this is a secret!'
yellmsg
Section titled “yellmsg”Send a yell message.
yellmsg 'msg'
Example: yellmsg 'Hello, everyone!'
emotemsg
Section titled “emotemsg”Send an emote message.
emotemsg 'msg'
Example: emotemsg 'Hello, everyone!'
waitforprompt
Section titled “waitforprompt”Wait for a prompt to appear within a specified timeout.
waitforprompt 'duration'
Example: waitforprompt '5000'
Note: The duration is optional and defaults to 10,000 milliseconds (10 seconds) if not provided.
cancelprompt
Section titled “cancelprompt”Cancel the current prompt.
cancelprompt
Example: cancelprompt
promptresponse
Section titled “promptresponse”Send a response to the current prompt.
promptresponse 'msg'
Example: promptresponse 'This is a response'
contextmenu
Section titled “contextmenu”Send a context menu request and select an option for a specific entity.
contextmenu 'serial' 'option'
Example: contextmenu '0x40001234' '1'
clearignorelist
Section titled “clearignorelist”Clear the ignore list
clearignorelist
ignoreobject
Section titled “ignoreobject”Ignore an object
ignoreobject 'serial
Example: ignoreobject 'self'
Ignorelists are reset when you stop the script. They are only available to that specific script, they are not global.
follow
Section titled “follow”Follow a mobile
follow 'serial'
Example: follow 'enemy'
pathfind
Section titled “pathfind”Pathfind to a position
pathfind 'x' 'y' 'z'
Example: pathfind '1235' '2367' '45'
cancelpathfind
Section titled “cancelpathfind”Cancel pathfinding or auto follow
cancelpathfind
addcooldown
Section titled “addcooldown”Add a cooldown bar with custom text and duration
addcooldown 'text' 'duration ms'
Example: addcooldown 'My Cooldown' '5000'
Expressions
Section titled “Expressions”findtypelist
Section titled “findtypelist”Find items of a specific type in a list and set an alias for the found item.
findtypelist 'listname' 'source' [color] [range]
Example: findtypelist 'myList' '0x40001234'
or findtypelist 'myList' '0x40001234' '0x1234' '5'
Get the current network ping.
ping
Example: if ping > 300
timerexists
Section titled “timerexists”Check if a timer exists
timerexists
‘123bandage’
returns true
/false
timerexpired
Section titled “timerexpired”Check if a timer has expired
timerexpired
‘123bandage’
Example: if timerexpired '123bandage'
findtype
Section titled “findtype”Find an object by type
findtype 'graphic' 'source' [color] [range]
Example: if findtype '0x1bf1' 'any' 'anycolor' '2' > 0
<- Find items in containers or ground within 2 tiles
If an object is found, you can use found
alias to reference it.
findalias
Section titled “findalias”Find an object you set as an alias
findalias 'backpack'
Example: if findalias 'myalias'
If found, you can use found
to reference it.
Get the value or a skill
skill 'name' [true/false]
false is default, returns value, true returns base
Example: if skill 'mining' >= 75
poisoned
Section titled “poisoned”Get poisoned status of mobile
posioned [serial]
If serial is not included, it will check your personal poisoned status
Example: if poisoned
or if poisoned 'pet'
Check if you are in warmode
war
Example: if war
contents
Section titled “contents”Count the contents of a container(Top level only)
contents 'container'
Example: if contents 'backpack' > 10
Note: This counts a stack as a single item, so 10 stacks of 30 would only return 10 items.
findobject
Section titled “findobject”Try to find an object by serial
findobject 'serial' [container]
Example: if findobject 'bank'
or if findobject '0x4245364' 'backpack'
distance
Section titled “distance”Get the distance of an item or mobile
distance 'enemy'
Example: if distance 'enemy' < 7
injournal
Section titled “injournal”Check if text exists in journal
injournal 'search text, case sensitive
Example: if injournal 'You see'
inparty
Section titled “inparty”Check if a mobile is in your party
inparty 'serial'
Example: if inparty 'self'
property
Section titled “property”Search properties of an item for text
property 'serial' 'text'
Example: if property 'found' 'Fencing +3'
buffexists
Section titled “buffexists”Check if a buff is active
buffexists 'name'
Example: if buffexists 'weak'
Note: name can be a partial match
findlayer
Section titled “findlayer”Check if there is an item in a layer
findlayer 'layername
Example: if findlayer 'onehanded'
Note: If an item is found, you can use ‘found’ to access it.
onehanded | twohanded | shoes |
---|---|---|
pants | shirt | helmet |
gloves | ring | talisman |
necklace | hair | waist |
torso | bracelet | face |
beard | tunic | earrings |
arms | cloak | backpack |
robe | skirt | legs |
mount | bank |
gumpexists
Section titled “gumpexists”Check if a gump is open
gumpexists 'gumpid'
Example: if gumpexists '1915258020'
listcount
Section titled “listcount”Count the number of items in a list. Will return 0 if the list does not exist
listcount 'name'
Example: if listcount 'pets'
listexists
Section titled “listexists”Check if a list exists
listexists 'name'
Example: if not listexists 'pets'
inlist
Section titled “inlist”Check if a list contains a value
inlist 'name' 'value'
Example: if inlist 'pets' '0x4532345'
nearesthostile
Section titled “nearesthostile”Find the nearest hostile(Gray, criminal, murderer, enemy)
nearesthostile ['distance']
Example: if nearesthostile
Note: if a hostile was found, you can use 'found'
to reference it
counttype
Section titled “counttype”Get the count of a type of item in a container
counttype 'graphic' 'source' ['hue'] ['ground range']
Example: while counttype '0x1bf3' 'backpack' > 3
Check if a mobile is dead
dead ['serial']
Example: if dead
Not: If you don’t include serial, it will default to yourself
itemamt
Section titled “itemamt”Get the amount of an item by its serial number.
itemamt 'serial'
Example: itemamt '0x40001234'
primaryabilityactive
Section titled “primaryabilityactive”Check if primary ability is active
primaryabilityactive
Example: if primaryabilityactive
secondaryabilityactive
Section titled “secondaryabilityactive”Check if secondary ability is active
secondaryabilityactive
Example: if secondaryabilityactive
mounted
Section titled “mounted”Check if the player is mounted.
mounted
Example: if mounted
paralyzed
Section titled “paralyzed”Check if a player or mobile is paralyzed.
paralyzed 'serial'
Example: if paralyzed
Note: serial
is optional, if omitted it will check yourself.
pathfinding
Section titled “pathfinding”Check if you are actively pathfinding or following
pathfinding
Example: if pathfinding
nearestcorpse
Section titled “nearestcorpse”Find the nearest corpse. If found it will be set to found
nearestcorpse
Example: if nearestcorpse
Aliases
Section titled “Aliases”Values
Section titled “Values”name
hits
,maxhits
,diffhits
<-- These support a 'serial' parameter
stam
,maxstam
,diffstam
mana
,maxmana
,diffmana
x
,y
,z
str
,dex
,int
followers
,maxfollowers
gold
,hidden
weight
,maxweight
mounted
true
,false
found
<- Available when using commands like findtype
count
<- Available when using commands like findtype
Objects
Section titled “Objects”backpack
bank
lastobject
lasttarget
lefthand
righthand
mount
self
bandage
any
<- Can be used in place of containers
anycolor
<- Match any hue
Syntax
Section titled “Syntax”if 'condition'
elseif 'condition'
else
endif
while 'condition'
endwhile
for 'count'
endfor
foreach 'item' in 'list'
endfor
break
, continue
stop
<- Stop the script
replay
<- Start the script over
goto 'line'
and return
These should work together, if you don’t have an equal amount of goto and returns it will end up causing you issues with your script.
Lines start at 0, if your editor starts at line 1 remember to -1.
Here is an example to demonstrate using them nest:
sysmsg 'This is a test of the goto functionality'
for 3 goto '7'endforstop
sysmsg 'Oo test is worky!'goto '11'return
headmsg 'self' 'This works too!'return