make titanium goggles wear out

master
flux 2019-08-13 06:18:40 +00:00
parent 060ad6fa74
commit d5aedf5dfb
3 changed files with 32 additions and 4 deletions

View File

@ -1,4 +1,3 @@
default
3d_armor?
more_monoids?
terumet?

View File

@ -1,4 +1,7 @@
if minetest.global_exists("armor") and minetest.global_exists("more_monoids") then
local damage_period = 19
local damage_amount = 100
armor:register_armor("titanium:sam_titanium", {
description = "Night Vision Goggles",
inventory_image = "sam_titanium.png",
@ -18,7 +21,10 @@ if minetest.global_exists("armor") and minetest.global_exists("more_monoids") th
damage_groups = {},
on_equip = function(player, index, stack)
more_monoids.sunlight_monoid:add_change(player, 1, "titanium:goggles")
local wear = stack:get_wear()
if (65535 - wear) > damage_amount then
more_monoids.sunlight_monoid:add_change(player, 1, "titanium:goggles")
end
end,
on_unequip = function(player, index, stack)
more_monoids.sunlight_monoid:del_change(player, "titanium:goggles")
@ -34,7 +40,30 @@ if minetest.global_exists("armor") and minetest.global_exists("more_monoids") th
}
})
-- terumet.register_repairable_item
-- terumet.register_repairable_item -- can't use this here cuz of dependency loop
local timer = 0
minetest.register_globalstep(function(dtime)
timer = timer + dtime;
if timer >= damage_period then
timer = timer - damage_period
for _, player in ipairs(minetest.get_connected_players()) do
local player_name = player:get_player_name()
local armor_inv = minetest.get_inventory({type="detached", name=player_name.."_armor"})
for index = 1, 6 do
local stack = armor_inv:get_stack("armor", index)
if stack:get_name() == "titanium:sam_titanium" then
local wear = stack:get_wear()
if (65535 - wear) > damage_amount then
armor:damage(player, index, stack, damage_amount)
else
more_monoids.sunlight_monoid:del_change(player, "titanium:goggles")
end
end
end
end
end
end)
else
minetest.register_craftitem("titanium:sam_titanium", {

View File

@ -1,3 +1,3 @@
name=titanium
depends=default
optional_depends=3d_armor,more_monoids,terumet
optional_depends=3d_armor,more_monoids