diff --git a/function.lua b/function.lua index 8b5da30..c8e610c 100644 --- a/function.lua +++ b/function.lua @@ -29,7 +29,6 @@ surface_effect.showLogo = function(player) }) surface_effect.nplayer[name]['logo'] = "on" - minetest.log("action", name .. " status logo " .. surface_effect.nplayer[name]['logo'] .. " id " .. id) end end @@ -43,14 +42,43 @@ surface_effect.setHud = function(player) id_varning_text = false, logo = 'off', id_mask = false, + id_status_chemical = false, } minetest.log("action", "Load nplayer: " .. surface_effect.dump(surface_effect.nplayer)) end end +--Состояние костюма химической защиты вывод в процентах. +surface_effect.getHazmatState = function(player) + local name, inv = armor:get_valid_player(player) + + if not name then + return -- Armor not initialized yet + end + + if not inv:contains_item("armor", "hazmat_suit:suit_hazmat") then + return -- Skip checking every stack + end + + for i=1, inv:get_size("armor") do + local stack = inv:get_stack("armor", i) + + if stack:get_name() == "hazmat_suit:suit_hazmat" then + local arm = 65535 / 100 + local percent = (65535 - stack:get_wear()) / arm + + --stack:add_wear(1) + --inv:set_stack("armor", i, stack) + --armor:save_armor_inventory(player) + return math.round(percent) + end + end +end + surface_effect.checkHazmat = function(player) local armor = armor:get_weared_armor_elements (player) + surface_effect.getHazmatState(player) if armor ~= 'nil' then if type(armor) == 'nil' then return false end @@ -122,11 +150,36 @@ surface_effect.mask = function(player) text = "surface_effect_mask.png" }) + surface_effect.nplayer[name]["id_status_chemical"] = player:hud_add({ + name = "Chemical protection status indicator", + hud_elem_type = "text", + position = {x = 0.7, y = 0.1}, + offset = {x = 60, y = -50}, + scale = { + x = 50, + y = 10 + }, + z_index = -99, + size = 2, + text = S("Chemical protection status: @1%", surface_effect.getHazmatState(player)), + number = 0x000000 + }) + surface_effect.nplayer[name]["id_mask"] = id elseif surface_effect.nplayer[name]["id_mask"] ~= false and surface_effect.checkHazmat(player) == false then player:hud_remove(surface_effect.nplayer[name]['id_mask']) surface_effect.nplayer[name]["id_mask"] = false + + player:hud_remove(surface_effect.nplayer[name]['id_status_chemical']) + surface_effect.nplayer[name]["id_status_chemical"] = false + + return + end + + if surface_effect.nplayer[name]["id_status_chemical"] ~= false then + player:hud_change(surface_effect.nplayer[name]["id_status_chemical"], + "text", S("Chemical protection status: @1%", surface_effect.getHazmatState(player))) end return @@ -186,3 +239,19 @@ su.rediationDomage = function (player, pos) surface_effect.radiaton_off(player) end end + +surface_effect.detectNuclides = function (player) + local inv = player:get_inventory() + if inv:contains_item("main", "surface_effect:dosimeter") then + return true + end + return false + + --[[for i=1, inv:get_size("main") do + local stack = inv:get_stack("main", i) + if stack:get_name() == "surface_effect:dosimeter" then + use_battery(stack) + inv:set_stack("main", i, stack) + end + end]] +end \ No newline at end of file diff --git a/init.lua b/init.lua index d528722..9277f68 100644 --- a/init.lua +++ b/init.lua @@ -6,6 +6,7 @@ local timer = 0 dofile(minetest.get_modpath("surface_effect") .. "/function.lua") dofile(minetest.get_modpath("surface_effect") .. "/nodes.lua") +dofile(minetest.get_modpath("surface_effect") .. "/register_abm.lua") minetest.register_globalstep(function(dtime) -- every 5 seconds @@ -110,9 +111,18 @@ local on_radiation_damage = function(player, damage, pos) end damage = math.floor(damage) if damage > 0 then - minetest.log("action", player:get_player_name() .. " takes " .. tostring(damage) .. " damage from mese radiation damage at " .. minetest.pos_to_string(pos)) - player:set_hp(player:get_hp() - damage) - minetest.sound_play({name = "radiant_damage_geiger", gain = math.min(1, damage/10)}, {to_player=player:get_player_name()}) + minetest.log("action", player:get_player_name() .. " Hazmat " .. surface_effect.dump(surface_effect.checkHazmat(player)) .. " pos" .. minetest.pos_to_string(pos)) + + if surface_effect.checkHazmat(player) == false then + minetest.log("action", player:get_player_name() .. " takes " .. tostring(damage) .. " damage from radiation damage earth at " .. minetest.pos_to_string(pos)) + player:set_hp(player:get_hp() - damage) + end + + if surface_effect.detectNuclides(player) then + minetest.sound_play({name = "radiant_damage_geiger", gain = math.min(1, damage/10)}, { + to_player=player:get_player_name() + }) + end end end @@ -122,7 +132,7 @@ radiant_damage.register_radiant_damage("radioactive_earth", { --inverse_square_falloff = true, emitted_by = {["surface_effect:radioactive_earth"] = 0.5}, attenuated_by = {['air'] = 0.4, ['default:grass_1'] = 0.5}, - default_attenuation = 1, + default_attenuation = 2, on_damage = on_radiation_damage, }) diff --git a/locale/surface_effect.ru.tr b/locale/surface_effect.ru.tr index 52f9705..84fdc70 100644 --- a/locale/surface_effect.ru.tr +++ b/locale/surface_effect.ru.tr @@ -1,5 +1,7 @@ # textdomain: surface_effect Attention! High levels of radiation.=Внимание! Высокий уровень радиации. +Chemical protection status: @1%=Состояние химзащиты: @1% #nodes lua -Irradiated Earth=Облученная земля \ No newline at end of file +Irradiated Earth=Облученная земля +Dosimeter=Дозиметр \ No newline at end of file diff --git a/mod.conf b/mod.conf index 604a586..f9d79d7 100644 --- a/mod.conf +++ b/mod.conf @@ -1,6 +1,6 @@ name = surface_effect description = surface effect -depends = default, persistent_effects, mobs_monster +depends = default, persistent_effects, mobs_monster, radiant_damage optional_depends = technic min_minetest_version = 5.7 title = Surface Effect diff --git a/nodes.lua b/nodes.lua index fc707df..e2265e0 100644 --- a/nodes.lua +++ b/nodes.lua @@ -16,13 +16,7 @@ minetest.register_node("surface_effect:radioactive_earth", { }), }) -minetest.register_abm({ - nodenames = {"default:dirt_with_grass"}, - interval = 10, - chance = 50, - action = function(pos) - if pos.y > -10 and pos.y < 1500 then - minetest.env:add_node(pos, {name="surface_effect:radioactive_earth"}) - end - end, +minetest.register_tool("surface_effect:dosimeter", { + description = S("Dosimeter"), + inventory_image = "surface_effect_dosimeter.png" }) \ No newline at end of file diff --git a/register_abm.lua b/register_abm.lua new file mode 100644 index 0000000..dffd144 --- /dev/null +++ b/register_abm.lua @@ -0,0 +1,25 @@ +local speed = minetest.setting_get("time_speed")/96 + +minetest.register_abm({ + nodenames = {"default:dirt_with_grass"}, + interval = 10/speed, + chance = 50, + action = function(pos) + if pos.y > -10 and pos.y < 1500 then + minetest.env:add_node(pos, {name="surface_effect:radioactive_earth"}) + end + end, +}) + +if minetest.get_modpath("areas") then + minetest.register_abm({ + nodenames = {"ethereal:grove_dirt"}, + interval = 10/speed, + chance = 50, + action = function(pos) + if pos.y > -10 and pos.y < 1500 then + minetest.env:add_node(pos, {name="surface_effect:radioactive_earth"}) + end + end, + }) +end \ No newline at end of file diff --git a/sounds/surface_effect_radiaciya.ogg b/sounds/surface_effect_radiaciya.ogg index fbe4d0d..bed5c7f 100644 Binary files a/sounds/surface_effect_radiaciya.ogg and b/sounds/surface_effect_radiaciya.ogg differ diff --git a/textures/surface_effect_dosimeter.png b/textures/surface_effect_dosimeter.png new file mode 100644 index 0000000..dcef9a9 Binary files /dev/null and b/textures/surface_effect_dosimeter.png differ diff --git a/textures/surface_effect_mask.png b/textures/surface_effect_mask.png index c835d93..367cd89 100644 Binary files a/textures/surface_effect_mask.png and b/textures/surface_effect_mask.png differ