Need LUA help w/ auto-pickup script


Problems running or configuring the software, commands & options, compiling, different platforms, using the interface, documentation, etc.

Dungeon Master

Posts: 3160

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

Post Tuesday, 6th May 2014, 20:04

Need LUA help w/ auto-pickup script

[cross-posted from Advice due to lack of response]

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)
}

Mines Malingerer

Posts: 51

Joined: Monday, 1st April 2013, 04:54

Post Friday, 6th June 2014, 02:03

Re: Need LUA help w/ auto-pickup script

A solution to reduce message spam I have used is to check crawl.messages(number_of_messages) before printing your message.

For example, to only print this message every 6 lines, you could use the following condition.
  Code:
if not string.find(crawl.messages(6), "ATTENTION") then
  crawl.mpr('<cyan>ATTENTION:</cyan> ' .. name)
end

I used this to help reduce the amount of messages printed in SpoilerAlerts.rc, which prints messages that warn the player about dangerous monsters. You might want to increase the number of messages you check.

Another possible solution might be to create a global boolean for each message, and set it to false when you print.

Return to Technical Support

Who is online

Users browsing this forum: No registered users and 24 guests

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