-- Define your walkable block
minetest.register_node("hwmod:damaging_block", {
    description = "Damaging Block",
    tiles = {"hwmod_damaging_block.png"}, -- Replace with your texture file
    groups = {cracky = 3, oddly_breakable_by_hand = 3},
    paramtype = "light",
    passable = true,
    walkable = false,
    pointable = false,
    air_equivalent = true,
    alpha = 160,
    damage_interval = 2, -- Damage interval in seconds
    damage_amount = 1, -- Amount of damage to inflict
    on_construct = function(pos)
    end,
    on_timer = function(pos)
        -- Get all objects in the node's position
        local objects = minetest.get_objects_inside_radius(pos, 1)
        for _, obj in ipairs(objects) do
            -- Check if the object is a player
            if obj:is_player() then
                obj:set_hp(obj:get_hp() - 1)
                minetest.chat_send_player(obj:get_player_name(), "You are taking damage!")
            end
        end
        -- Restart the timer
        return true
    end,
})

-- Register the timer for damaging blocks
minetest.register_abm({
    label = "Damage Players on Damaging Blocks",
    nodenames = {"hwmod:damaging_block"},
    interval = 2, -- Check every second
    chance = 1,
    action = function(pos, node)
        local meta = minetest.get_meta(pos)
        local timer = meta:get_int("timer") or 0
        -- Increment the timer
        timer = timer + 1
        if timer >= meta:get_int("damage_interval") then
            -- Reset the timer
            meta:set_int("timer", 0)
            -- Call on_timer function
            minetest.registered_nodes[node.name].on_timer(pos)
        else
            -- Update the timer in metadata
            meta:set_int("timer", timer)
        end
    end,
})

Изменить пасту