minetest-mods / 3d_armor

Visible player armor & wielded items for minetest
Other
17 stars 39 forks source link

get_armor #145

Closed SkyBuilder1717 closed 6 months ago

SkyBuilder1717 commented 6 months ago

how to ger armor of the player? if a player wears a shield in armor, the code will run, do you have any ideas how to realize this?

BuckarooBanzay commented 6 months ago

something like this might get you started: https://github.com/mt-mods/spacesuit/blob/master/drowning.lua#L3-L12

    local _, armor_inv = armor.get_valid_player(armor, player, "[spacesuit]")
    if not armor_inv then
        -- inventory not found (somehow?), skip check
        return
    end

    local has_helmet = armor_inv:contains_item("armor", "spacesuit:helmet")
    local has_chestplate = armor_inv:contains_item("armor", "spacesuit:chestplate")
    local has_pants = armor_inv:contains_item("armor", "spacesuit:pants")
    local has_boots = armor_inv:contains_item("armor", "spacesuit:boots")

disclaimer: this is from an older mod, there might be a better way to do this :)

SkyBuilder1717 commented 6 months ago

something like this might get you started: https://github.com/mt-mods/spacesuit/blob/master/drowning.lua#L3-L12

  local _, armor_inv = armor.get_valid_player(armor, player, "[spacesuit]")
  if not armor_inv then
      -- inventory not found (somehow?), skip check
      return
  end

  local has_helmet = armor_inv:contains_item("armor", "spacesuit:helmet")
  local has_chestplate = armor_inv:contains_item("armor", "spacesuit:chestplate")
  local has_pants = armor_inv:contains_item("armor", "spacesuit:pants")
  local has_boots = armor_inv:contains_item("armor", "spacesuit:boots")

disclaimer: this is from an older mod, there might be a better way to do this :)

thanks