Page 1 of 1

Tell if player is inside [solved]

PostPosted: Thu Dec 29, 2016 23:54
by jordan4ibanez
Does anyone know a trick to getting if a player is inside a building or under a cave or anything of that manner?
Light level doesn't really do the trick when it's dark out, and unless there's an api function I'm missing there doesn't seem to be anyway of telling unless a voxel manip is opened and you check 50 nodes above the player for walkable nodes.

Re: Tell if player is inside

PostPosted: Fri Dec 30, 2016 11:43
by AiTechEye
I had to use a function like this in the mars mod viewtopic.php?f=11&t=13913, to check if the air generator not was on a open space.

it checks 10 nodes in the directions: x+,x-,z+,z-,y+

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
   start=0
   distance=10
   for i=start,start+distance,1 do
      local p1={x=pos.x+i,y=pos.y,z=pos.z}
      local p2={x=pos.x-i,y=pos.y,z=pos.z}
      local p3={x=pos.x,y=pos.y,z=pos.z+i}
      local p4={x=pos.x,y=pos.y,z=pos.z-i}
      local p5={x=pos.x,y=pos.y+i,z=pos.z}
      if minetest.get_node(p1) and minetest.get_node(p1).name~="air" then --x+
         return false
      end
      if minetest.get_node(p2) and minetest.get_node(p2).name~="air" then --x-
         return false
      end
      if minetest.get_node(p3) and minetest.get_node(p3).name~="air" then --z+
         return false
      end
      if minetest.get_node(p4) and minetest.get_node(p4).name~="air" then --z-
         return false
      end
      if minetest.get_node(p5) and minetest.get_node(p5).name~="air" then --y+
         return false
      end
   end
   return true

Re: Tell if player is inside

PostPosted: Sat Dec 31, 2016 18:56
by stu
jordan4ibanez wrote:Light level doesn't really do the trick when it's dark out, and unless there's an api function I'm missing.

IIRC minetest.get_node_light allows you to specify time of day but I think there can be no perfect solution to this problem, there will always be some exception that breaks the rule.

Re: Tell if player is inside

PostPosted: Mon Jan 02, 2017 06:18
by jordan4ibanez
Thank you for the replies, but browsing through paramat's snowdrift mod, I found this line of code:
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 ppos = player:getpos()
local outside = minetest.get_node_light(ppos, 0.5) == 15

This easily allows to find if in direct sunlight (outside) and could be useful for many mods in the future!

Re: Tell if player is inside

PostPosted: Mon Jan 02, 2017 06:49
by xeranas
jordan4ibanez wrote:Thank you for the replies, but browsing through paramat's snowdrift mod, I found this line of code:
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 ppos = player:getpos()
local outside = minetest.get_node_light(ppos, 0.5) == 15

This easily allows to find if in direct sunlight (outside) and could be useful for many mods in the future!

Some weather mods use this check, too bad transparent blocks like glass propogates 100% light so if ceiling is made from glass according this check you are still "outside".

Re: Tell if player is inside [solved]

PostPosted: Mon Jan 02, 2017 15:13
by BrandonReese
Would minetest.line_of_site be too expensive? Maybe use line_of_site in combination with the light method for more accuracy.