Hi Nick and all,
Thanks for your previous advice on the scripting and I'm playing the MUD much better than 20 years ago (yes the same MUD I played when I was a child lol)
Recently I found some old Lua code and want to revise it for my char, while it cannot work so want to consult you:
- Goal: auto perform/cast when enter a fight
- If the 1st attempt fails, then auto perform/cast again until succeeds
- Multiple criteria of failure and success
The following are my codes and appreciate your help to advise where goes wrong:
New self-defined function 1: if ts/tw matched, return true; if fs/fw matched, return false
function mywait(ts, fs, tw, fw)
local expr = "^(" .. table.concat(ts, "|") .. "|" .. table.concat(fs, "|") .. ")$"
local l, w = wait.regexp(expr)
if not l then return false end
if tw then
for _, v in pairs(tw) do
if string.find(l, v) then return true end
end
end
if fw then
for _, v in pairs(fw) do
if string.find(l, v) then return false end
end
end
for _, v in pairs(fs) do
if string.find(l, v) then return false end
end
for _, v in pairs(ts) do
if string.find(l, v) then return true end
end
return true
end
New self-defined function 2
function myrepeat(cmd, ts, fs, tw, fw, t)
repeat
Execute(cmd)
local rpt = mywait(ts, fs, tw, fw)
if rpt and t then
wait.time(t)
end
until not rpt
end
New Mushclient variable "pfm": pfm boundary
Auto perform script: same for auto_cast
function auto_pfm()
local p = "p"
if var.pfm and var.pfm ~= "" then p = var.pfm end
myrepeat(p, {"xxx1", "xxx2"}, {"yyy1", "yyy2", "yyy3", "yyy4"}, nil, nil, 0.5)
if f then f() end
end
Note
- xxx1, xxx2: criteria of failed perform (i.e. the auto perform script should continue executing if "xxx1" and "xxx2" appear)
- yyy1, yyy2, yyy3, yyy4: criteria of successful perform (i.e. the auto perform script should stop if "yyy1~4" appear)
- xxx1, xxx2, yyy1, yyy2, yyy3, yyy4 are in traditional Chinese (with regular expression) so I don't put the original words here, while I tested them via regex101 as well as new Muchclient triggers and both methods work fine
After trial and errors for 2 weeks, I still cannot make the script work as what I expect so would like to seek for your opinion to improve them. Thanks. |