Page 1 of 1

Dealing damage to player?

PostPosted: Sun Jun 28, 2015 02:53
by TheSpaceCat
I'm taking my first steps in making MineTest mods, and one of my projects is a form of uranium that will eventually turn into lead. Is there a way to have the uranium deal damage to the player while they are near it? An ABM possibly?

Re: Dealing damage to player?

PostPosted: Sun Jun 28, 2015 07:38
by TenPlus1
Here is an extract from my PlayerPlus mod that has been changed to deal damage when standing close to uranium ore...

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local time = 0
minetest.register_globalstep(function(dtime)

   time = time + dtime

   -- every 1 second
   if time > 1 then

      -- reset time for next check
      time = 0

      -- check players
      for _,player in ipairs(minetest.get_connected_players()) do
         
         -- where am I?
         local pos = player:getpos()
            
         -- am I near a block of uranium?
         local near = minetest.find_node_near(pos, 1, "uranium:stone_with_uranium")
         if near then
               
            -- am I touching the uranium? if so it hurts
            for _,object in ipairs(minetest.get_objects_inside_radius(near, 1.0)) do
               if object:get_hp() > 0 then
                  object:set_hp(object:get_hp()-1)
               end
            end

         end

      end
      
   end
end)

Re: Dealing damage to player?

PostPosted: Sun Jun 28, 2015 20:12
by TheSpaceCat
Wow! That works just pasted in! Thanks a lot, i'll look at the code to see what you did.