Script File Types
Lich supports multiple script file formats:
.lic - Standard Lich script format (Ruby with label support)
.rb - Pure Ruby scripts
.cmd / .wiz - Legacy Wizard script format (automatically converted)
Scripts are stored in your script directory, typically scripts/ or scripts/custom/ for personal scripts.
Basic Script Structure
Simple Ruby Script (.rb)
# Basic information about your script
# author: Your Name
# version: 1.0.0
# Access current script
script = Script . current
# Output to user
echo "Script started with args: #{ script. vars . join ( ', ' ) } "
# Send command to game
put "look"
# Wait for game response
waitfor "Obvious"
echo "Script complete"
Label-Based Script (.lic)
Lich scripts support goto labels for flow control:
# version: 1.0.0
echo "Starting main loop"
main_loop:
result = waitfor "health" , "mana"
if result =~ /health/
echo "Health check triggered"
goto :heal
elsif result =~ /mana/
echo "Mana check triggered"
goto :rest
end
goto :main_loop
heal:
fput "drink my potion"
goto :main_loop
rest:
fput "sit"
pause 10
fput "stand"
goto :main_loop
Script Arguments
Scripts can access command-line arguments through script.vars:
script = Script . current
# script.vars[0] contains all arguments as a single string
# script.vars[1..n] contains individual arguments
echo "All args: #{ script. vars [ 0 ] } "
echo "First arg: #{ script. vars [ 1 ] } "
echo "Second arg: #{ script. vars [ 2 ] } "
# Example usage: ;example arg1 arg2 arg3
# Output:
# All args: arg1 arg2 arg3
# First arg: arg1
# Second arg: arg2
Quiet Mode
Scripts can run silently without start/stop messages:
# Method 1: First line of script
quiet
# Method 2: Set programmatically
script = Script . current
script. quiet = true
# Method 3: Start with quiet flag
start_script ( "example" , [], { quiet: true })
Version Declaration
Declare your script version in comments at the top:
# version: 2.1.5
# author: Your Name
# tags: hunting, utility
Check script versions programmatically:
if Script . version ( "dependency_script" , "1.5.0" )
echo "dependency_script needs to be updated"
exit
end
Place metadata in a comment block at the top of your script for easy discovery and maintenance.
=begin
Script: example_hunter
Author: Your Name
Version: 1.2.0
Description:
Automated hunting script with safety checks
Usage:
;example_hunter <creature_type>
Required:
- go2 script
- combat-trainer script
=end
# Your script code here
Common Patterns
Main Loop Pattern
loop do
line = get
if line =~ /You are hungry/
fput "eat my rations"
elsif line =~ /You are tired/
break
end
end
echo "Script exiting"
State Machine Pattern
state = :hunting
loop do
case state
when :hunting
if Char . mana < 20
state = :resting
else
fput "attack creature"
end
when :resting
fput "rest"
wait_until { Char . mana > 80 }
state = :hunting
end
end
Configuration Pattern
# Use Settings hash for persistent configuration
Settings [ :healing_threshold ] ||= 50
Settings [ :rest_location ] ||= "town square"
# Save on exit
before_dying {
Settings . save
}
# Access in script
if Char . health < Settings [ :healing_threshold ]
echo "Health below threshold, healing..."
end
Best Practices
Use Descriptive Names Choose clear, descriptive script names that indicate their purpose
Version Your Scripts Always include version information in your script comments
Handle Errors Use begin/rescue blocks to handle unexpected situations gracefully
Document Usage Include usage instructions in script comments for future reference
Next Steps
Script Lifecycle Learn about script startup, termination, and cleanup
Global Methods Explore available methods for game interaction
Hooks Intercept and modify game data with hooks
Threading Create multi-threaded scripts for complex automation