From 4f04d05b9b6877b19dfb812109b55ed56eca9bd6 Mon Sep 17 00:00:00 2001 From: Vitaliy Olkhin Date: Wed, 24 Jul 2024 11:17:26 +0500 Subject: [PATCH] add radiation protect mod technic forcefield --- function.lua | 176 +++++++++++++++++++++++++++++++++++++++++++++++++++ init.lua | 149 +++---------------------------------------- mod.conf | 3 +- 3 files changed, 187 insertions(+), 141 deletions(-) create mode 100644 function.lua diff --git a/function.lua b/function.lua new file mode 100644 index 0000000..0e493e1 --- /dev/null +++ b/function.lua @@ -0,0 +1,176 @@ +local S = minetest.get_translator("surface_effect") + +surface_effect.dump = function(o) + if type(o) == 'table' then + local s = '{ ' + for k,v in pairs(o) do + if type(k) ~= 'number' then k = '"'..k..'"' end + s = s .. '['..k..'] = ' .. surface_effect.dump(v) .. ',' + end + return s .. '} ' + else + return tostring(o) + end +end + +surface_effect.showLogo = function(player) + local name = player:get_player_name() + + if surface_effect.nplayer[name]['logo'] == 'off' then + local id = player:hud_add({ + name = "logo", + hud_elem_type = "image", + position = {x = 0.2, y = 0.9}, + scale = { + x = -30, + y = -10 + }, + text = "surfaces_effect_Mine_apocalypse.png" + }) + + surface_effect.nplayer[name]['logo'] = "on" + + minetest.log("action", name .. " status logo " .. surface_effect.nplayer[name]['logo'] .. " id " .. id) + end +end + +surface_effect.setHud = function(player) + local name = player:get_player_name() + + if type(surface_effect.nplayer[name]) == 'nil' then + surface_effect.nplayer[name] = { + id = false, + radiation_damage = "OFF", + id_varning_text = false, + logo = 'off', + } + + minetest.log("action", "Load nplayer: " .. surface_effect.dump(surface_effect.nplayer)) + end +end + +surface_effect.checkHazmat = function(player) + local armor = armor:get_weared_armor_elements (player) + + if armor ~= 'nil' then + if type(armor) == 'nil' then return false end + + if armor.head == "hazmat_suit:suit_hazmat" then + return true + else + return false + end + end + + return false +end + +surface_effect.radiaton_off = function(player) + local name = player:get_player_name() + + if surface_effect.nplayer[name]["radiation_damage"] == "ON" then + player:hud_remove(surface_effect.nplayer[name]['id']) + player:hud_remove(surface_effect.nplayer[name]['id_varning_text']) + surface_effect.nplayer[name]["radiation_damage"] = "OFF" + surface_effect.nplayer[name]["id_varning_text"] = nil + end +end + +--Защита от радиацйии +surface_effect.technic_forcefield_radiation_protection = function(pos, player) + if not minetest.get_modpath("technic") then return false end + + local radius = 20 + local protectors = minetest.find_nodes_in_area( + {x = pos.x - radius , y = pos.y - radius , z = pos.z - radius}, + {x = pos.x + radius , y = pos.y + radius , z = pos.z + radius}, + {"technic:forcefield_emitter_on"}) + + if #protectors > 0 then + local npos = protectors[1] + local meta = minetest.get_meta(npos) + local pos1 = vector.subtract(pos, npos) + local range = meta:get_int("range") + + if math.round(pos1.x) < range and math.round(pos1.x) > 0 - range and + math.round(pos1.y) < range and math.round(pos1.y) > 0 - range and + math.round(pos1.z) < range and math.round(pos1.z) > 0 - range + then + --minetest.chat_send_all(dump((0 - range))) + surface_effect.radiaton_off(player) + return true + end + + return false + else + return false + end +end + +su.rediationDomage = function (player, pos) + local name = player:get_player_name() + + if pos.y > -40 and pos.y < 1500 then + if surface_effect.technic_forcefield_radiation_protection(pos,player) == true then + return + end + + minetest.sound_play("surface_effect_radiaciya",{ + gain = 1.0, + to_player = name, + }) + + persistent_api.add_persistent_effect({ + name = "damage_player", -- identifier + object = player, -- affected object + duration = 10, -- this effect will last 10 seconds + effect = function(player) + + if surface_effect.nplayer[name]['radiation_damage'] == "OFF" then + local id = player:hud_add({ + name = "Radiation effect", + hud_elem_type = "image", + position = {x = 0.5, y = 0.5}, + scale = { + x = -100, + y = -110 + }, + text = "surface_effect_rad.png" + }) + + local idtext = player:hud_add({ + name = "Attention! Radiation ", + hud_elem_type = "text", + position = {x = 1, y = 0.5}, + offset = {x = -180, y = 0}, + text = S("Attention! High levels of radiation."), + alignment = -1, + scale = { x = 50, y = 10}, + number = 0xFF0000, + }) + + minetest.after(1.52, function(name, id) + local player = minetest.get_player_by_name(name) + if player then + --player:hud_remove(id) + else + -- player has left the game + end + end, player:get_player_name(), id) + + surface_effect.nplayer[name]['id'] = id + surface_effect.nplayer[name]["radiation_damage"] = "ON" + surface_effect.nplayer[name]["id_varning_text"] = idtext + end + + if surface_effect.checkHazmat(player) == false then + player:set_hp(player:get_hp()-0.1) -- damage the player one half heart + end + + end, + persistence = 2, -- every 0.1 seconds for 10 seconds the previous function will be run. + }) + else + surface_effect.radiaton_off(player) + end +end diff --git a/init.lua b/init.lua index d43d3e3..a779765 100644 --- a/init.lua +++ b/init.lua @@ -1,144 +1,10 @@ -local S = minetest.get_translator("surface_effect") - su = {} -surface_effect = {} - +surface_effect = { + nplayer = {} +} local timer = 0 -local nplayer = {} -local function dump(o) - if type(o) == 'table' then - local s = '{ ' - for k,v in pairs(o) do - if type(k) ~= 'number' then k = '"'..k..'"' end - s = s .. '['..k..'] = ' .. dump(v) .. ',' - end - return s .. '} ' - else - return tostring(o) - end -end - -surface_effect.showLogo = function(player) - local name = player:get_player_name() - - if nplayer[name]['logo'] == 'off' then - local id = player:hud_add({ - name = "logo", - hud_elem_type = "image", - position = {x = 0.2, y = 0.9}, - scale = { - x = -30, - y = -10 - }, - text = "surfaces_effect_Mine_apocalypse.png" - }) - - nplayer[name]['logo'] = "on" - - minetest.log("action", name .. " status logo " .. nplayer[name]['logo'] .. " id " .. id) - end -end - -surface_effect.setHud = function(player) - local name = player:get_player_name() - - if type(nplayer[name]) == 'nil' then - nplayer[name] = { - id = false, - radiation_damage = "OFF", - id_varning_text = false, - logo = 'off', - } - - minetest.log("action", "Load nplayer: " .. dump(nplayer)) - end -end - -surface_effect.checkHazmat = function(player) - local armor = armor:get_weared_armor_elements (player) - - if armor ~= 'nil' then - if type(armor) == 'nil' then return false end - - if armor.head == "hazmat_suit:suit_hazmat" then - return true - else - return false - end - end - - return false -end - -su.rediationDomage = function (player, pos) - local name = player:get_player_name() - - if pos.y > -40 and pos.y < 1500 then - minetest.sound_play("surface_effect_radiaciya",{ - gain = 1.0, - to_player = name, - }) - - persistent_api.add_persistent_effect({ - name = "damage_player", -- identifier - object = player, -- affected object - duration = 10, -- this effect will last 10 seconds - effect = function(player) - - if nplayer[name]['radiation_damage'] == "OFF" then - local id = player:hud_add({ - name = "Radiation effect", - hud_elem_type = "image", - position = {x = 0.5, y = 0.5}, - scale = { - x = -100, - y = -110 - }, - text = "surface_effect_rad.png" - }) - - local idtext = player:hud_add({ - name = "Attention! Radiation ", - hud_elem_type = "text", - position = {x = 1, y = 0.5}, - offset = {x = -180, y = 0}, - text = S("Attention! High levels of radiation."), - alignment = -1, - scale = { x = 50, y = 10}, - number = 0xFF0000, - }) - - minetest.after(1.52, function(name, id) - local player = minetest.get_player_by_name(name) - if player then - --player:hud_remove(id) - else - -- player has left the game - end - end, player:get_player_name(), id) - - nplayer[name]['id'] = id - nplayer[name]["radiation_damage"] = "ON" - nplayer[name]["id_varning_text"] = idtext - end - - if surface_effect.checkHazmat(player) == false then - player:set_hp(player:get_hp()-0.1) -- damage the player one half heart - end - - end, - persistence = 2, -- every 0.1 seconds for 10 seconds the previous function will be run. - }) - else - if nplayer[name]["radiation_damage"] == "ON" then - player:hud_remove(nplayer[name]['id']) - player:hud_remove(nplayer[name]['id_varning_text']) - nplayer[name]["radiation_damage"] = "OFF" - nplayer[name]["id_varning_text"] = nil - end - end -end +dofile(minetest.get_modpath("surface_effect") .. "/function.lua") minetest.register_globalstep(function(dtime) -- every 5 seconds @@ -156,7 +22,6 @@ minetest.register_globalstep(function(dtime) if object then local pos = object:get_pos() su.rediationDomage(player, pos) - surface_effect.showLogo(player) --minetest.chat_send_all(dump(areas:getAreasAtPos(pos))) end end @@ -166,6 +31,8 @@ end) minetest.register_on_newplayer(function(player) surface_effect.setHud(player) + surface_effect.showLogo(player) + if minetest.get_modpath("hazmat_suit") then player:get_inventory():add_item("main", 'hazmat_suit:suit_hazmat 1') end @@ -177,10 +44,12 @@ end) minetest.register_on_joinplayer(function(player, last_login) surface_effect.setHud(player) + surface_effect.showLogo(player) + local name = player:get_player_name() local pos = player:get_pos() - nplayer[name]['logo'] = 'off' + surface_effect.nplayer[name]['logo'] = 'off' end ) minetest.register_on_prejoinplayer(function(name, ip) diff --git a/mod.conf b/mod.conf index eadb6b4..604a586 100644 --- a/mod.conf +++ b/mod.conf @@ -1,6 +1,7 @@ name = surface_effect -description = surface effect test +description = surface effect depends = default, persistent_effects, mobs_monster +optional_depends = technic min_minetest_version = 5.7 title = Surface Effect release = 0 \ No newline at end of file