Dealing damage to player?

TheSpaceCat
New member
 
Posts: 2
Joined: Sun Jun 28, 2015 02:49
In-game: SpaceCat

Dealing damage to player?

by TheSpaceCat » Sun Jun 28, 2015 02:53

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?
 

User avatar
TenPlus1
Member
 
Posts: 1874
Joined: Mon Jul 29, 2013 13:38
GitHub: tenplus1

Re: Dealing damage to player?

by TenPlus1 » Sun Jun 28, 2015 07:38

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)
Last edited by TenPlus1 on Mon Jun 29, 2015 06:33, edited 1 time in total.
 

TheSpaceCat
New member
 
Posts: 2
Joined: Sun Jun 28, 2015 02:49
In-game: SpaceCat

Re: Dealing damage to player?

by TheSpaceCat » Sun Jun 28, 2015 20:12

Wow! That works just pasted in! Thanks a lot, i'll look at the code to see what you did.
 


Return to Minetest General

Who is online

Users browsing this forum: No registered users and 8 guests

cron