Ares doesn’t allow you to alter the game code from the MU client window, but sometimes you need to do things that aren’t covered by an existing command - find all characters over 30 years old, update the faction on a bunch of people at once, etc. There’s no need to create specific commands for this sort of tinkering, especially if you’re unlikely to do that specific task ever again. In Ares, you can use the ruby
command to execute simple code blocks, or the tinker
command to perform more involved processing.
coder
role. This is a security feature, because giving someone access to run arbitrary code essentially gives them the keys to the kingdom. They could do literally anything with the database.
Table of Contents
The ruby
command lets you run simple Ruby code snippets straight from your MU client. Separate multiple lines with semicolons. For example:
ruby c = Character.find_one_by_name("Faraday");c.update_demographic("hair","blonde")
Doing a lot of code on a single line can be cumbersome. That’s where the tinker
command comes in. Tinker is a built-in command that does nothing by default. You update the command code to do whatever you need at that moment. Unlike other commands, the tinker code can be easily updated through the web portal.
Tinkering involves three steps:
tinker
in-game to run the code.aresmush/plugins/tinker/commands/tinker_cmd.rb
then reload the code using load tinker
in-game.
Let’s say you wanted to write a quick code snippet to find all the characters who are 30 years or older. All you need to do is modify the handle
method to find those characters and emit their names to you.
For example:
def handle
client.emit Character.all.select { |c| c.age >= 30 }.map { |c| "#{c.name} - #{c.age}" }
client.emit_success "Done!"
end
You can also use the tinker command to update things in the database. For example, if you wanted to change Bob’s hair color (and didn’t want to use the demographic/set command because that would be too easy):
def handle
char = Character.find_one_by_name("Bob")
char.update_demographic("hair", "Gray" )
client.emit_success "Done!"
end
You can even combine the two - a query and an update - to act on a list of characters. Say you changed a faction’s name and wanted to update everyone with the old faction name to the new one:
def handle
chars = Character.all.select { |c| c.group("Faction") == "Old Faction" }
chars.each do |c|
Demographics.set_group(c, "Faction", "New Faction")
end
client.emit_success "Done!"
end
Tinkering is set up with the assumption that only one person will be tinkering at a time, because frankly most games only have one coder. In the remarkable event that you have multiple coders wanting to tinker at the same time, they’ll just have to take turns or create their own personal tinker commands.