surface_effect/init.lua

233 lines
5.9 KiB
Lua
Raw Normal View History

2024-07-23 12:18:41 +03:00
local S = minetest.get_translator("surface_effect")
su = {}
surface_effect = {}
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
minetest.register_globalstep(function(dtime)
-- every 5 seconds
if timer > os.time() then
return
end
timer = os.time() + 10
for k, player in ipairs(minetest.get_connected_players()) do
local name = player:get_player_name()
local object = minetest.env:get_player_by_name(name)
surface_effect.setHud(player)
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
end)
--Новый игрок
minetest.register_on_newplayer(function(player)
surface_effect.setHud(player)
if minetest.get_modpath("hazmat_suit") then
player:get_inventory():add_item("main", 'hazmat_suit:suit_hazmat 1')
end
if minetest.get_modpath("farming") then
player:get_inventory():add_item("main", 'farming:bread 99')
end
end)
minetest.register_on_joinplayer(function(player, last_login)
surface_effect.setHud(player)
local name = player:get_player_name()
local pos = player:get_pos()
nplayer[name]['logo'] = 'off'
end )
minetest.register_on_prejoinplayer(function(name, ip)
local player = minetest.get_player_by_name(name)
--Защита игрока отсмерти на спавне
--[[if object then
local pos = object:get_pos()
su.rediationDomage(player, pos)
end]]
end)
minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch, tool_capabilities, dir, damage)
--minetest.chat_send_all(dump(areas:getAreasAtPos(pos)))
local pos = player:get_pos()
local arAtr = areas:getAreasAtPos(pos)
if minetest.get_modpath("areas") then
if type(arAtr[1]) ~= 'nil' then
if arAtr[1]['name'] == 'spawn' then return true end
end
end
end )
--Вызывается, когда игрок покидает игру
--[[minetest.register_on_leaveplayer(function(player, timed_out)
end)]]
local mobs_monster = {
{name = "mobs_monster:sand_monster"},
{name = "mobs_monster:dirt_monster"},
{name = "mobs_monster:dungeon_master"},
{name = "mobs_monster:fire_spirit"},
{name = "mobs_monster:land_guard"},
{name = "mobs_monster:lava_flan"},
{name = "mobs_monster:mese_monster"},
{name = "mobs_monster:oerkki"},
{name = "mobs_monster:stone_monster"},
{name = "mobs_monster:tree_monster"},
}
for akey, v in ipairs(mobs_monster) do
local def = minetest.registered_entities[v.name]
def["on_die"] = function(self, pos)
minetest.add_item(pos, 'bonemeal:bone 5')
end
end