Help with a LUA script


Ask fellow adventurers how to stay alive in the deep, dark, dangerous dungeon below, or share your own accumulated wisdom.

Dungeon Master

Posts: 3160

Joined: Sunday, 5th August 2012, 14:52

Post Monday, 5th May 2014, 13:46

Help with a LUA script

I'm trying to adapt Medar's lua autopickup script. Right now the script picks up auxiliary armor that's enchanted or when your auxiliary slot is unfilled or under max enchantment. I wanted to add some code to not pickup certain classes of exceptional items, but to notify me of their existence instead (demon weapons, lajatangs, dragon armour, etc.). However, my code seems to notify me every time I try to autoexplore, which results in absurd spam. Is there a way to have this warning trigger only when such an item is noticed for the first time (even if in a pile of items) and then never again?

Below is the code for the autopickup function. The part in red is what I added.

  Code:
{
local function armour_plus(it)
  local plus = string.gsub(it.name(), "+", "", 1)
  return tonumber(string.gsub(plus, "[^-%d]", ""))
end

local function autopickup(it, name)
    if it.artefact then
        return true
    end
    local class = it.class(true)
    if class == "armour" then
        local good_slots = {cloak="Cloak", helmet="Helmet",
                            gloves="Gloves", boots="Boots"}
        st, _ = it.subtype()
        if good_slots[st] ~= nil then
            if it.branded then return true end

            local cur = items.equipped_at(good_slots[st])
            if cur == nil then return true end

            if cur.branded or cur.artefact then return false end
            if armour_plus(it) ~= nil then
                if armour_plus(it) > armour_plus(cur) then return true end
            else
                if armour_plus(cur) < 2 then return true end
            end
        elseif st == "body" then
            local cur = items.equipped_at("armour")
            if cur == nil then return false end
            if cur.name("qual") ~= it.name("qual") then return false end

            if it.branded then return true end

            if cur.branded or cur.artefact then return false end
            if armour_plus(it) ~= nil then
                if armour_plus(it) > armour_plus(cur) then return true end
            else
                if armour_plus(cur) < 2 then return true end
            end
        end
       [color=#FF0000]
        if name:find("dragon skin") or
           name:find("dragon armour") or
           name:find("crystal") then
           crawl.mpr('<cyan>ATTENTION:</cyan> ' .. name)
        end
    end

    if class == "weapon" then
        if name:find("distortion") then
            return true
        end
        if name:find("demon") or
           name:find("bastard") or
           name:find("eveningstar") or
           name:find("lajatang") or
           name:find("quick blade") then
           crawl.mpr('<cyan>ATTENTION:</cyan> ' .. name)
        end
    end
    [/color]

    if class == "missile" then
        if name:find("curare") then
            return true
        end
    end

    return false
end

add_autopickup_func(autopickup)
}

Ziggurat Zagger

Posts: 11111

Joined: Friday, 8th February 2013, 12:00

Post Monday, 5th May 2014, 13:52

Re: Help with a LUA script

I think it can be accomplished by having a new local variable outside of those functions, the variable (array or dictionary, not sure about name in lua) can store whether specific items have been seen before.

Return to Dungeon Crawling Advice

Who is online

Users browsing this forum: No registered users and 158 guests

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.