Console/Label Affliction tracking

Post Reply
Jaaqi
Posts: 3
Joined: Tue Jan 17, 2012 2:42 pm

Console/Label Affliction tracking

Post by Jaaqi »

Hi There,

I just started playing some aetolia again after a few years, and coming from zmud/cmud I would like to keep my afflictions tracked in a sidebar. I used to have buttons that would change colors as i got afflictions and could then click the button for the cure if wanted to as well.

After reading a bit it seems in mudlet i would have to go with a miniconsole and echoes or labels. I have created one miniconsole which has the afflictions echoed to it, but either i get the same affliction listed twice or i end with a whole lot of blank lines and then an affliction. I'm not bothered about clicking to heal, I just want my afflictions to be listed as they appear, ina neat list and go away as I cure. And be easily readible wihtout lines of blank spaces between them.

What would the recommended way be to do this, and could anyone give me some practical examples with a light explanation so that I can understand it and tinker with it myself? ie I do not want to just copy paste and not learn how it works.

User avatar
tsuujin
Posts: 695
Joined: Fri Feb 26, 2010 12:59 am
Location: California
Contact:

Re: Console/Label Affliction tracking

Post by tsuujin »

This is what i use to track my opponents afflictions. It is just a text only display, but has some nice functionality as far as sorting and output color.

Keep in mind this will not work as a standalone script. It depends on certain other functions in my system that are not included and should only be used for example purposes.
Code: [show] | [select all] lua
-- [[ Opponent Affliction Tracker ]] --

module("opAff",package.seeall)


local affCat = php:Table()
affCat["Lock"] = {"anorexia", "asthma", "slickness"}
affCat["Physical Debuff"] = {"disrupt", "epilepsy", "prone", "paralysis"}
affCat["Mental Debuff"] = {"impatience", "stupidity", "peace"}

local fontsize = 11
local winStat = {}
local list = php:Table()

function init()
    initAffs()
    resetAffs()
    winInit()
    print()
    if exists("opAff Decay","timer") == 0 then
        permTimer("opAff Decay","",1,[[opAff.decay()]])
    end
    enableTimer("opAff Decay")
end

function winInit()
    local w,h = getMainWindowSize()
    local fw,fh = calcFontSize(fontsize)
    local width = fw * 24
    local height = fh * 27
    local x = w - width - 15
    local y = h - height - 15

    winStat = {}
    winStat["width"] = width
    winStat["height"] = height

    createMiniConsole("opAff",0,0,0,0,1)
    setBackgroundColor("opAff",0,0,0,255)
    setMiniConsoleFontSize("opAff",fontsize)
    moveWindow("opAff",x,y)
    resizeWindow("opAff",width,height)
end

function reposition()
    local w,h = getMainWindowSize()
    local x = w - winStat["width"] - 15
    local y = h - winStat["height"] - 15
    moveWindow("opAff",x,y)
end

function initAffs()
    list = php:Table()
    define("anorexia","skin","apply")
    define("asleep","wake","action")
    define("asthma","kelp","eat")
    define("clumsiness","kelp","eat")
    define("epilepsy","goldenseal","eat")
    define("hallucinations","ash","eat")
    define("impatience","goldenseal","eat")
    define("disfigurement","smoke","smoke")
    define("disrupt","concentrate","action")
    define("hypochondria","kelp","eat")
    define("peace","bellwort","eat")
    define("paralysis","bloodroot","eat")
    define("prone","stand","action")
    define("slickness","smoke","smoke")
    define("stupidity","goldenseal","eat")
    define("recklessness","lobelia","eat")
    define("weariness","kelp","eat")
end

function define(aff,cure,method,decay)
    list[aff] = {}
    list[aff]["cure"] = cure
    list[aff]["method"] = method
    list[aff]["pct"] = 0
    list[aff]["decay"] = decay or 0
end

function resetAffs()
    for i,v in list:pairs() do
        v.pct = 0
        v.value = nil
    end
    print()
end

function afflicted(aff,val)
    if not list[aff] then return end
    list[aff]["pct"] = 100
    list[aff]["value"] = val or nil
    print()
end

function cureAff(aff)
    list[aff]["pct"] = 0
    list[aff]["value"] = nil
    print()
end

