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

Helpful Mudlet snippets!

AesiAesi Posts: 1,222Member @ - Epic Achaean
edited December 2015 in Tech Support
Hey there!

I figure this might be a good addition for people getting their feet wet. The point is to post a snippet of code that proves helpful to others. Be it alias, trigger, script, etc. Please state whether it's for mudlet or Nexus or otherwise!

I will kick us off.

Mudlet:

Script:
function isClass(className)
if string.lower(gmcp.Char.Status.class):match(string.lower(className)) == string.lower(className) then
return true
else
return false
end
end


Usage: 

if isClass("runewarden") then
--stuff!
else
--things!
end if isClass("dragon") then
--stuff!
else
--things!
end


- Easy, non long way to tell what class you are.


Post edited by Sarapis on
AustereAdetRohaiDairon

Comments

  • TrevizeTrevize Posts: 1,517Member @ - Epic Achaean
    edited October 2015
    Love the idea.

    A few tips to shorten that one, you can call lower() like you did match(), use find() instead of match(), use type() to check if it returned a number (it returns nil if it doesn't find it) instead of using if statements, then you end up with:
    function isClass(className)
    return type(gmcp.Char.Status.class:lower():find(className:lower())) == "number"
    end
    Current scripts: GoldTracker 1.2, mData 1.1
    Site: https://github.com/trevize-achaea/scripts/releases
    Thread: http://forums.achaea.com/discussion/4064/trevizes-scripts
    Latest update: 9/26/2015 better character name handling in GoldTracker, separation of script and settings, addition of gold report and gold distribute aliases.
    Aesi
  • AesiAesi Posts: 1,222Member @ - Epic Achaean
    Trevize said:
    Love the idea.

    A few tips to shorten that one, you can call lower() like you did match(), use find() instead of match(), use type() to check if it returned a number (it returns nil if it doesn't find it) instead of using if statements, then you end up with:
    function isClass(className)
    return type(gmcp.Char.Status.class:lower():find(className:lower())) == "number"
    end
    didn't think you could chain those! awesome.
  • TrevizeTrevize Posts: 1,517Member @ - Epic Achaean
    One of my own, something I made goofing off, how to check what health a certain level/con/bracelet combination will give. Mudlet.

      gethealth = function (arg)
        local level = arg.level
        local olevel = 0
    
        if level > 100 then
          olevel = level - 100
          level = 100
        end
    
        local con = arg.con
    
        local bracelets = arg.bracelets or 0
    
        if level < 1 or level >= 200 then
          return "Invalid character level. Please choose a character level between 1 and 199."
        elseif bracelets < 0 or bracelets > 3 then
          return "Invalid bracelet level. Please choose a bracelet level between 0 and 3."
        else
          return math.floor ((300+level*(3*con+4)+olevel*(3*con-16))*(1+bracelets*0.05))
        end -- if
      end, -- func


    You call it (note the curly braces) like: gethealth {level=101,con=23,bracelets=2}
    Current scripts: GoldTracker 1.2, mData 1.1
    Site: https://github.com/trevize-achaea/scripts/releases
    Thread: http://forums.achaea.com/discussion/4064/trevizes-scripts
    Latest update: 9/26/2015 better character name handling in GoldTracker, separation of script and settings, addition of gold report and gold distribute aliases.
    Rohai
  • DeladanDeladan Posts: 647Member ✭✭✭✭ - Eminent

    function GetRoomExits()

    roomexits = nil

    for i,v in pairs(gmcp.Room.Info.exits) do

    if not roomexits then

    roomexits = string.upper(i)

    else

    roomexits = roomexits..","..string.upper(i)

    end

    end

    roomexits = roomexits or "TRAPPED!"


    roomlabel : setFgColor("white")


    roomlabel:echo("<b>Exits<br>" ..roomexits, nil, "c")

    end


    roomlabel = Geyser.Label:new({name="Room Exits",x="0.5%", y="94%",width="25.5%", height=35,fontSize = 10,})

    roomlabel : setFgColor("white")

    roomlabel:setStyleSheet[[

    border-image: url(C:/MudletGFX/chat.png);

    ]]


    registerAnonymousEventHandler("gmcp.Room.Info", "GetRoomExits")


    Rohai
  • TrevizeTrevize Posts: 1,517Member @ - Epic Achaean
    Here's a lua iterator that runs through a table's keys alphabetically. Non-client-specific as long as it runs lua.

    sortedpairs = function (tbl)
      local i = 0
      local tmp = {}
      for n in pairs (tbl) do table.insert (tmp, n) end
      table.sort (tmp)
      return function ()
        i = i + 1
        if tmp[i] ~= nil then return tmp[i], tbl[tmp[i]] end
      end -- func
    end -- func


    As an example...

    Given table: t = {b=true,a=true,c=true}
    You use it like so: for k, v in sortedpairs (t) do print (k, v) end
    And the result is:

    a    true    
    b    true    
    c    true

    I use this a lot when displaying output, like my rift.
    Current scripts: GoldTracker 1.2, mData 1.1
    Site: https://github.com/trevize-achaea/scripts/releases
    Thread: http://forums.achaea.com/discussion/4064/trevizes-scripts
    Latest update: 9/26/2015 better character name handling in GoldTracker, separation of script and settings, addition of gold report and gold distribute aliases.
    Rohai
  • MediMedi Posts: 94Member
    edited November 2015
    Does anyone have something for wielding?

    Here is a target herb/mineral highlight that I use:
    function colourHerbs(herb)
    -- cecho(herb)
    if (herb == "aurum flake") or (herb == "piece of kelp") then
    cecho("\n<white:green>[ KELP ][ KELP ]\n")
    targeat:cecho("<white:green>[ KELP ]\n")
    elseif (herb == "lobelia seed") or (herb == "argentum flake") then
    cecho("\n<white:orange>[ LOBELIA ][ LOBELIA ]\n")
    targeat:cecho("<white:orange>[ LOBELIA ]\n")
    elseif (herb == "kola nut") or (herb == "quartz grain") then
    cecho("\n<white:dark_orchid>[ KOLA ][ KOLA ]\n")
    targeat:cecho("<white:dark_orchid>[ KOLA ]\n")
    elseif (herb == "cuprum flake") or (herb == "bellwort flower") then
    cecho("\n<white:gold>[ Bellwort ][ Bellwort ]\n")
    targeat:cecho("<white:gold>[ Bellwort ]\n")
    elseif (herb == "hawthorn berry") or (herb == "calamine crystal") then
    cecho("\n<white:brown>[ Hawthorn ][ Hawthorn ]\n")
    targeat:cecho("<white:brown>[ Hawthorn ]\n")
    elseif (herb == "stannum flake") or (herb == "prickly ash bark") then
    cecho("\n<white:purple>[ ASH ][ ASH ]\n")
    targeat:cecho("<white:purple>[ ASH ]\n")
    elseif (herb == "ginseng root") or (herb == "ferrum flake") then
    cecho("\n<white:blue>[ GINSENG ][ GINSENG ]\n")
    targeat:cecho("<white:blue>[ GINSENG ]\n")
    elseif (herb == "bloodroot leaf") or (herb == "magnesium chip") then
    cecho("\n<white:red>[ BROOT ][ BROOT ]\n")
    targeat:cecho("<white:red>[ BROOT ]\n")
    elseif (herb == "goldenseal root") or (herb == "plumbum flake") then
    cecho("\n<white:yellow>[ GSEAL ][ GSEAL ]\n")
    targeat:cecho("<white:yellow>[ GSEAL ]\n")
    end -- if
    end -- colourHerbs
    Called by a simple trigger for the eat line:
    if matches[2] == target then
    colourHerbs(matches[4])
    end
    Edit: You can definitely rewrite my code to be better, but I wrote it years ago, and it works =D
  • AntoniusAntonius Posts: 4,668Member @@ - Legendary Achaean
    @Medi If you don't want to use containers (scabbards, belthooks, etc), you don't need a script for wielding (except possibly in retardation?). WIELD <left> <right> will handle unwielding items already in your hands for you. If you do want to use containers, it gets a lot more complicated quite quickly.
    Medi
  • AtalkezAtalkez Posts: 4,790Member @@ - Legendary Achaean
    edited November 2015
    Just a few things that have helped me in my offenses for BM and Serpent
    BM:
    --Alias--
    ^(ice|void|fire|light)$
    if matches[2] == "ice" then
    infuse = "infuse ice"
    elseif matches[2] == "void" then
    infuse = "infuse void"
    elseif matches[2] == "fire" then
    infuse = "infuse fire"
    elseif matches[2] == "light" then
    infuse = "infuse lightning"
    end

    --Alias--
    ^(par|ast|sli)$
    if matches[2] == "par" then
    strike = "strike " ..target.. " neck"
    elseif matches[2] == "ast" then
    strike = "strike " ..target.. " throat"
    elseif matches[2] == "sli" then
    strike = "strike " ..target.. " underarm"
    end

    --Alias--
    ^lsl$
    send("setalias lsl " ..infuse.. "/legslash " ..target.. " left/" ..strike..";queue add eqbal lsl")


    Serpent:

    --Alias--
    ^d([a-z])([a-z]?)$
    if gmcp.Char.Status.class == "Serpent" then
    local venom = {
    a = "aconite",
    b = "digitalis",
    c = "curare",
    d = "delphinium",
    e = "eurypteria",
    g = "gecko",
    h = "selarnia",
    i = "epseth",
    k = "kalmia",
    l = "larkspur",
    m = "monkshood",
    n = "selarnia",
    o = "voyria",
    p = "prefarar",
    r = "darkshade",
    s = "slike",
    u = "euphorbia",
    v = "vernalius",
    x = "xentio",
    z = "vardrax",
    }
    ven1 = venom[matches[2]]
    ven2 = venom[matches[3]]
    send("dstab " ..target.. " " ..ven1.. " " ..ven2)

    --Alias--
    ^hyp(\d+)$
    if gmcp.Char.Status.class == "Serpent" then
    hypnoStep = 1
    if matches[2] == "1" then
    hyp = "hyp1"
    cecho("\n<red>[<blue>Hypnotising " ..target.. " 1<red>]")
    send("hypnotise " ..target)
    elseif matches[2] == "2" then
    hyp = "hyp2"
    cecho("\n<red>[<blue>Hypnotising " ..target.. " 2<red>]")
    send("hypnotise " ..target)
    elseif matches[2] == "3" then
    hyp = "hyp3"
    cecho("\n<red>[<blue>Hypnotising " ..target.. " 3<red>]")
    send("hypnotise " ..target)
    elseif matches[2] == "4" then
    hyp = "hyp4"
    cecho("\n<red>[<blue>Hypnotising " ..target.. " 4<red>]")
    send("hypnotise " ..target)
    elseif matches[2] == "5" then
    hyp = "hyp5"
    cecho("\n<red>[<blue>Hypnotising " ..target.. " 5<red>]")
    send("hypnotise " ..target)
    elseif matches[2] == "6" then
    hyp = "hyp6"
    cecho("\n<red>[<blue>Hypnotising " ..target.. " 6<red>]")
    send("hypnotise " ..target)
    elseif matches[2] == "7" then
    hyp = "hyp7"
    cecho("\n<red>[<blue>Hypnotising " ..target.. " 7<red>]")
    send("hypnotise " ..target)
    elseif matches[2] == "8" then
    hyp = "hyp8"
    cecho("\n<red>[<blue>Hypnotising " ..target.. " 8<red>]")
    send("hypnotise " ..target)
    elseif matches[2] == "9" then
    hyp = "hyp9"
    cecho("\n<red>[<blue>Hypnotising " ..target.. " 9<red>]")
    send("hypnotise " ..target)
    end
    end

    if hyp == "hyp1" then
    hypnoAffs = {
    "clearalias hyp;setalias hyp suggest " ..target.. " stuff;queue add eqbal hyp",
    }
    elseif hyp == "hyp2" then
    hypnoAffs = {
    "same stuff",
    }
    elseif hyp == "hyp3" then
    hypnoAffs = {
    "same stuff",
    }
    elseif hyp == "hyp4" then
    hypnoAffs = {
    "same stuff",
    }
    elseif hyp == "hyp5" then
    hypnoAffs = {
    "same stuff",
    }
    elseif hyp == "hyp6" then
    hypnoAffs = {
    "same stuff",
    }
    elseif hyp == "hyp7" then
    hypnoAffs = {
    "same stuff",
    }
    elseif hyp == "hyp8" then
    hypnoAffs = {
    "same stuff",
    }
    elseif hyp == "hyp9" then
    hypnoAffs = {
    "same stuff",
    }
    end

    --Alias--
    ^hyp$
    hypnoStack()

    --Script--
    function hypnoStack()
    send(hypnoAffs[hypnoStep])
    end

    --Trigger--
    ^You issue the suggestion, concealing it deep within (\w+)'s mind\.$

    hypnoStep = hypnoStep+1

    deleteFull()

    cecho("\n<red>[<blue>Suggest Succeeded<red>]")




    You hug Aurora compassionately.
    AesiJacenAereidhna
  • AntoniusAntonius Posts: 4,668Member @@ - Legendary Achaean
    You could massively reduce that hypnosis script, make it easier to add additional hypnosis stacks, and make it more user friendly, by doing something like this:

    -- Script
    
    hypnoAffs = {
    	{
    		"aff1", "aff2", "aff3", "aff4", "aff5"
    	}, -- 1
    	{
    		"aff2", "aff6", "aff7"
    	}, -- 2,
    	-- etc.
    }
    
    function hypnoStack()
    	local list = hypnoAffs[hyp]
    	if list and list[hypnoStep] then
    		sendAll("setalias hyp suggest " .. target .. " " .. list[hypnoStep], "queue add eqbal hyp", false)
    	else
    		-- message indicating end of stack or invalid list
    	end
    end
    
    -- Alias
    
    ^hyp(\d+)$
    -- if we're not a Serpent, do nothing
    if gmcp.Char.Status.class ~= "Serpent" then return end
    hypnoStep = 1
    hyp = tonumber(matches[2])
    local affs = hypnoAffs[hyp]
    if affs then
    	cecho("\n[Hypnotising " ..target.. " with " .. string.concat(affs, ", ") .. ".]")
    	send("hypnotise " ..target)
    else
    	-- some kind of error message indicating you've tried to use a list that doesn't exist
    end
    
    -- Alias
    ^hyp$
    hypnoStack()
    
    -- Trigger
    ^You issue the suggestion, concealing it deep within (\w+)'s mind\.$
    
    hypnoStep = hypnoStep+1
    deleteFull()
    cecho("\n[Suggest Succeeded]")
    Adding a stack is as simple as adding a new entry into the hypnoAffs table, and it's just a list of affs itself, not the full commands, so it saves on typing (bonus: you can display exactly what it's going to suggest when picking the stack). Added some comments where you'd inform the user that they've tried to do something that won't work, like use a hypno stack they haven't defined or tried to suggest when there's no more suggestions.
    AtalkezSobriquetJacen
  • SeifurSeifur Posts: 64Member ✭✭✭ - Distinguished
    edited December 2015
    Convert a number into a comma-separated string (ex: 1500000 to 1,500,000).
    function comma (num)
       local subs
       while true do
          num, subs = tostring(num):gsub("^(-?%d+)(%d%d%d)", "%1,%2")
          if subs == 0 then break end
       end
       return num
    end
    retired
    AesiYae
Sign In to Comment.