In the old days when I mudded, I had no real need for macros, but the complexity of the command system on this game, I felt I needed to.
After utterly failing to get anything to work in CMud, I tried Mudlet, and have had a lot of success and have a basic macro system in place which seems to work well.
I was wondering if there was a better way to do it, or if I was making things too complicated
To start with, I have a prompt trigger which matches on:
Code: Select all
(\d+)h, +(\d+)e, +(\d+)f (.*)(A: (.*))*-
Code: Select all
status = {
health = tonumber(matches[2]),
endurance = tonumber(matches[3]),
faith = tonumber(matches[4]),
flags = matches[5],
balance = true,
equilibrium = true
}
if string.find(status.flags, "x") ~= nil then
status.equilibrium = true
else
status.equilibrium = false
end
if string.find(status.flags, "b") ~= nil then
status.balance = true
else
status.balance = false
end
It's basically:
Code: Select all
function get_target2(command, input)
target = ""
if matches[1] == command then
target = "self"
else
target = input
end
return target
end
function do_buff_prayer(command, input, faith_cost, self_action, other_action)
target = get_target2(command, input)
if not status.balance then
echo("You do not yet have balance.")
else
if not status.equilibrium then
echo("You do not yet have equilibrium.")
else
if faith_cost > 0 and status.faith < faith_cost then
echo("Insufficient faith.")
else
if target == "self" then
self_action()
else
other_action(target)
end
end
end
end
end
Code: Select all
^h( (.*))*$
Code: Select all
do_buff_prayer("h", matches[3], 30,
function()
send("pray for healing")
end,
function(target)
send("pray for healing of "..target)
end
)
Code: Select all
saved_target = ""
function get_target(command, input)
target = ""
if matches[1] == command then
if saved_target ~= "" then
target = saved_target
else
target = ""
end
else
target = input
end
return target
end
function do_targeted_prayer(command, input, faith_cost, balance, equilibrium, action)
target = get_target(command, input)
if target == "" then
echo("Target required.")
else
if balance and not status.balance then
echo("You do not yet have balance.")
else
if equilibrium and not status.equilibrium then
echo("You do not yet have equilibrium.")
else
if faith_cost > 0 and status.faith < faith_cost then
echo("Insufficient faith.")
else
action(target)
end
end
end
end
end
An example command is a pattern of:
Code: Select all
^f( (.*))*$
Code: Select all
do_targeted_prayer("f", matches[3], 0, true, false,
function(target)
send("smite "..target.." with fury")
end
)
Thoughts? Is there a better way to approach these problems?
Thanks in advance.