[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Plugins
. . -> [Subject]  Aardwolf scan in a miniwindow
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Aardwolf scan in a miniwindow

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Blainer   (191 posts)  [Biography] bio
Date Sat 10 Oct 2009 06:38 AM (UTC)

Amended on Mon 16 Nov 2009 10:26 PM (UTC) by Blainer

Message
Plugin to display the output from the "scan" command in a miniwindow with keywords stored in a database highlighted.

-Quest and campaign mobiles
Quest and Campaign mobiles are added and remove automatically. Every time a quest or campaign mobile is killed all keywords for that group are
removed and the remaining mobiles are added again.

-Multiple characters
The plugin will make a database in the world files directory at install based on the the player name set in Game - > Configure -> Connecting.
If the player name is blank the script will use the name of the title of the world file. If you have a world file for each character this should
allow for multiple characters.

-Adding and removing keywords
The script highlights words stored in a database when found in the scan output. "sl ?" command has syntax to add or remove them from the
command line.

This trigger will add your friends to the database with the colour green ever time you enter the friends command.
<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   match="\s{2}\d+\)\s\-\s(\w+)\s*\(.+\)"
   name="Friend_Trigger"
   regexp="y"
   send_to="10"
   sequence="100"
  >
  <send>addkey %1 green friend</send>
  </trigger>
</triggers>

Here is simple trigger that fires on "Some text with a keyword and stuff." and adds the word keyword with the colour purple in NewGroup.
<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   match="Some text with a * and stuff."
   name="AutoAddSomething"
   send_to="10"
   sequence="100"
  >
  <send>addkey %1 purple NewGroup</send>
  </trigger>
</triggers>


-Turn auto scanning on and off
The plugin has an alias "sl on|off" that turns auto scanning on and off. The script will catch the command when sent through Execute.
This alias will turn off auto scanning before recalling.
<aliases>
  <alias
   name="travel_home"
   match="travel home"
   enabled="y"
   send_to="10"
   sequence="100"
  >
  <send>
   sl off
   recall
  </send>
  </alias>
</aliases>

This alias will turn auto scanning on before speedwalking. If I enter "travel verume" the script will run to "Jungles of Verume" and
auto scanning will be turned on.
<aliases>
  <alias
   name="travel"
   match="travel *"
   expand_variables="y"
   enabled="y"
   send_to="10"
   sequence="101"
  >
  <send>
   recall
   runto %1
   sl on
  </send>
  </alias>
</aliases>

Template:pasting For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.


-Installing
This plugin replaces Look_Scan.xml (http://www.gammon.com.au/forum/?id=9625).
The plugin will not install until this plugin has been removed and MUSH has been re-started.
A bunch of tags will be left on by Look_Scan.xml (sorry) the commands below will turn them off.
tags EXITS off
tags ROOMDESCS off
tags ROOMNAMES off
tags ROOMCHARS off
tags ROOMOBJS off


Template:saveplugin=Aardwolf_Scan_Window To save and install the Aardwolf_Scan_Window plugin do this:
  1. Copy between the lines below (to the Clipboard)
  2. Open a text editor (such as Notepad) and paste the plugin into it
  3. Save to disk on your PC, preferably in your plugins directory, as Aardwolf_Scan_Window.xml
  4. Go to the MUSHclient File menu -> Plugins
  5. Click "Add"
  6. Choose the file Aardwolf_Scan_Window.xml (which you just saved in step 3) as a plugin
  7. Click "Close"

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Thursday, July 16, 2009, 9:58 PM -->
<!-- MuClient version 4.42 -->
<!-- Plugin "Scan_Window" generated by Plugin Wizard -->
<muclient>
<plugin
   name="Aardwolf_Scan"
   author="Blainer"
   id="73766b7b4dfab1cd1ce9494d"
   language="Lua"
   purpose="Put scan in a miniwindow."
   date_written="2009-07-16 21:58:17"
   requires="4.43"
   version="1.0"
   save_state="y"
   >
</plugin>
<include name="constants.lua"/>
<triggers>
<!-- scan triggers -->
<trigger
    name="scan1"
    enabled="y"
    group="scan"
    lines_to_match="1"
    keep_evaluating="n"
    match="^\d* ?(Up|Down|Right|North|South|East|West) .*here you see:$"
    multi_line="n"
    omit_from_output="y"
    regexp="y"
    send_to="12"
    sequence="101"
    script="scan_trigger"
>
</trigger>
<trigger
    name="scan2"
    enabled="y"
    group="scan"
    lines_to_match="1"
    keep_evaluating="n"
    match="^You see [A-Za-z0-9 ]+(up|down|right|north|south|east|west)?\.$"
    multi_line="n"
    match_text_colour="y"
    text_colour="10"
    omit_from_output="y"
    regexp="y"
    send_to="12"
    sequence="101"
    script="scan_trigger"
>
</trigger>
<trigger
    name="scan3"
    enabled="y"
    group="scan"
    lines_to_match="1"
    keep_evaluating="n"
    match="^\s{5}\- (?!--+).+$"
    multi_line="n"
    omit_from_output="y"
    regexp="y"
    send_to="12"
    sequence="101"
    script="scan_trigger"
>
</trigger>
<trigger
    enabled="n"
    name="end_scan_trigger"
    lines_to_match="1"
    keep_evaluating="n"
    match=".+"
    multi_line="n"
    omit_from_output="n"
    regexp="y"
    send_to="12"
    sequence="999"
    script="end_scan_trigger"
>
</trigger>
<trigger
   enabled="y"
   group="scan"
   keep_evaluating="y"
   match="^.*\[Exits\: .*\]$"
   name="auto_scan"
   regexp="y"
   script="auto_scan"
   send_to="12"
   sequence="100"
  >
</trigger>
<!-- campaign triggers -->
<!--http://www.gammon.com.au/forum/?id=8815 -->
<trigger
    enabled="y"
    match="^You still have to kill \* (.*?)$"
    keep_evaluating="y"
    name="campaign_item"
    script="camp_trigger"
    sequence="99"
    regexp="y"
>
</trigger>
<trigger
    enabled="y"
    keep_evaluating="y"
    match="^(Congratulations)\, that was one of your CAMPAIGN mobs\!$"
    regexp="y"
    sequence="99"
    script="camp_trigger"
>
</trigger>
<!-- quest trigger -->
<trigger
   enabled="y"
   group="quest"
   keep_evaluating="y"
   match="* can be found in the vicinity of*"
   name="QUEST"
   script="quest_trigger"
   send_to="12"
   sequence="100"
>
</trigger>
<trigger
   enabled="y"
   group="quest"
   keep_evaluating="y"
   match=".+ 'An enemy of mine, (.+), is making vile'"
   name="QUEST_START"
   regexp="y"
   script="quest_trigger"
   send_to="12"
   sequence="100"
  >
  </trigger>
<trigger
   enabled="y"
   group="quest"
   keep_evaluating="y"
   match="QUEST: You have almost completed your QUEST!"
   name="QUEST_FINISHED"
   script="quest_trigger"
   send_to="12"
   sequence="100"
  >
  </trigger>
</triggers>

<aliases>
  <alias
   name="sl_command"
   script="sl_command"
   match="sl *"
   enabled="y"
   group="sl_command"
   omit_from_log="y"
   send_to="12"
   omit_from_output="y"
   sequence="100"
  >
  </alias>

<alias
   name="addkey"
   script="addkey"
   match="addkey * * *"
   enabled="y"
   send_to="12"
   sequence="100"
   keep_evaluating="n"
  >
</alias>
<alias
   name="addkey_error"
   script="addkey"
   match="addkey.*"
   regexp="y"
   enabled="y"
   send_to="12"
   sequence="101"
   keep_evaluating="n"
  >
</alias>
<alias
   name="remkey"
   script="remkey"
   match="remkey *"
   enabled="y"
   send_to="12"
   sequence="100"
   keep_evaluating="n"
  >
</alias>
<alias
   name="remkey_error"
   script="remkey"
   match="remkey.*"
   regexp="y"
   enabled="y"
   send_to="12"
   sequence="101"
   keep_evaluating="n"
  >
</alias>

</aliases>
<script>
<![CDATA[
require "mw"
require "movewindow"
require "check"

PADDING         = 4
BORDER_SIZE     = 2
LINE_SPACE      = 2
FONT            = "Dina"
FONT_SIZE       = 8
BORDER          = 2
LINESPERPAGE    = 10
BACKCOLOUR      = ColourNameToRGB ("black")
BORDERCOLOUR    = ColourNameToRGB ("dimgray")
DEFAULT_ALIAS   = GetVariable("default_alias") or "look"
CAMP_COLOUR     = GetVariable("camp_colour") or 0x00D7FF
QUEST_COLOUR    = GetVariable("quest_colour") or 0x008CFF
GQUEST_COLOUR   = GetVariable("gquest_colour") or 0x00A5FF
AUTO_SCAN       = true -- do scan after move (triggers on Exits from Look)
db_path = ""
db_name = ""

scanT = {}
scT = {}
wt = {}
iwin = {}
win_mt = {__index = iwin}
repT =  {["(Translucent)"] = "(Trans.)",
         ["(White Aura)"] = "(W.Aura)",
         ["(Animated)"] = "(Anim.)",
         ["(Golden Aura)"] = "(Gold.)",
         ["(Red Aura)"] = "(Red.)",
         ["Up"] = "UP",
         ["Down"] = "DOWN",
         ["Right"] = "RIGHT",
         ["North"] = "NORTH",
         ["South"] = "SOUTH",
         ["East"] = "EAST",
         ["West"] = "WEST"
        }

--add / remove keywords ----------------------------------------------------------
--add custom keywords
function add_keyword (keyword, colour, group)
    local t = { SELECT  = { "*" },
                FROM    = { "keywords" },
                WHERE   = { "keyword <> ''" }}
    local listT, s = AardSelect (t)
    for _,v in ipairs(listT) do
        if v.keyword == keyword and v.cgroup == group then -- remove keyword if already in db for new one
            t = { "keyword","colour","cgroup" }
            s = AardExec ("DELETE FROM 'keywords' WHERE (keyword = '" .. keyword:lower() .. "')")
            DBmsg ("add_keyword: removing keyword: keywords table: " .. s )
        end
    end
    --add custom keyword
    sqlT = {    table = "keywords",
                INSERT  = { "keyword","colour","cgroup" },
                VALUES  = { keyword:lower(), colour, group:lower() } }
    s = AardInsert (sqlT)
    DBmsg ("add_trigger: adding keyword: keywords table: " ..  s)
    if s:match("not an error") then
        Note(keyword .. ": keyword added")
    end
end -- add_keyword

--remove custom keywords
function rem_keyword (keyword)
    local t = { SELECT  = { "*" },
                FROM    = { "keywords" },
                WHERE   = { "keyword == '" .. keyword .. "'" }}
    local listT, s = AardSelect (t)
    if not listT[1] then
        Note(keyword .. ": keyword not found")
        return
    end
    t = { "keyword","colour","cgroup" }
    s = AardExec ("DELETE FROM 'keywords' WHERE (keyword = '" .. keyword:lower() .. "')")
    DBmsg ("rem_keyword: removing keyword: keywords table: " .. s )
    if s:match("not an error") then
        Note(keyword .. ": keyword removed")
    end
end -- rem_keyword

--check if all wildcards supplied and call add_keyword
function addkey (name, line, wildcards)
    for i=1, 3 do
        if not wildcards[i] then
            Note("addkey [keyword] [colour] [group]")
            return
        end
    end
    if wildcards[2]:match ("%a") then
        wildcards[2] = ColourNameToRGB (wildcards[2])
    end
    add_keyword(wildcards[1], wildcards[2], wildcards[3])
end

--check if all wilodcards cupplied and call rem_keyword
function remkey (name, line, wildcards)
    if not wildcards[1] then
        Note("remkey [keyword]")
        return
    end
    rem_keyword(wildcards[1]:lower())
end

function get_keyword(w)
    return w:gsub("%s%[.+%]", ""):gsub("[%,%.%'%;%:%-]", ""):gsub("%(.+%)", ""):gsub("^%s+", ""):match("(%a+)$")
end -- get_keyword

-- remove the last charater from string
function dcomma (s)
    s = s:sub (1, s:len() - 1)
    return s
end -- dcomma

--alias functions ----------------------------------------------------
function sl_command (name, line, wildcards)
    if not wildcards[1] then
        return
    elseif wildcards[1] == "?" then
        Help()
    elseif wildcards[1]:lower() == "clear" then
        s = AardExec ("DELETE FROM keywords")
        DBmsg ("sl_command: clearing all: keywords table: " .. s )
    elseif wildcards[1]:lower() == "on" then
        SetVariable ("mode", "explore")
        Note("auto scan on")
        SendNoEcho ("scan")
    elseif wildcards[1]:lower() == "off" then
        Minimize ("", GetPluginID() .. "scan")
        SetVariable ("mode", "town")
        Note("auto scan off")
    elseif wildcards[1]:lower() == "list" then
    local t = { SELECT  = { "*" },
                FROM    = { "keywords" },
                WHERE   = { "keyword <> ''" }}
    local p, s = AardSelect (t)
    local num = 0
    if not p[1] then
        Note("Database is empty")
        return
    end
    for _,v in ipairs(p) do
        num = math.max (v.keyword:len(), num)
    end
    local bac = RGBColourToName(GetInfo(271))
    for _,v in ipairs(p) do
        local col = RGBColourToName (v.colour)
        ColourTell(col, "black", v.keyword)
        Tell(string.rep(" ", num + 1 - v.keyword:len()) .. " [")
        ColourTell(col, "black", col)
        Tell("] [" .. v.cgroup .. "] ")
        Hyperlink ("!!73766b7b4dfab1cd1ce9494d:rem_keyword(" .. v.keyword .. ")", "remove", "Remove keyword from the database.", "gray", "black", false)
        Note(" ")
    end
    else
        if SetVariable("default_alias", wildcards[1]) == 0 then
            Note("Default alias set to: " .. wildcards[1])
        end
        SendNoEcho ("scan")
    end
end -- sl_command

function Help ()
    local a = {
                "cp check - get/update campaign MOB list.",
                "quest check - get/update quest MOB list.",
                "scan - update scan window.",
                "addkey [keyword] [colour] [group] - add keyword, i.e. \"addkey mob colour global\".",
                "remkey [keyword] - remove keyword, i.e. \"remkey mob\".",
                "sl [on/off] - turn auto scan on or off, i.e. \"sl on\".",
                "sl clear - clear all keywords.",
                "sl list - list all keywords in database.",
                "sl [alias] - set default alias, i.e. \"sl my_alias\".",
                "sl ? - show this help."
                }
    for i,v in ipairs (a) do
        sSpa = string.rep (" ", 34 - v:sub(1,v:find("-") - 1):len() )
        ColourTell ("yellow", GetInfo(271), v:sub(1,v:find("-") - 1) .. sSpa )
        ColourNote ("white", GetInfo(271), v:sub(v:find("-"), v:len() ))
    end
end -- help

--trigger functions --------------------------------------------------
function auto_scan (name, line, wildcards)
    if GetVariable ("mode"):lower() == "explore" and AUTO_SCAN then
        SendNoEcho ("scan")
    end
end -- auto_scan

function scan_trigger (name, line, wildcards, styles)
    if name:match("scan%d") then
        EnableTrigger ("end_scan_trigger", true)
        for _,v in ipairs(styles) do
            v.text = v.text:gsub ("%([%a ]+%)",
                                    function (str)
                                        return repT [str]
                                    end)
            v.text = v.text:gsub ("(%a+)",
                                    function (str)
                                        return repT [str]
                                    end)
            v.text = v.text:gsub ("     ", " ")
        end
        if name == "scan1" or name == "scan2" then
            styles.title = "title_line"
        end
        table.insert (scT, styles)
    end
end -- scan_trigger

function end_scan_trigger (name, line, wildcards, styles)
    if name == "end_scan_trigger" then
        EnableTrigger ("end_scan_trigger", false)
        scanT = scT
        scT = {}
        title = "Scan "
        name = GetPluginID() .. "scan"
        scan_window(name, title)
    end
end -- end_scan_trigger

function camp_trigger (name, line, wildcards)
    if wildcards[1] == "Congratulations" then -- clear all cp mobs ready for new list
        s = AardExec ("DELETE FROM 'keywords' WHERE (cgroup LIKE 'campaign')")
        DBmsg ("camp_trigger: removing keyword: keywords table: " .. s )
        return
    end
    local mob = wildcards[1]:match("^(.+)%s%("):lower()
    local col = GetVariable ("camp_colour") or CAMP_COLOUR
    if not mob then
        return
    end
    --add mob as campaign mob
    sqlT = {    table = "keywords",
                INSERT  = { "keyword","colour","cgroup" },
                VALUES  = { mob, col, "campaign" } }
    s = AardInsert (sqlT)
    DBmsg ("camp_trigger: adding keyword: keywords table: " ..  s)
end -- camp_trigger

function quest_trigger (name, line, wildcards)
    s = AardExec ("DELETE FROM 'keywords' WHERE (cgroup LIKE 'quest')")
    DBmsg ("quest_trigger: removing keyword: keywords table: " .. s)
    if not wildcards[1] then
        return
    end
    local col = GetVariable("quest_colour") or QUEST_COLOUR
    --add mob as quest mob
    sqlT = {    table = "keywords",
                INSERT  = { "keyword","colour","cgroup" },
                VALUES  = { wildcards[1]:lower(), col, "quest" } }
    s = AardInsert (sqlT)
    DBmsg ("quest_trigger: adding keyword: keywords table: " ..  s)
end -- quest_trigger

--Miniwindow functions ---------------------------------------------------
-- make the window, install fonts return window table
function iwin:install (win, stitle)
    windowinfo = movewindow.install (win, 6)
    check(WindowCreate (win,
             windowinfo.window_left,
             windowinfo.window_top,
             1,
             1,
             windowinfo.window_mode,
             windowinfo.window_flags,
             BACKCOLOUR))
    local fonts = utils.getfontfamilies ()
    if not fonts[FONT] then
        FONT = "Courier"
    end
    check(WindowFont (win, win, FONT, FONT_SIZE, false, false, false, false, 0, 0))
    return setmetatable ({  name            = win,
                            width           = WindowInfo (win, 3),
                            height          = WindowInfo (win, 4),
                            left            = windowinfo.window_left,
                            top             = windowinfo.window_top,
                            flags           = windowinfo.window_flags,
                            mode            = windowinfo.window_mode,
                            font_id         = win,
                            font_height     = WindowFontInfo (win, win, 1),
                            line_height     = WindowFontInfo (win, win, 1) + LINE_SPACE,
                            headfoot_height = WindowFontInfo (win, win, 1) + BORDER_SIZE * 2 + LINE_SPACE * 2,
                            head_width      = 0,
                            backcolour      = WindowInfo (win, 9),
                            title           = stitle
                            }, win_mt)
end

--show the window
function iwin:show ()
    check(WindowShow(self.name, true))
end -- show

function Minimize (flag, ID)
    if not wt[ID] then -- window is not made yet
        return
    end
    movewindow.save_state (wt[ID].name)
    wt[ID].height = wt[ID].headfoot_height
    wt[ID].width = wt[ID].head_width
    wt[ID]:make()
    wt[ID]:header("Maximize")
    wt[ID]:show()
end

function Maximize (flag, ID)
    SendNoEcho ("scan")
end

function Click(flag, ID)
    local dir = ID:match(".+dir%:([%a%d]+)mob%:.+")
    local mob = ID:match("mob%:(.+)$")
    if flag == 18 then -- ctrl
        local b = GetVariable("default_alias") or DEFAULT_ALIAS
        if dir then
            SendNoEcho ("run " .. dir)
            if GetVariable ("mode") == "town" or not AUTO_SCAN then
                SendNoEcho ("scan")
            end
            Execute (b .. " " .. mob)
        else
            Execute (b .. " " .. mob)
        end
    elseif flag == 16 then
        if GetPluginInfo ("584807a32cf46af04a1bece3", 17) then -- Aardwolf_Consider_Window.xml
            if dir then
                SendNoEcho ("run " .. dir)
            if GetVariable ("mode") == "town" or not AUTO_SCAN then
                SendNoEcho ("scan")
            end
                Execute ("conw")
            else
                Execute ("conw")
            end
        else
            if dir then
                SendNoEcho ("run " .. dir)
                Execute ("consider all")
            if GetVariable ("mode") == "town" or not AUTO_SCAN then
                SendNoEcho ("scan")
            end
            else
                Execute ("consider all")
            end
        end
    end
end -- MouseDown

--do the menus
function ListMenu (flag, ID)
    local win = ID:sub(1, ID:len() - 1)
    --make the menu
    local menu = " Show command line help || Set quest hightlight colour | Set campaign highlight colour "
    local result = WindowMenu (wt[win].name, WindowInfo (wt[win].name, 14), WindowInfo (wt[win].name, 15), menu)
    --run command
    if result ~= "" then
        if result:match("help") then
            Help()
            return
        elseif result:match("quest") then
            QUEST_COLOUR = PickColour (QUEST_COLOUR)
            SetVariable ("quest_colour", QUEST_COLOUR)
            SendNoEcho("quest check")
            return
        elseif result:match("campaign") then
            CAMP_COLOUR = PickColour (CAMP_COLOUR)
            SetVariable ("camp_colour", CAMP_COLOUR)
            return
        end
    end
end -- ListMenu

--return the width of a line with padding
function iwin:lwidth(s)
    return WindowTextWidth (self.name, self.name, mw.strip_colours(s)) + PADDING * 2
end -- line_width

function iwin:get_size ()
    self.height = #scanT * self.line_height + self.headfoot_height + LINE_SPACE
    self.width = self:lwidth (title .. "?") + self.headfoot_height / 3 + PADDING * 3
    self.head_width = self.width
    for _,v in ipairs (scanT) do
        local s = ""
        for _,w in ipairs (v) do
            s = w.text .. s
            self.width = math.max (self.width, self:lwidth(s))
        end
    end
end -- get_size

function iwin:make()
    check(WindowCreate (self.name,
             windowinfo.window_left,
             windowinfo.window_top,
             self.width,
             self.height,
             windowinfo.window_mode,
             windowinfo.window_flags,
             self.backcolour))
end -- show_window

--put header on window
function iwin:header (s)
    x       = self.width / 2
    y       = self.headfoot_height / 2
    boxsq   = self.headfoot_height / 3
    indent  = PADDING + BORDER_SIZE
    --draw the title
    mw.colourtext (self.name, self.font_id, self.title,
        indent,
        y - self.font_height / 2,
        indent + self:lwidth (self.title) - PADDING,
        y + self.font_height,
        false)
    --draw ?
    local left = self.width - boxsq - indent - self:lwidth("?")
    WindowText (self.name, self.font_id, "?",
        left,
        y - self.font_height / 2,
        left + self:lwidth("?"),
        y + self.font_height,
        BORDERCOLOUR)
    check(WindowAddHotspot (self.name, self.name .. "?",
        left,
        y - self.font_height / 2,
        left + self:lwidth("?"),
        y + self.font_height,
        "", "", "", "", "ListMenu", "Click for help and to set highlight colours.", 1, 0))
    --draw minimize button
    check(WindowCircleOp (self.name, 2,
        self.width - boxsq - indent,
        y - boxsq / 2,
        self.width - indent,
        y + boxsq / 2,
        BORDERCOLOUR, 0, 0, BORDERCOLOUR, 0))
    check(WindowAddHotspot (self.name, self.name,
        self.width - boxsq - indent,
        y - boxsq / 2,
        self.width - indent,
        y + boxsq / 2,
        "", "", s,  "", "", s .. " Window", 1, 0))
    --draw border
    check(WindowCircleOp (self.name, 2,
        0,
        0,
        self.width,
        self.headfoot_height,
        BORDERCOLOUR, 6, BORDER_SIZE, BORDERCOLOUR, 1))
   check(WindowRectOp (self.name, 1, 0, 0, self.width , self.headfoot_height, BORDERCOLOUR))
    --drag handler
    movewindow.add_drag_handler (self.name, 0, 0, buttonleft, self.headfoot_height, 1)
end -- header

function iwin:add_lines()
    local t = {}
    local top = self.headfoot_height + LINE_SPACE
    local bottom = top + self.font_height
    local t = { SELECT  = { "*" },
                FROM    = { "keywords" },
                WHERE   = { "keyword <> ''" }}
    local mobT, s = AardSelect (t)
    local nwid = 0
    for _,v in ipairs(scanT) do -- find keyword matches
        for _,w in ipairs(v) do
            for _,q in ipairs(mobT) do
                if w.text:lower():match(q.keyword:lower()) then
                    w.textcolour = q.colour
                    w.text = w.text .. " [" .. q.cgroup .. "]" -- add group name to item
                    nwid = math.max (self:lwidth(q.cgroup), nwid)
                end
            end
        end
    end
    if nwid then -- re-size window to fit group names if matches found
        self.width = self.width + nwid
        self:make()
        self:header("Minimize")
    end
    for i,v in ipairs(scanT) do
        local left = PADDING
        local s = ""
        for _,w in ipairs(v) do
            left = left + WindowText (self.name, self.font_id, w.text,
                    left,
                    top,
                    left + self:lwidth(w.text),
                    bottom,
                    w.textcolour)
            s = s .. w.text
        end
        if v.title then -- get directions
            if s:match("^RIGHT.+") then
                dir = ""
            elseif s:match("^You see.+") then
                dir = s:match("%s(%a)%.$")
            else
                dir = s:match("^(%d*%s*%a)")
                dir = dir:gsub("%s", "")
            end
            t = {} -- new room so clear keyword table
        else
            s = get_keyword(s)
            t[#t + 1] = s -- table for counting mob numbers
            local g = 0
            for _,h in ipairs(t) do
                if s == h then g = g + 1 end
            end
            local a = self.name .. i .. "dir:" .. dir .. "mob:" .. g .. "." .. s -- make hotspot ID with direction and mob
            check(WindowAddHotspot (self.name, a,
                PADDING,
                top,
                left,
                bottom,
                "", "", "", "", "Click", "", 1, 0))
            local l1 = "Commands\t\n"
            local l2 = "left mouse         - move to room and \"consider all\".\n"
            local l3 = "ctrl+left mouse  - move to room and execute default alias or command.\n\n"
            local b = GetVariable("default_alias") or DEFAULT_ALIAS
            local l4 = "(Default alias\\command: " .. b .. ")\n"
            check(WindowHotspotTooltip(self.name, a, l1 .. l2 .. l3 .. l4))
        end
        top = top + self.line_height
        bottom = top + self.font_height
    end
end -- add_lines

function scan_window (name, title)
    if not wt[name] then
        wt[name] = iwin:install(name, title)
    end
    wt[name]:get_size()
    wt[name]:make()
    wt[name]:header("Minimize")
    wt[name]:add_lines()
    wt[name]:show()
end -- scan_window

--database functions -------------------------------------------------
dbmsg = false -- display SQL messages

-- print db return msgs
function DBmsg (s)
    if dbmsg then
        Note (s)
    end
end

--opens and closes db, called at start and end of script
function OpenCloseDatabase (Option)
    b = GetInfo(3)
    if b == "" then
        b = GetInfo(55):match("^(.+)%..+$")
    end
    db_path = GetInfo(54):match("(.+%\\)") .. b .. "_" .. "AardKeywords.db"
    db_name = GetPluginID() .. "db"
    if Option then
        DatabaseOpen(db_name, db_path, 6)
    elseif not Option then
        DatabaseClose(db_name)
        return
    end
    DBmsg(AardCreate ())
end -- OpenCloseDatabase

-- create the databse and tables
function AardCreate ()
    if not DatabaseList() then
        OpenCloseDatabase (true)
    end
    aard_sql =  {   -- table holding db setup sql
    keywords =      {   -- keyword table, holds keywords and colours
                    [[
                    CREATE TABLE IF NOT EXISTS keywords(
                    keyword TEXT UNIQUE,
                    colour TEXT,
                    cgroup TEXT
                    );
                    CREATE INDEX xref_keywords_keyword ON keywords (keyword);
                    CREATE INDEX xref_keywords_cgroup ON keywords (cgroup);
                    ]]
                    }
                }
    --make sql tables and execute
    for k in pairs (aard_sql) do
        if not checkfortable(k) then
            DBmsg ("creating database table: " .. k .. ": " .. AardExec (aard_sql[k][1]) )
        end
    end
end -- AardCreate

-- check if table exists http://www.gammon.com.au/forum/?id=9497
function checkfortable(tablename)
    if not tablename then
        Note("checkfortable: no tablename")
        return "no tablename"
    end
    db = assert(sqlite3.open (db_path))
    if db:isopen() then
        for a in db:nrows("SELECT name FROM sqlite_master") do
            if a['name'] == tablename then
                db:close()
                return true
            end
        end
    end
    db:close()
    return false
end -- checkfortable

-- execute sql on db
function AardExec (sql)
    if not DatabaseList() then
        OpenCloseDatabase (true)
    end
    if not sql then
        Note ("AardExec no sql")
        return "No sql"
    end
    DatabaseExec(db_name, sql)
    s = DatabaseError (db_name)
    return s
end -- AardExec

-- insert values into database
function AardInsert (t)
    if not DatabaseList() then
        OpenCloseDatabase (true)
    end
    if not t then
        Note ("AardInsert: no sql table")
        return false
    end
    -- construct the sql
    sql = "INSERT INTO " .. t.table .. " ("
    for i,v in pairs (t.INSERT) do
        sql = sql .. "'" .. v .. "'" .. ","
    end
    sql = dcomma (sql) .. ") VALUES ("
    for i,v in pairs (t.VALUES) do
        sql = sql .. "'" .. v .. "'" .. ","
    end
    sql = dcomma (sql) .. ")"
    -- execute the sql
    s = AardExec (sql)
    if not s then
        return false
    else
        return s
    end
end -- AardInsert

-- select records from db and return with column names
function AardSelect (t)
    if not DatabaseList() then
        OpenCloseDatabase (true)
    end
    if not t then
        Note ("AardSelect no sql table")
        return "No table"
    end
    -- construct the sql
    sql = "SELECT"
    for i,v in pairs (t.SELECT) do
        sql = sql .. " " .. v .. ","
    end
    sql = dcomma (sql) .. " FROM"
    for i,v in pairs (t.FROM) do
        sql = sql .. " " .. v .. ","
    end
    sql = dcomma (sql) .. " WHERE"
    for i,v in pairs (t.WHERE) do
        sql = sql .. " " .. v
    end
    -- open, prepare and step the database
    t = {}
    u = {}
    DatabasePrepare (db_name, sql)
    rc = DatabaseStep (db_name)
    s = DatabaseError (db_name)
    while rc == 100 do
        row = DatabaseColumnValues (db_name)
        for i in ipairs(row) do
            u[DatabaseColumnName(db_name, i)] = row[i]
        end
        table.insert (t,u)
        u = {}
        rc = DatabaseStep (db_name)
        s = DatabaseError (db_name)
    end
    DatabaseFinalize(db_name)
    if t[1] == nil then
        DBmsg ("AardSelect: " .. s)
        return t, s
    else
        return t, s
    end
end -- AardSelect

--Plugin events ------------------------------------------------------
function OnPluginConnect ()
end -- OnPluginConnect

function OnPluginInstall ()
    if GetVariable ("enabled") == "false" then
        ColourNote ("yellow", "", "Warning: Plugin " .. GetPluginName ().. " is currently disabled.")
        check (EnablePlugin(GetPluginID (), false))
        return
    end -- they didn't enable us last time
    Note("Aardwolf_Scan.xml loaded")
end --OnPluginInstall

function OnPluginEnable ()
    SetVariable ("enabled", "true")
    OnPluginInstall ()
end -- OnPluginEnable

function OnPluginDisable ()
    SetVariable ("enabled", "false")
    OpenCloseDatabase(false)
    OnPluginClose ()
end -- OnPluginDisable

function OnPluginClose()
    OnPluginSaveState()
    --close windows
    local wins = WindowList()
    if wins then
        for _, v in ipairs (wins) do
            if v:match (GetPluginID()) then
                WindowDelete(v)
            end
        end
    end -- if any
    OpenCloseDatabase(false)
end -- OnPluginClose

function OnPluginSaveState ()
    --save window locations
    local wins = WindowList ()
    if wins then
        for _, v in ipairs (wins) do
            if v:match (GetPluginID()) then
                movewindow.save_state (v)
            end
        end
    end
end -- OnPluginSaveState

function OnPluginBroadcast (msg, id, sname, text)
  if msg == 99 and id == "c471cbdbb5dd42756ec21c27" then
    if text == "town" then
        Minimize ("", GetPluginID() .. "scan")
        SetVariable ("mode", "town")
        return
    elseif text == "explore" then
        SetVariable ("mode", "explore")
        SendNoEcho ("scan")
    end
  end -- stats changed
end
]]>
</script>
</muclient>

[Go to top] top

Posted by Blainer   (191 posts)  [Biography] bio
Date Reply #1 on Sun 11 Oct 2009 12:34 AM (UTC)
Message
Fixed the error when MUSH was started.

Changed the alias in the post to use Execute rather than Script.
[Go to top] top

Posted by Blainer   (191 posts)  [Biography] bio
Date Reply #2 on Sun 11 Oct 2009 01:26 AM (UTC)
Message
Changed the way the database is opened to ensure the database is opened and created when ever the script tries to access it.
[Go to top] top

Posted by Thebigone   (1 post)  [Biography] bio
Date Reply #3 on Thu 17 Jun 2010 10:24 AM (UTC)
Message
i can get the plugin to work when i first install it, but after moving and scanning some, i receive this error:

Run-time error
Plugin: Aardwolf_Scan (called from world: Aardwolf)
Function/Sub: end_scan_trigger called by trigger
Reason: processing trigger "end_scan_trigger"
[string "Plugin"]:652: attempt to concatenate local 's' (a nil value)
stack traceback:
[string "Plugin"]:652: in function 'add_lines'
[string "Plugin"]:678: in function 'scan_window'
[string "Plugin"]:361: in function <[string "Plugin"]:354>
Error context in script:
648 : local g = 0
649 : for _,h in ipairs(t) do
650 : if s == h then g = g + 1 end
651 : end
652*: local a = self.name .. i .. "dir:" .. dir .. "mob:" .. g .. "." .. s -- make hotspot ID with direction and mob
653 : check(WindowAddHotspot (self.name, a,
654 : PADDING,
655 : top,
656 : left,

this problem also happens when i scan after reading graffiti...

aardwolf has added scan tags to mark the start and end of the scan output, so maybe that will help?

i know it has been some time since you last logged onto aardwolf, but this plugin looks good and hopefully you can help me make it work
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


6,938 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]