2012-01-26 18:10:49 -05:00
|
|
|
function OnBlockPlace( Block, Player )
|
|
|
|
|
|
|
|
-- dont check if the direction is in the air
|
|
|
|
if Block.m_Direction ~= -1 then
|
|
|
|
|
2012-03-19 16:30:24 -04:00
|
|
|
if( Player:HasPermission("core.build") == false ) then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2012-01-26 18:10:49 -05:00
|
|
|
local X = Block.m_PosX
|
|
|
|
local Y = Block.m_PosY
|
|
|
|
local Z = Block.m_PosZ
|
|
|
|
X, Y, Z = AddDirection( X, Y, Z, Block.m_Direction )
|
2012-03-04 09:09:35 -05:00
|
|
|
if( Y >= 256 or Y < 0 ) then
|
2012-01-26 18:10:49 -05:00
|
|
|
return true
|
|
|
|
end
|
2012-02-15 08:16:42 -05:00
|
|
|
|
|
|
|
local CheckCollision = function( Player )
|
|
|
|
-- drop the decimals, we only care about the full block X,Y,Z
|
|
|
|
local PlayerX = math.floor(Player:GetPosX(), 0)
|
|
|
|
local PlayerY = math.floor(Player:GetPosY(), 0)
|
|
|
|
local PlayerZ = math.floor(Player:GetPosZ(), 0)
|
|
|
|
|
|
|
|
local BlockX = Block.m_PosX
|
|
|
|
local BlockY = Block.m_PosY
|
|
|
|
local BlockZ = Block.m_PosZ
|
|
|
|
|
|
|
|
-- player height is 2 blocks, so we check the position and then offset it up one
|
|
|
|
-- so they can't place a block on there face
|
|
|
|
|
|
|
|
local collision = false
|
|
|
|
if Block.m_Direction == 0 then if PlayerY == BlockY-2 and PlayerX == BlockX and PlayerZ == BlockZ then collision = true end end
|
|
|
|
if Block.m_Direction == 1 then if PlayerY == BlockY+1 and PlayerX == BlockX and PlayerZ == BlockZ then collision = true end end
|
2012-01-26 18:10:49 -05:00
|
|
|
|
2012-02-15 08:16:42 -05:00
|
|
|
if Block.m_Direction == 2 then if PlayerY == BlockY and PlayerX == BlockX and PlayerZ == BlockZ-1 then collision = true end end
|
|
|
|
if Block.m_Direction == 2 then if PlayerY+1 == BlockY and PlayerX == BlockX and PlayerZ == BlockZ-1 then collision = true end end
|
|
|
|
|
|
|
|
if Block.m_Direction == 3 then if PlayerY == BlockY and PlayerX == BlockX and PlayerZ == BlockZ+1 then collision = true end end
|
|
|
|
if Block.m_Direction == 3 then if PlayerY+1 == BlockY and PlayerX == BlockX and PlayerZ == BlockZ+1 then collision = true end end
|
|
|
|
|
|
|
|
if Block.m_Direction == 4 then if PlayerY == BlockY and PlayerX == BlockX-1 and PlayerZ == BlockZ then collision = true end end
|
|
|
|
if Block.m_Direction == 4 then if PlayerY+1 == BlockY and PlayerX == BlockX-1 and PlayerZ == BlockZ then collision = true end end
|
|
|
|
|
|
|
|
if Block.m_Direction == 5 then if PlayerY == BlockY and PlayerX == BlockX+1 and PlayerZ == BlockZ then collision = true end end
|
|
|
|
if Block.m_Direction == 5 then if PlayerY+1 == BlockY and PlayerX == BlockX+1 and PlayerZ == BlockZ then collision = true end end
|
|
|
|
|
|
|
|
return collision
|
|
|
|
end
|
|
|
|
|
2012-02-14 14:14:23 -05:00
|
|
|
if( Player:GetWorld():ForEachPlayer( CheckCollision ) == false ) then
|
|
|
|
return true
|
|
|
|
else
|
|
|
|
return false
|
|
|
|
end
|
2012-01-26 18:10:49 -05:00
|
|
|
|
2012-02-14 14:14:23 -05:00
|
|
|
end
|
2012-01-26 18:10:49 -05:00
|
|
|
|
2012-02-14 14:14:23 -05:00
|
|
|
return false
|
2012-01-26 18:10:49 -05:00
|
|
|
|
|
|
|
end
|