Skip to content

Commit

Permalink
make titanium goggles wear out
Browse files Browse the repository at this point in the history
  • Loading branch information
fluxionary committed Aug 13, 2019
1 parent 060ad6f commit d5aedf5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
1 change: 0 additions & 1 deletion depends.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
default
3d_armor?
more_monoids?
terumet?
33 changes: 31 additions & 2 deletions goggles.lua
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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")
Expand All @@ -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", {
Expand Down
2 changes: 1 addition & 1 deletion mod.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
name=titanium
depends=default
optional_depends=3d_armor,more_monoids,terumet
optional_depends=3d_armor,more_monoids

0 comments on commit d5aedf5

Please sign in to comment.