Mudlet Targetting Alias and Color trigger.

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 Storm
    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 Australia
    Do I like, just paste that in below the echo part in the targeting alias?

    Viva la Bluef.
  • KlendathuKlendathu Eye of the Storm
    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 Australia
    I did the second. It works great. Thank you very much for your help.

    Viva la Bluef.
  • EldEld
    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.
  • 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.
  • 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.

  • KlendathuKlendathu Eye of the Storm
    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."
  • Looks right to me.
  • ValdusValdus Australia
    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.
  • Add it above the highlight lines.

    target = whatever

    killtrigger

    highlight

    should be the order.

  • ValdusValdus Australia
    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.
  • 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()..[[")]])









  • Looks good to me, @Valdus. If it works, it works.
  • ValdusValdus Australia
    Thank you all very much. I appreciate your time and help.

    Viva la Bluef.
Sign In or Register to comment.