function show_heart(pos) minetest.add_particle( { pos = pos, velocity = {x=0, y=1, z=0}, acceleration = {x=0, y=0, z=0}, -- Spawn particle at pos with velocity and acceleration expirationtime = 1, -- Disappears after expirationtime seconds size = 3, -- Scales the visual size of the particle texture. -- If `node` is set, size can be set to 0 to spawn a randomly-sized -- particle (just like actual node dig particles). texture = "heart.png", -- The texture of the particle glow = 0 -- Optional, specify particle self-luminescence in darkness. -- Values 0-14. } ) end function show_hearts(player) local hearts = 2+math.ceil(math.random()*3) local player_pos = player:get_pos() local looking_dir = player:get_look_dir() looking_dir.y = 0 for i=0,hearts do local vert_offset = 1.5*math.random()-0.75 local y_offset = 0.5*math.random() + 1.5 local offset = vector.multiply(looking_dir, vert_offset) offset.y = y_offset offset.x, offset.z = offset.z, offset.x show_heart(vector.add(player_pos,offset)) end end minetest.register_on_player_hpchange(function(player, hp_change, reason) if hp_change < 0 then show_hearts(player) end end)