Welcome to the Achaea Forums! Please be sure to read the Forum Rules.

Mudlet Targetting Alias and Color trigger.

ValdusValdus AustraliaMember Posts: 598 ✭✭✭✭✭ - Grand Achaean
So I've finally decided I'm tired of not having my target highlighted. I'm using a very very simple targeting alias right now which is this.

Pattern: ^tar (.+)$

target = matches[2]
echo("Target is now: " ..target)

What I'd like to know how to do, is have it so that whenever I see the word that I have targetted, whether it's in tells, room descriptions or even the echo on my targeting alias, the letters are red.

I also want to point out that I am as new to LUA and Mudlet coding as you can be, really. Used Zmud and Cmud for years, so if you want me to understand anything, you'll have to explain.

Viva la Bluef.

Comments

  • KlendathuKlendathu Eye of the StormMember Posts: 3,159 @@ - Legendary Achaean
    Assuming your variable is target:

    function highlightTarget()
    
    	target_low = tempTrigger(target:lower(), [[selectString("]] .. target:lower() .. [[", 1) fg("MediumSpringGreen") resetFormat()]])
    	target_high = tempTrigger((target:lower()):title(), [[selectString("]] .. (target:lower()):title() .. [[", 1) fg("MediumSpringGreen") resetFormat()]])
    
    end



    Tharos, the Announcer of Delos shouts, "It's near the end of the egghunt and I still haven't figured out how to pronounce Clean-dat-hoo."
  • ValdusValdus AustraliaMember Posts: 598 ✭✭✭✭✭ - Grand Achaean
    Do I like, just paste that in below the echo part in the targeting alias?

    Viva la Bluef.
  • KlendathuKlendathu Eye of the StormMember Posts: 3,159 @@ - Legendary Achaean
    You can either paste it in as a separate function and call it in your target alias, or you can take the two lines starting target_ and paste them into your existing alias.

    Tharos, the Announcer of Delos shouts, "It's near the end of the egghunt and I still haven't figured out how to pronounce Clean-dat-hoo."
  • ValdusValdus AustraliaMember Posts: 598 ✭✭✭✭✭ - Grand Achaean
    I did the second. It works great. Thank you very much for your help.

    Viva la Bluef.
    Klendathu
  • EldEld Member Posts: 3,946 @@ - Legendary Achaean
    edited February 2015
    Looks to me like you might want to add a couple lines to kill any previously existing triggers first,
    if target_high then killTrigger(target_high) end
    and similar for target_low, so you'll stop highlighting your old target when you switch.
  • AntoniusAntonius Member Posts: 4,755 @@ - Legendary Achaean
    That will also only match the first occurrence of the name on a line, which is generally sufficient. Might be a few odd cases where it's not, but probably not enough to be worth worrying about.
  • EldEld Member Posts: 3,946 @@ - Legendary Achaean
    Antonius said:
    That will also only match the first occurrence of the name on a line, which is generally sufficient. Might be a few odd cases where it's not, but probably not enough to be worth worrying about.
    Right, and won't check for full words, so it'll highlight the "man" in "human" if you target "man" or the "element" in "elemental" if you target Element. Also fixable, but also generally not particularly problematic.

    Klendathu said:
    Assuming your variable is target:

    function highlightTarget()
    
    	target_low = tempTrigger(target:lower(), [[selectString("]] .. target:lower() .. [[", 1) fg("MediumSpringGreen") resetFormat()]])
    	target_high = tempTrigger((target:lower()):title(), [[selectString("]] .. (target:lower()):title() .. [[", 1) fg("MediumSpringGreen") resetFormat()]])
    
    end


    FWIW, you don't need the extra parentheses around target:lower() - target:lower():title() works just fine. And in case you or anyone else is interested, you can use string.format to avoid the concatenation operators (..), like
    string.format([[selectString(%q,1) fg("MediumSpringGreen") resetFormat()]], target:lower()) 

    which I find considerably more readable, especially for cases where you want to sub in multiple variables.

    AntoniusKlendathu
  • KlendathuKlendathu Eye of the StormMember Posts: 3,159 @@ - Legendary Achaean
    so...

     target_low = tempTrigger(target:lower(), string.format([[selectString(%q,1) fg("MediumSpringGreen") resetFormat()]], target:lower()) )

    or something else?


    Tharos, the Announcer of Delos shouts, "It's near the end of the egghunt and I still haven't figured out how to pronounce Clean-dat-hoo."
  • EldEld Member Posts: 3,946 @@ - Legendary Achaean
    Looks right to me.
    Klendathu
  • ValdusValdus AustraliaMember Posts: 598 ✭✭✭✭✭ - Grand Achaean
    So.. where do I add the "if target_high then killTrigger(target_high) end" to the modified line Klendathu posted @Eld ?

    Just underneath them both? I know I'll have to add a second for target_low as well




    Viva la Bluef.
  • CynlaelCynlael Member Posts: 3,257 @@ - Legendary Achaean
    Add it above the highlight lines.

    target = whatever

    killtrigger

    highlight

    should be the order.

  • ValdusValdus AustraliaMember Posts: 598 ✭✭✭✭✭ - Grand Achaean
    target = matches[2]
    if target_low then killTrigger(target_low) end
    if target_high then killTrigger(target_high) end
    target_low = tempTrigger(target:lower(), string.format([[selectString(%q,1) fg("red") resetFormat()]], target:lower()) )
    target_high = tempTrigger(target:lower():title(), string.format([[selectString(%q,1) fg("red") resetFormat()]], target:lower():title()) )
    echo("Target is now: " ..target)
    

    That's how I've got it set. I'm not noticing any problems, and I've double checked to see if the old targets are still highlighted, and they're not. See anything wrong?

    Viva la Bluef.
  • CynlaelCynlael Member Posts: 3,257 @@ - Legendary Achaean
    IDK. I use this

    ds_tar = matches[2]:title()

    output("<LightSkyBlue>Target set to <pink>" .. ds_tar .. "<LightSkyBlue>.")


    if target_upper then killTrigger(target_upper) end

    target_upper = tempTrigger(ds_tar, [[highlightTarget("]]..ds_tar..[[")]])


    if target_lower then killTrigger(target_lower) end

    target_lower = tempTrigger(ds_tar:lower(), [[highlightTarget("]]..ds_tar:lower()..[[")]])









  • EldEld Member Posts: 3,946 @@ - Legendary Achaean
    Looks good to me, @Valdus. If it works, it works.
  • ValdusValdus AustraliaMember Posts: 598 ✭✭✭✭✭ - Grand Achaean
    Thank you all very much. I appreciate your time and help.

    Viva la Bluef.
Sign In to Comment.