surface_effect/init.lua

141 lines
4.2 KiB
Lua
Raw Normal View History

2024-07-23 12:18:41 +03:00
su = {}
surface_effect = {
nplayer = {}
}
2024-07-23 12:18:41 +03:00
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")
2024-07-23 12:18:41 +03:00
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
surface_effect.mask(player)
2024-07-23 12:18:41 +03:00
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)
--minetest.chat_send_all(dump(areas:getAreasAtPos(pos)))
end
end
end)
--Новый игрок
minetest.register_on_newplayer(function(player)
surface_effect.setHud(player)
surface_effect.showLogo(player)
2024-07-23 12:18:41 +03:00
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)
surface_effect.showLogo(player)
2024-07-23 12:18:41 +03:00
local name = player:get_player_name()
local pos = player:get_pos()
surface_effect.mask(player)
2024-07-23 12:18:41 +03:00
surface_effect.nplayer[name]['logo'] = 'off'
2024-07-23 12:18:41 +03:00
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
local on_radiation_damage = function(player, damage, pos)
local radiation_multiplier = player:get_armor_groups().radiation
if radiation_multiplier then
damage = damage * radiation_multiplier / 100
end
damage = math.floor(damage)
if damage > 0 then
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
radiant_damage.register_radiant_damage("radioactive_earth", {
interval = 1,
range = 3,
--inverse_square_falloff = true,
emitted_by = {["surface_effect:radioactive_earth"] = 0.5},
attenuated_by = {['air'] = 0.4, ['default:grass_1'] = 0.5},
default_attenuation = 2,
on_damage = on_radiation_damage,
})
minetest.register_on_player_receive_fields(function(player, formname, fields)
surface_effect.mask(player)
end)