Dungeon Master
Posts: 3160
Joined: Sunday, 5th August 2012, 14:52
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.
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)
}