# Using Script.at_exitScript.at_exit do echo "Cleaning up resources..." fput "stance defensive" Settings.saveend# Using before_dying helperbefore_dying { echo "Script is exiting" # Restore original state fput "remove my weapon"}# Multiple callbacks are supportedScript.at_exit { echo "First cleanup" }Script.at_exit { echo "Second cleanup" }
Callbacks are executed in the order they were registered. If a callback raises an error, subsequent callbacks will still run.
# Check if script is runningif Script.running?("other_script") Script.kill("other_script")end# Using helper methodstop_script("script1", "script2")# Check running statusif running?("combat_script", "healing_script") echo "All required scripts are running"end
Automatically kill other scripts when current script exits:
# These scripts will be killed when current script exitsdie_with_me("helper_script", "support_script")# Via script propertyscript = Script.currentscript.die_with.push("dependent_script")
# Hide current script from ;listscriptshide_me# Hide another scripthide_script("background_script")# Scripts in script.hidden are still accessibleall_scripts = Script.running + Script.hidden
# Get all visible running scriptsScript.running.each do |s| echo "Running: #{s.name}"end# Get all scripts (including hidden)Script.list.each do |s| echo "#{s.name} (hidden: #{s.hidden})"end# Get only hidden scriptsScript.hidden.each do |s| echo "Hidden: #{s.name}"end
script = Script.current# Get script's thread groupthread_group = script.thread_group# Check if thread belongs to scriptif script.has_thread?(Thread.current) echo "This thread belongs to the script"end# List all threads in scriptscript.thread_group.list.each do |thread| echo "Thread: #{thread.inspect}"end