stujones11 / minetest-3d_armor

Visible player armor & wielded items for minetest
Other
56 stars 98 forks source link

[PR] Add wear calculation #146

Open appgurueu opened 6 years ago

appgurueu commented 6 years ago
local wear=0
    local divide=0
    for i=0,5 do
        local add=player:get_inventory({type="detached", name=name.."_armor"}):get_stack("armor",i):get_wear()
        if not (add == 0) then
            divide=divide+1
        end
        wear=wear+add
    end
    formspec = formspec:gsub("armor_preview", armor.textures[name].preview)
    formspec = formspec:gsub("armor_level", armor.def[name].level)
    formspec = formspec:gsub("armor_wear",  100-((math.floor(wear/(divide*65535)*1000+0.5)/10) or "0").."")

BTW, wear bar would be nice too.

Note you also have to change :

armor.formspec = armor.formspec..
    "label[5,1;"..F("Level")..": armor_level]"..
    "label[5,1.5;"..F("Heal")..":  armor_attr_heal]"..
    "label[5,3;"..F("Wear")..":  armor_wear]"

:+1: Keep up the good work !!! Great mods !!!