Page 1 of 1

Tweak this function to include scarves?

PostPosted: Sunday, 29th October 2017, 04:36
by ClefAria
I just got back into the game after a while, and noticed that if I had a scarf equipped, I was automatically picking up every cloak I found, because of this great quality-of-life function I'd found and put in my init.txt. Could someone show me how to adjust it to account for scarves too, so that I'll only automatically pick up plain cloaks when I have neither a cloak nor a scarf equipped?

  Code:
  if (class == "armour") then
      if it.is_useless then return false end

    sub_type = it.subtype()
    equipped_item = items.equipped_at(armour_slots[sub_type])

    if (sub_type == "cloak") or (sub_type == "helmet") or (sub_type == "gloves") or (sub_type == "boots") then
      if not equipped_item then
        return true
      else
        return it.artefact or it.branded or it.ego
      end
    end

Re: Tweak this function to include scarves?

PostPosted: Sunday, 29th October 2017, 13:12
by emikaela
this one is similar but works like you want it to. why is beyond me though, at a glance they seem to do the same thing, but i'm not very familiar with the syntax.

  Code:
{
add_autopickup_func(function(it, name)
  if it.is_useless then
    return
  end
  if it.class(true) == "armour" then
    local good_slots = {cloak="Cloak", helmet="Helmet", gloves="Gloves",
                        boots="Boots"}
    st, _ = it.subtype()
    if good_slots[st] ~= nil and items.equipped_at(good_slots[st]) == nil then
      return true
    end
  end
end)
}

Re: Tweak this function to include scarves?

PostPosted: Sunday, 29th October 2017, 16:29
by ClefAria
emikaela wrote:this one is similar but works like you want it to. why is beyond me though, at a glance they seem to do the same thing, but i'm not very familiar with the syntax.

  Code:
{
add_autopickup_func(function(it, name)
  if it.is_useless then
    return
  end
  if it.class(true) == "armour" then
    local good_slots = {cloak="Cloak", helmet="Helmet", gloves="Gloves",
                        boots="Boots"}
    st, _ = it.subtype()
    if good_slots[st] ~= nil and items.equipped_at(good_slots[st]) == nil then
      return true
    end
  end
end)
}


EDIT: Or maybe it is, and I pasted it wrong at first...testing.

This doesn't seem to be working, as I just came across a pair of gloves, while not having any gloves, and it didn't want to automatically pick them up.