Minor update to the consider window plugin (aardwolf mud)

Posted by Dakine on Fri 01 May 2015 04:30 PM — 4 posts, 19,838 views.

#0
This is one of the plugins I use the most and find it prevents finger typing strain!

See original post and latest plugin version here:

http://www.gammon.com.au/forum/?id=9681&reply=68#reply68


The one drawback I found was that if you had duplicate mob names in the room and you wanted to select, say the 2nd one specifically, you couldn't. It would kill based on order in the room. A frequent situation might arise if you wanted to select only one type of aligned mob to kill or for a campaign/quest.

I updated the code to compensate for this situation. e.g

mobs in a room/displayed in mini window
1.(R) scary monster
2.(G) cute cuddly bear
3.(G) scary monster

Clicking no. 3 or command line type>3

issues 'kill 2.monster

This does however, mean that your selection is more specific and clicking on e.g the '6.mob' no longer kills the first occurrence in the room. If 6.mob is already dead and the window hasn't yet updated then it will tell you it doesn't exist.

I tried to add the whole plugin but it wouldn't let me.
See code snippets below:

function send_consider ()

    if GetVariable ("doing_consider") == "true" then
        return
    else
        SetVariable ("doing_consider", "true")
        EnableTriggerGroup ("consider", true)
        SendNoEcho ("consider all")
        Send ("echo nhm")
        targT = {}
        -- New change 2 lines below
	tmptbl = nil
	tmptbl  = {}
    end

end -- send_consider



function execute_command (id, s)

    if not s then
        return
    end
    -- New change line below
    s = s:match ("^([%d+%.%w']+)%:%d+$")
    Execute (default_command .. " " .. s)
    ColourTell ("white", "blue", default_command .. " " .. s)
    ColourNote ("", "black", " ")

end -- execute_command




function adapt_consider (name, line, wildcards)
    -- new change line below    
    mobDup = 0
    mob = nil
    for k,  v in pairs (consider_messages) do
        mob = string.match (line, k)
        if keyword_position == "end" then
            sPat = "[%w\-\.]+$"
        else
            sPat = "^[%w\-\.]+"
        end
        
        if mob then
                        -- New change 13 lines below
            mobKeyword = mob:gsub ("%w+", function (str) return replaceT [str] end ):gsub("^%s+", ""):gsub("%s+$", ""):match(sPat)
            table.insert (tmptbl, mobKeyword)
            
            for i,v in ipairs (tmptbl) do
                if tmptbl[i] == mobKeyword then
                    mobDup = mobDup + 1
                end --if
            end
            
            if tonumber(mobDup) > 0 then
                mobKeyword = mobDup .. "." .. mobKeyword
                mobRep = 0
            end
            t = {
                -- new change line below
                keyword = mobKeyword,
                name    = mob,
                line    = line,
                colour  = v.colour,
                range   = "(" .. v.range .. ")",
                message = line
                }
            if ECHO_CONSIDER then
                ColourNote (v.colour, "", line .. " (" .. v.range .. ")" )
            end

            table.insert (targT, t)

            break
        end -- if

    end -- for

    if not mob and SHOW_NO_MOB then
        ColourTell ("white", "blue", "Could not find anything: " .. line)
        ColourNote ("", "black", " ")
    end -- not  found in table

end -- adapt_consider




Dak
Amended on Fri 01 May 2015 09:03 PM by Nick Gammon
Australia Forum Administrator #1
Thanks. I edited your post to "fix up" square brackets inside code tags.
#2
Thanks Nick,

That explains the italics, which at the time of posting, wasn't sure why.
Australia Forum Administrator #3
Template:codetag
To make your code more readable please use [code] tags as described here.


In particular the bit about "Convert Clipboard Forum Codes".