Skip to content

Instantly share code, notes, and snippets.

@blakepell
Last active February 23, 2020 03:31
Show Gist options
  • Save blakepell/0af993ecad9c832bd34f9d1eab7e32fa to your computer and use it in GitHub Desktop.
Save blakepell/0af993ecad9c832bd34f9d1eab7e32fa to your computer and use it in GitHub Desktop.
Avalon Mud Client (Lua): Alias to mass inspect items in a shop
-- Trigger pattern:
-- Condition: excellent \((95|96|97|98|99|100)%\)
global.inspect_results[%1] = global.inspect_results[%1] .. global.inspect_counter .. ","
-- Echo the number we're on above the item.
lua:EchoEvent("#" .. global.inspect_counter .. " is " .. %1 .. "%")
{
"AliasList": [
{
"AliasExpression": "shop-inspect",
"Command": "-- Syntax: mass-inspect <start index> <end index> <keyword>\r\n\r\n-- The triggers for these only run when the inspection is happening so they save\r\n-- having to be processed all of the time.\r\nlua:EnableGroup(\"Inspect\")\r\n\r\n-- Reset the counter\r\nglobal.inspect_counter = 0\r\nglobal.inspect_results = { }\r\nglobal.inspect_results[95] = \"\"\r\nglobal.inspect_results[96] = \"\"\r\nglobal.inspect_results[97] = \"\"\r\nglobal.inspect_results[98] = \"\"\r\nglobal.inspect_results[99] = \"\"\r\nglobal.inspect_results[100] = \"\"\r\n\r\n-- Setup the keyword, if it has two values make sure both get there\r\n-- e.g. mithril dagger and not just mithril\r\nlocal keyword = \"%3\"\r\n\r\nif \"%4\" ~= \"\" then\r\n\tkeyword = keyword .. \" %4\"\r\nend\r\n\r\n-- Loop through all of the items requested.\r\nfor i = %1, %2, 1 \r\ndo\r\n\t-- The global will allow us to echo what number the item is\r\n\t-- when the trigger hits\r\n\tglobal.inspect_counter = i\r\n\t\r\n\t-- Send the inspect command to the game\r\n lua:Send(\"inspect \" .. i .. \".\" .. keyword)\r\n \r\n -- Important, we pause for a half a second, this is important because the game\r\n -- has to respond so we can echo to the terminal if there is a match and what\r\n -- index that match was (so the person can buy that specific item). Increase\r\n -- this number on laggy connections or if they're not getting the data back from\r\n -- the mud in time.\r\n lua:Sleep(750)\r\nend\r\n\r\n-- Display the output of the results of what the trigger collected.\r\nlua:Echo(\"Inspection Results for \" .. \"%3 at \" .. lua:GetVariable(\"Room\"))\r\nlua:Echo(\"-------------------------------------------------------------------\")\r\n\r\nfor i = 100, 95, -1\r\ndo\r\n\tlua:Echo(i .. \"%\")\r\n\tlua:Echo(lua:TrimEnd(lua:Coalesce(global.inspect_results[i], \"None\"), \",\"))\r\n\tlua:Echo(\"\")\r\nend\r\n\r\n-- Cleanup the results.\r\nglobal.inspect_results = { }\r\n\r\n-- Disable the inspection trigger so it doesn't fire on a regular basis\r\nlua:DisableGroup(\"Inspect\")",
"Enabled": true,
"Character": "",
"Group": "",
"IsLua": true,
"Count": 31
}
],
"TriggerList": [
{
"Command": "global.inspect_results[%1] = global.inspect_results[%1] .. global.inspect_counter .. \",\"\r\n\r\n-- Echo the number we're on above the item.\r\nlua:EchoEvent(\"#\" .. global.inspect_counter .. \" is \" .. %1 .. \"%\")",
"Pattern": "Condition: excellent \\((95|96|97|98|99|100)%\\)",
"Character": "",
"Group": "Inspect",
"IsSilent": false,
"IsLua": true,
"Plugin": false,
"VariableReplacement": false,
"Enabled": false,
"Gag": false,
"MoveTo": 0,
"HighlightLine": false,
"Count": 0,
"Identifier": "1317e74b-66e0-41ac-bfbb-0481416819f9"
}
]
}
-- Syntax: mass-inspect <start index> <end index> <keyword>
-- The triggers for these only run when the inspection is happening so they save
-- having to be processed all of the time.
lua:EnableGroup("Inspect")
-- Reset the counter
global.inspect_counter = 0
global.inspect_results = { }
global.inspect_results[95] = ""
global.inspect_results[96] = ""
global.inspect_results[97] = ""
global.inspect_results[98] = ""
global.inspect_results[99] = ""
global.inspect_results[100] = ""
-- Setup the keyword, if it has two values make sure both get there
-- e.g. mithril dagger and not just mithril
local keyword = "%3"
if "%4" ~= "" then
keyword = keyword .. " %4"
end
-- Loop through all of the items requested.
for i = %1, %2, 1
do
-- The global will allow us to echo what number the item is
-- when the trigger hits
global.inspect_counter = i
-- Send the inspect command to the game
lua:Send("inspect " .. i .. "." .. keyword)
-- Important, we pause for a half a second, this is important because the game
-- has to respond so we can echo to the terminal if there is a match and what
-- index that match was (so the person can buy that specific item). Increase
-- this number on laggy connections or if they're not getting the data back from
-- the mud in time.
lua:Sleep(750)
end
-- Display the output of the results of what the trigger collected.
lua:Echo("Inspection Results for " .. "%3 at " .. lua:GetVariable("Room"))
lua:Echo("-------------------------------------------------------------------")
for i = 100, 95, -1
do
lua:Echo(i .. "%")
lua:Echo(lua:TrimEnd(lua:Coalesce(global.inspect_results[i], "None"), ","))
lua:Echo("")
end
-- Cleanup the results.
global.inspect_results = { }
-- Disable the inspection trigger so it doesn't fire on a regular basis
lua:DisableGroup("Inspect")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment