Posted by
| Nick Gammon
Australia (22,975 posts) bio
Forum Administrator |
Message
| Well, this was an interesting one. :)
The script seemed to call out for an automated conversion, so I wrote a little script to run in the Immediate window to do that.
That looks like this:
cmud_script = [=[
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
... blah blah - the Cmud script from your post goes here ...
</cmud>
]=]
require "getlines"
require "addxml"
function fix_send (send)
local need_pause = string.match (send, "#wait")
local script = ""
if need_pause then
script = [[
require "wait"
wait.make (function ()
]]
end -- if
for line in getlines (send) do
local time = string.match (line, "#wait (%d+)")
if time then
script = script .. string.format ("wait.time (%.1f)\n", time / 1000)
else
script = script .. 'Execute ("' .. line .. '")\n'
end -- if
end -- for loop
if need_pause then
script = script .. "end)"
end -- if
return script
end -- fix_send
-- CONVERT ALIASES
count = 0
for alias in string.gmatch (cmud_script, "<alias (.-) </alias>") do
match = assert (string.match (alias, 'name="(%w+)"'), "No match")
send = assert (string.match (alias, '<value>(.*)</value>'), "No send")
script = fix_send (send)
-- add the alias
addxml.alias {
match = match,
send = script,
sequence = 100,
enabled = true,
name = match,
send_to = sendto.script,
group = "fishing"
}
count = count + 1
end -- for
print ("added", count, "aliases")
-- CONVERT TRIGGERS
count = 0
for trigger in string.gmatch (cmud_script, "<trigger (.-) </trigger>") do
local omit = false
local send_to = sendto.script
match = assert (string.match (trigger, '<pattern>(.-)</pattern>'), "No match")
send = assert (string.match (trigger, '<value>(.*)</value>'), "No send")
sequence = assert (string.match (trigger, 'priority="(.-)"'), "No priority")
if send == "#gag" then
omit = true
send_to = sendto.world
script = ""
else
script = fix_send (send)
end -- if
-- add the trigger
count = count + 1
addxml.trigger {
match = match,
send = script,
sequence = tonumber (sequence),
enabled = true,
name = "fishing" .. count,
send_to = send_to,
regexp = "y",
omit_from_output = omit,
group = "fishing"
}
end -- for
print ("added", count, "triggers")
I used a few Lua string matches to do a crude XML parse. This broke up the script into individual aliases and triggers. Then for each one it extracted out the match text, and what to send.
The tricky part was the frequent use of the #wait statement, which I am guessing pauses a CMud script for x milliseconds. We can do something similar in MUSHclient in a script as described here:
Running the script displayed:
added 5 aliases
added 32 triggers
The resulting aliases were:
<aliases>
<alias
name="bhb"
match="bhb"
enabled="y"
group="fishing"
send_to="12"
sequence="100"
>
<send>require "wait"
wait.make (function ()
Execute ("take bass from tank")
wait.time (2.1)
Execute ("bait hook with bass")
wait.time (4.0)
Execute ("cls")
wait.time (4.0)
Execute ("tl")
end)</send>
</alias>
<alias
name="cls"
match="cls"
enabled="y"
group="fishing"
send_to="12"
sequence="100"
>
<send>Execute ("cast line short")
</send>
</alias>
<alias
name="rel"
match="rel"
enabled="y"
group="fishing"
send_to="12"
sequence="100"
>
<send>Execute ("reel line")
</send>
</alias>
<alias
name="sfm"
match="sfm"
enabled="y"
group="fishing"
send_to="12"
sequence="100"
>
<send>require "wait"
wait.make (function ()
Execute ("gen")
wait.time (1.1)
Execute ("sell hugefish to malusine")
wait.time (1.1)
Execute ("self")
end)</send>
</alias>
<alias
name="tl"
match="tl"
enabled="y"
group="fishing"
send_to="12"
sequence="100"
>
<send>Execute ("tease line")
</send>
</alias>
</aliases>
The resulting triggers were:
<triggers>
<trigger
enabled="y"
group="fishing"
match="you feel a fish nibbling on your hook"
name="fishing1"
regexp="y"
send_to="12"
sequence="2050"
>
<send>require "wait"
wait.make (function ()
wait.time (2.0)
Execute ("tease line")
end)</send>
</trigger>
<trigger
enabled="y"
group="fishing"
match="medium strike at your bait"
name="fishing2"
regexp="y"
send_to="12"
sequence="2060"
>
<send>require "wait"
wait.make (function ()
wait.time (1.9)
Execute ("jerk pole")
end)</send>
</trigger>
<trigger
enabled="y"
group="fishing"
match="small strike at your bait"
name="fishing3"
regexp="y"
send_to="12"
sequence="2070"
>
<send>require "wait"
wait.make (function ()
wait.time (1.9)
Execute ("jerk pole")
end)</send>
</trigger>
<trigger
enabled="y"
group="fishing"
match="you stagger as a fish"
name="fishing4"
regexp="y"
send_to="12"
sequence="2090"
>
<send>require "wait"
wait.make (function ()
wait.time (1.9)
Execute ("jerk pole")
end)</send>
</trigger>
<trigger
enabled="y"
group="fishing"
match="you see the watter ripple"
name="fishing5"
regexp="y"
send_to="12"
sequence="2100"
>
<send>require "wait"
wait.make (function ()
wait.time (1.8)
Execute ("jerk pole")
end)</send>
</trigger>
<trigger
enabled="y"
group="fishing"
match="relaxing the tension on your line"
name="fishing6"
regexp="y"
send_to="12"
sequence="2110"
>
<send>Execute ("reel line")
</send>
</trigger>
<trigger
enabled="y"
group="fishing"
match="You feel the fish tugging on your line"
name="fishing7"
regexp="y"
send_to="12"
sequence="2120"
>
<send>Execute ("reel line")
</send>
</trigger>
<trigger
enabled="y"
group="fishing"
match="but the hook pulls free of the fish"
name="fishing8"
regexp="y"
send_to="12"
sequence="2130"
>
<send>require "wait"
wait.make (function ()
wait.time (2.0)
Execute ("tease line")
end)</send>
</trigger>
<trigger
enabled="y"
group="fishing"
match="The fish you've hooked struggles"
name="fishing9"
regexp="y"
send_to="12"
sequence="2140"
>
<send>Execute ("reel line")
</send>
</trigger>
<trigger
enabled="y"
group="fishing"
match="The fish tries to swim"
name="fishing10"
regexp="y"
send_to="12"
sequence="2160"
>
<send>Execute ("reel line")
</send>
</trigger>
<trigger
enabled="y"
group="fishing"
match="Your fish struggl"
name="fishing11"
regexp="y"
send_to="12"
sequence="4270"
>
<send>Execute ("reel line")
</send>
</trigger>
<trigger
enabled="y"
group="fishing"
match="Relaxing the tension on your line, you are able to reel again.$"
name="fishing17"
omit_from_output="y"
regexp="y"
sequence="5830"
>
</trigger>
<trigger
enabled="y"
group="fishing"
match="You quickly jerk back your fishing pole and feel the line go taut"
name="fishing12"
regexp="y"
send_to="12"
sequence="5840"
>
<send>require "wait"
wait.make (function ()
wait.time (2.4)
Execute ("rel")
end)</send>
</trigger>
<trigger
enabled="y"
group="fishing"
match="As the fish strains your line beyond its breaking point"
name="fishing13"
regexp="y"
send_to="12"
sequence="5850"
>
<send>require "wait"
wait.make (function ()
wait.time (4.1)
Execute ("bhb")
end)</send>
</trigger>
<trigger
enabled="y"
group="fishing"
match="With a short dipping and raising motion, you tease your fishing line.$"
name="fishing18"
omit_from_output="y"
regexp="y"
sequence="5860"
>
</trigger>
<trigger
enabled="y"
group="fishing"
match="You quickly jerk back your fishing pole, but the hook pulls free of the fish.$"
name="fishing19"
omit_from_output="y"
regexp="y"
sequence="5870"
>
</trigger>
<trigger
enabled="y"
group="fishing"
match="You are already reeling in your fish."
name="fishing20"
omit_from_output="y"
regexp="y"
sequence="5880"
>
</trigger>
<trigger
enabled="y"
group="fishing"
match="With a final tug, you finish"
name="fishing14"
regexp="y"
send_to="12"
sequence="5890"
>
<send>require "wait"
wait.make (function ()
wait.time (3.2)
Execute ("bhb")
end)</send>
</trigger>
<trigger
enabled="y"
group="fishing"
match="You furiously reel in your line, straining to land your fish"
name="fishing21"
omit_from_output="y"
regexp="y"
sequence="5900"
>
</trigger>
<trigger
enabled="y"
group="fishing"
match="You move your fishing pole quickly back and forth hoping to excite the interest"
name="fishing22"
omit_from_output="y"
regexp="y"
sequence="5910"
>
</trigger>
<trigger
enabled="y"
group="fishing"
match="You tease your fishing line gingerly.$"
name="fishing23"
omit_from_output="y"
regexp="y"
sequence="5920"
>
</trigger>
<trigger
enabled="y"
group="fishing"
match="With a slow and steady motion you reel in a length of line, straining against $"
name="fishing24"
omit_from_output="y"
regexp="y"
sequence="5930"
>
</trigger>
<trigger
enabled="y"
group="fishing"
match="Jerking the line quickly, you let the fish feel your power as you reel it in. "
name="fishing25"
omit_from_output="y"
regexp="y"
sequence="5940"
>
</trigger>
<trigger
enabled="y"
group="fishing"
match="of line left to bring in.$"
name="fishing26"
omit_from_output="y"
regexp="y"
sequence="5950"
>
</trigger>
<trigger
enabled="y"
group="fishing"
match="Playing your fishing pole skilfully, you take up the slack and reel in some $"
name="fishing27"
omit_from_output="y"
regexp="y"
sequence="5960"
>
</trigger>
<trigger
enabled="y"
group="fishing"
match="Your rod bends slightly as your fish tries to escape its barbed tether, running $"
name="fishing28"
omit_from_output="y"
regexp="y"
sequence="5970"
>
</trigger>
<trigger
enabled="y"
group="fishing"
match="You reel in the last bit of line"
name="fishing15"
regexp="y"
send_to="12"
sequence="5980"
>
<send>require "wait"
wait.make (function ()
wait.time (3.5)
Execute ("bhb")
end)</send>
</trigger>
<trigger
enabled="y"
group="fishing"
match="With a style born of skill, you"
name="fishing16"
regexp="y"
send_to="12"
sequence="5990"
>
<send>require "wait"
wait.make (function ()
wait.time (4.8)
Execute ("bhb ")
end)</send>
</trigger>
<trigger
enabled="y"
group="fishing"
match="With a pull that threatens to rip the pole from your hand, the fish you've $"
name="fishing29"
omit_from_output="y"
regexp="y"
sequence="6180"
>
</trigger>
<trigger
enabled="y"
group="fishing"
match="Your fish struggles and swims firmly away from you"
name="fishing30"
omit_from_output="y"
regexp="y"
sequence="6190"
>
</trigger>
<trigger
enabled="y"
group="fishing"
match="You quickly reel in a"
name="fishing31"
regexp="y"
send_to="12"
sequence="6560"
>
<send>require "wait"
wait.make (function ()
wait.time (4.3)
Execute ("bhb")
end)</send>
</trigger>
<trigger
enabled="y"
group="fishing"
match="{bass(%d)}"
name="fishing32"
regexp="y"
send_to="12"
sequence="9680"
>
<send>Execute ("{#math fishweight")
Execute ("{@fishweight + %1}}")
Execute ("")
</send>
</trigger>
</triggers>
|
For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.
|
It may not be perfect, but you can tweak the script if necessary. You will definitely need to change the last trigger (the one that does #math fishweight) because this needs to be converted to the way MUSHclient does maths in a script. I'll leave that as an exercise. ;) |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | top |
|