function calcPctLoss(poss)
    local pct = 100*((1/#poss))
    for _,i in pairs(poss) do
        list[i]["pct"] = math.max(0,math.floor(list[i]["pct"] - pct))
        if list[i]["pct"] == 0 then list[i]["value"] = nil end
    end
    print()
end

function focused()
    local poss = {}
    for _,i in pairs(cures.focusable) do
        if list[i] and list[i]["pct"] > 0 then table.insert(poss,i) end
    end
    calcPctLoss(poss)
end

function cured(item,method)
    local poss = {}
    for i,v in list:pairs() do
        if v["method"] == method and v["cure"] == item and v["pct"] > 0 then table.insert(poss,i) end
    end
    calcPctLoss(poss)
end

function passiveCure()
    local poss = {}
    for i,v in list:pairs() do
        if v.pct > 0 then table.insert(poss,i) end
    end
    calcPctLoss(poss)
end

function getNeeded(priority)
    if priority then
        for _,aff in pairs(priority:split(":")) do
            if list[aff]["pct"] < 10 then return {list[aff]["strike"]} end
        end
    end
    local tbl = {}
    for i,v in list:pairs() do if v["pct"] < 10 and v["strike"] then table.insert(tbl,v["strike"]) end end
    return tbl
end

function getPercent(aff)
    aff = aff:lower()
    if not list[aff] then return 0 end
    return list[aff]["pct"]
end

function decay()
    for aff,params in list:pairs() do
        if params["pct"] > 0 then list[aff]["pct"] = math.max(0,(params["pct"] - params["decay"])) end
    end
    print()
end

-- set the decay rate of an affliction to a number of seconds equal to 100 / time.
function setDecayTime(aff,time)
    list[aff]["decay"] = 100 / tonumber(time)
end

function print()
    clearWindow("opAff")
    linesPrinted = 0

    local function printSeparator()
        cecho("opAff",string.format("<RoyalBlue>+%s+\n",string.rep("-",21)))
        linesPrinted = linesPrinted + 1
    end

    local function printSpacer()
        cecho("opAff",string.format("<RoyalBlue>|%s|\n",string.rep(" ",21)))
    end

    local function printout(aff)
        if not list[aff] then msg.print("no entry") return end
        local pct = list[aff]["pct"]
        color_table["MyCustom"] = {colorTransition(pct,"firebrick","coral","SpringGreen")}
        local sf = "<RoyalBlue>|<MyCustom>%-15s: %3d%%<RoyalBlue>|\n"
        local header = list[aff]["value"] or aff
        cecho("opAff",sf:format(header:titleCase(),pct))
        linesPrinted = linesPrinted + 1
    end

    local function printHeader(head)
        cecho("opAff","<RoyalBlue>+- ")
        cecho("opAff",string.format("<gold>%s ",head:upper()))
        local stLen = 20 -(#head + 2)
        cecho("opAff",string.format("<RoyalBlue>%s+",string.rep("-",stLen)))
        echo("opAff","\n")
        linesPrinted = linesPrinted + 1
    end

    local function printRemaining()
        local linesToPrint = 26 - linesPrinted
        if linesToPrint > 0 then
            for i=0,linesToPrint-1 do
                printSpacer()
            end
            printSeparator()
        end
    end

    -- Push through a category and determine if any of the afflictions are active.
    local activeCats = php:Table()
    for cat,alist in affCat:pairs() do
        for _,aff in pairs(alist) do
            if list[aff]["pct"] > 0 then
                if not activeCats[cat] then activeCats[cat] = php:Table() end
                activeCats[cat][aff] = true
            end
        end
    end


    printHeader("Opponent Affs")
    for cat,affs in activeCats:pairs() do
        --printHeader(cat)
        for k,_ in affs:pairs() do
            printout(k)
        end
        printSeparator()
    end
    printRemaining()
end

init()

Jaaqi
Posts: 3
Joined: Tue Jan 17, 2012 2:42 pm

Re: Console/Label Affliction tracking

Post by Jaaqi »

Thanks tsuujin, I'll pop that in and play around till I can make sense of it. I'll post back if i don't understand anything specific. :)

User avatar
Oneymus
Posts: 321
Joined: Thu Sep 17, 2009 5:24 am

Re: Console/Label Affliction tracking

Post by Oneymus »

I'm not terribly familiar with Mudlet's buttons, but I should think they can handle exactly what you're after. I might check the manual, or do some searching on here for button-related information.

Jaaqi
Posts: 3
Joined: Tue Jan 17, 2012 2:42 pm

Re: Console/Label Affliction tracking

Post by Jaaqi »

i read either in the manual or on the forum somewhere that mudlet buttons shouldnt be used for things that can rapidly change. afflictions can be given at between 2 and 6 probably per 2 seconds, heals can occur roughly 2 - 6 or so every 2-3 seconds. i thought that would probably count as relatively rapid?

User avatar
tsuujin
Posts: 695
Joined: Fri Feb 26, 2010 12:59 am
Location: California
Contact:

Re: Console/Label Affliction tracking

Post by tsuujin »

I don't think there's a need to use buttons. It's a lot faster to manipulate text than images and I'm a fan of lightweight.

gaosin
Posts: 5
Joined: Fri Jan 20, 2012 6:15 am

Re: Console/Label Affliction tracking

Post by gaosin »

Oo, I like the opponent affliction tracker. It's a bit beyond my skill to build something like that or dissect it (I'm a psych major, keep me away from technology) but I'll have to try and work it out. I use a blademaster in Achaea and a Pureblade in Lusternia, do you think it would be possible to set up something that will track wounds/bleeding? Maybe a nice little stick figure or some sort of graphic that would show broken limbs?

User avatar
tsuujin
Posts: 695
Joined: Fri Feb 26, 2010 12:59 am
Location: California
Contact:

Re: Console/Label Affliction tracking

Post by tsuujin »

I wrote that for a blademaster, actually. Helped me to lock in brokenstars when i knew what my opponents actually had. Broken limbs could just be made into a category (I think i actually had one set up initially) so it would display on it's own.

I never got into the stick figure thing, though I know a lot of people did. It's a a lot of coding for a system that is going to be inaccurate by nature (because you don't see when you break their limbs, and there are a ton of factors that alter limb damage output).

Post Reply