Tell if player is inside [solved]

User avatar
jordan4ibanez
Member
 
Posts: 1865
Joined: Tue Sep 27, 2011 18:44
GitHub: jordan4ibanez
IRC: jordan4ibanez
In-game: jordan4ibanez

Tell if player is inside [solved]

by jordan4ibanez » Thu Dec 29, 2016 23:54

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.
Last edited by jordan4ibanez on Mon Jan 02, 2017 06:19, edited 1 time in total.
If you can think it, you can make it.
 

User avatar
AiTechEye
Member
 
Posts: 409
Joined: Fri May 29, 2015 21:14

Re: Tell if player is inside

by AiTechEye » Fri Dec 30, 2016 11:43

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
Alive AI Mine/Build AI NPC
Gravitygun HL2
Portalgun Portal
Marssurvive Survive on mars
Bows bows + arrows
SoundCloud (Music)
SoundCloud (Classic)
YouTube
 

User avatar
stu
Member
 
Posts: 737
Joined: Sat Feb 02, 2013 02:51
GitHub: stujones11

Re: Tell if player is inside

by stu » Sat Dec 31, 2016 18:56

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.
 

User avatar
jordan4ibanez
Member
 
Posts: 1865
Joined: Tue Sep 27, 2011 18:44
GitHub: jordan4ibanez
IRC: jordan4ibanez
In-game: jordan4ibanez

Re: Tell if player is inside

by jordan4ibanez » Mon Jan 02, 2017 06:18

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!
If you can think it, you can make it.
 

User avatar
xeranas
Member
 
Posts: 99
Joined: Fri Feb 05, 2016 11:06
GitHub: xeranas

Re: Tell if player is inside

by xeranas » Mon Jan 02, 2017 06:49

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".
 

User avatar
BrandonReese
Member
 
Posts: 836
Joined: Wed Sep 12, 2012 00:44
GitHub: bremaweb
IRC: BrandonReese
In-game: BrandonReese

Re: Tell if player is inside [solved]

by BrandonReese » Mon Jan 02, 2017 15:13

Would minetest.line_of_site be too expensive? Maybe use line_of_site in combination with the light method for more accuracy.
 


Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 58 guests

cron