Need Help- Trying to Fix Dimensions for gmod 13

This addon/mod was made by Overv (as far as I know since that’s what it says on the beta page) at some point that I’m assuming was a long time ago. I found it in the Garrysmod beta only mostly fixed and I wanted to integrate it into a gamemode I’m working on (derived from sandbox, so I have no problem using it in addon form).

The Dimensions addon is designed to separate gameplay into distinct “dimensions” or “rooms” where you can only see and interact with props, npcs, other players, etc in the same dimension as you.

The main problem I’m having is that ropes and tracer fire are still visible when you’re in another dimension. The code is otherwise working and I haven’t had to add anything to it except minor bug fixing. I’m just going to post the actual area of code I’m having trouble with because everything else is working fine. I’m not getting any error messages, it just isn’t working as intended.

Original Code (for reference):
cl_dimensionscore.lua:
[lua]function Dimensions:SetEntityVisiblity( ent, dimension )
if ( ent:EntIndex() < 0 or !ent:IsValid() ) then return end

local visible = false

if ( ent:GetOwner():IsValid() ) then
	visible = ent:GetOwner():GetDimension() == dimension
elseif ( ent:GetClass() == "class C_RopeKeyframe" ) then
	visible = ent:GetNWEntity( "CEnt", ent ):GetDimension() == dimension
else
	visible = ent:GetDimension() == dimension
end

if ( ent:GetClass() == "class C_RopeKeyframe" ) then
	if ( visible ) then
		ent:SetColor(Color(255, 255, 255, 255))
	else
		ent:SetColor(Color(255, 255, 255, 0))
	end
else
	ent:SetNoDraw( !visible )
	
	if ( visible and !ent.DimensionVisibility ) then
		ent:CreateShadow()
	end
end

ent.DimensionVisibility = visible

end

function Dimensions.RenderEntities()
local localDimension = LocalPlayer():GetViewDimension()

for _, ent in ipairs( ents.GetAll() ) do
	Dimensions:SetEntityVisiblity( ent, localDimension )
	
	if ( ent.Dimension and ent.Dimension != ent:GetDimension() and ( ent.Dimension != localDimension and ent:GetDimension() == localDimension ) or ( ent.Dimension == localDimension and ent:GetDimension() != localDimension ) and !ent:GetOwner():IsValid() ) then
		local ed = EffectData()
		
		ed:SetEntity( ent )
		util.Effect( "entity_remove", ed, true, true )	
	end
	
	ent.Dimension = ent:GetDimension()
end

end
hook.Add( “RenderScene”, “DimensionsEntityDrawing”, Dimensions.RenderEntities )[/lua]

My Version. trying to fix the error (doesn’t seem to make any difference) I commented out a section that was another attempt (it still didn’t work):
cl_dimensionscore.lua:
[lua]function Dimensions:SetEntityVisiblity( ent, dimension )
if ( ent:EntIndex() < 0 or !ent:IsValid() ) then return end

local visible = false
local localDimension = LocalPlayer():GetViewDimension()

--if ( ent:GetOwner():IsValid() ) then
--	visible = ent:GetOwner():GetDimension() == dimension
--elseif ( ent:GetClass() == "C_RopeKeyframe" ) then
--	if ent:GetNWEntity( "CEnt", ent ):GetDimension() == localDimension then
--	visible = true
--	else
--	visible = false 
--	end
--	print(visible)
--	print(ent:GetNWEntity( "CEnt", ent ):GetDimension())
--else
--	visible = ent:GetDimension() == dimension
--end

if ( ent:GetOwner():IsValid() ) then
	if ent:GetOwner() == LocalPlayer() then
		if ent:GetDimension() == localDimension then
			visible = true
		end
	end	
elseif ( ent:GetClass() == "class C_RopeKeyframe" ) then
	if ent:GetNWEntity( "CEnt", ent ):GetDimension() == localDimension then
	visible = true
	print(visible)
	end
else
	if ent:GetDimension() == localDimension then
	visible = true
	else
	visible = false
	end
end

if ( ent:GetClass() == "C_RopeKeyframe" ) then
	if ( visible ) then
		ent:SetColor(255, 255, 255, 255)
	else
		ent:SetColor(255,255,255,0)
		ent:SetRenderMode(RENDERMODE_TRANSALPHA)
	end
else
	ent:SetNoDraw( !visible )
	
	if ( visible and !ent.DimensionVisibility ) then
		ent:CreateShadow()
	end
end

ent.DimensionVisibility = visible
end

function Dimensions.RenderEntities()
local localDimension = LocalPlayer():GetViewDimension()

for _, ent in ipairs( ents.GetAll() ) do
	Dimensions:SetEntityVisiblity( ent, localDimension )
	
	if ( ent.Dimension and ent.Dimension != ent:GetDimension() and ( ent.Dimension != localDimension and ent:GetDimension() == localDimension ) or ( ent.Dimension == localDimension and ent:GetDimension() != localDimension ) and !ent:GetOwner():IsValid() ) then
		local ed = EffectData()
		
		ed:SetEntity( ent )
		util.Effect( "entity_remove", ed, true, true )	
	end
	
	ent.Dimension = ent:GetDimension()
end

end
hook.Add( “RenderScene”, “DimensionsEntityDrawing”, Dimensions.RenderEntities )[/lua]

If there isn’t anything obvious there then here’s the full code. This includes the serverside stuff for the Networked Entity, which I checked and seems to be working.
original code (I just added “_R = debug.getregistry()”):
cl_dimensionscore.lua
[lua]–[[------------------------------------------------------------------------------------------------------------------
Clientside dimensions core
------------------------------------------------------------------------------------------------------------------]]–

Dimensions = {}
–for debugging purposes -Zyler
_R = debug.getregistry()
–[[------------------------------------------------------------------------------------------------------------------
Get dimension function
------------------------------------------------------------------------------------------------------------------]]–

function _R.Entity:GetDimension()
if ( !self:IsValid() ) then return 1 end

local val = self:GetDTInt( 3 )

if ( val == 0 and self != LocalPlayer() ) then val = LocalPlayer():GetDimension() end

return val

end

function _R.Entity:GetViewDimension()
local val = self:GetDTInt( 2 )

if ( val == 0 ) then val = LocalPlayer():GetDimension() end

return val

end

–[[------------------------------------------------------------------------------------------------------------------
Collision prediction
------------------------------------------------------------------------------------------------------------------]]–

function Dimensions.ShouldCollide( ent1, ent2 )
if ( ent1:GetDimension() != ent2:GetDimension() && !ent1:IsWorld() && !ent2:IsWorld() ) then
return false
end
end
hook.Add( “ShouldCollide”, “DimensionsCollisionHandling”, Dimensions.ShouldCollide )

–[[------------------------------------------------------------------------------------------------------------------
Trace modification
------------------------------------------------------------------------------------------------------------------]]–

Dimensions.OriginalTraceLine = util.TraceLine
function util.TraceLine( td, dimension )
if ( !dimension ) then dimension = LocalPlayer():GetDimension() end

local originalResult = Dimensions.OriginalTraceLine( td )

if ( !originalResult.Entity:IsValid() or originalResult.Entity:GetDimension() == dimension ) then
	return originalResult
else
	if ( td.filter ) then
		if ( type( td.filter ) == "table" ) then
			table.insert( td.filter, originalResult.Entity )
		else
			td.filter = { td.filter, originalResult.Entity }
		end
	else
		td.filter = originalResult.Entity
	end
	
	return util.TraceLine( td )
end

end

Dimensions.OriginalPlayerTrace = util.GetPlayerTrace
function util.GetPlayerTrace( ply, dir )
local originalResult = Dimensions.OriginalPlayerTrace( ply, dir )
originalResult.filter = { ply }

for _, ent in ipairs( ents.GetAll() ) do
	if ( ent:GetDimension() != ply:GetDimension() ) then
		table.insert( originalResult.filter, ent )
	end
end

return originalResult

end

–[[------------------------------------------------------------------------------------------------------------------
Rendering
------------------------------------------------------------------------------------------------------------------]]–

function Dimensions:SetEntityVisiblity( ent, dimension )
if ( ent:EntIndex() < 0 or !ent:IsValid() ) then return end

local visible = false

if ( ent:GetOwner():IsValid() ) then
	visible = ent:GetOwner():GetDimension() == dimension
elseif ( ent:GetClass() == "class C_RopeKeyframe" ) then
	visible = ent:GetNWEntity( "CEnt", ent ):GetDimension() == dimension
else
	visible = ent:GetDimension() == dimension
end

if ( ent:GetClass() == "class C_RopeKeyframe" ) then
	if ( visible ) then
		ent:SetColor(Color(255, 255, 255, 255))
	else
		ent:SetColor(Color(255, 255, 255, 0))
	end
else
	ent:SetNoDraw( !visible )
	
	if ( visible and !ent.DimensionVisibility ) then
		ent:CreateShadow()
	end
end

ent.DimensionVisibility = visible

end

function Dimensions.RenderEntities()
local localDimension = LocalPlayer():GetViewDimension()

for _, ent in ipairs( ents.GetAll() ) do
	Dimensions:SetEntityVisiblity( ent, localDimension )
	
	if ( ent.Dimension and ent.Dimension != ent:GetDimension() and ( ent.Dimension != localDimension and ent:GetDimension() == localDimension ) or ( ent.Dimension == localDimension and ent:GetDimension() != localDimension ) and !ent:GetOwner():IsValid() ) then
		local ed = EffectData()
		
		ed:SetEntity( ent )
		util.Effect( "entity_remove", ed, true, true )	
	end
	
	ent.Dimension = ent:GetDimension()
end

end
hook.Add( “RenderScene”, “DimensionsEntityDrawing”, Dimensions.RenderEntities )

// <3 PinkFoxi[/lua]

sv_dimensionscore.lua:
[lua]–[[------------------------------------------------------------------------------------------------------------------
Serverside layers core
------------------------------------------------------------------------------------------------------------------]]–
–for debugging purposes -Zyler
_R = debug.getregistry()

AddCSLuaFile( “autorun/vgui/layerlist.lua” )
AddCSLuaFile( “autorun/vgui/layerlist_layer.lua” )
AddCSLuaFile( “autorun/client/cl_layerscore.lua” )

Dimensions = {}

–[[------------------------------------------------------------------------------------------------------------------
Dimension management
------------------------------------------------------------------------------------------------------------------]]–

Dimensions.Dimensions = {
{ Owner = NULL, Title = “Default” },
}

function Dimensions:CreateDimension( ply, title )
if ( !ply.OwnedDimension ) then
local id = table.insert( Dimensions.Dimensions, { Owner = ply, Title = title } )

	umsg.Start( "dimension_created" )
		umsg.Short( id )
		umsg.String( title )
		umsg.Entity( ply )
	umsg.End()
	
	ply.OwnedDimension = id
end

end

function Dimensions:DestroyDimension( ply )
if ( ply.OwnedDimension ) then
umsg.Start( “dimension_destroyed” )
umsg.Short( ply.OwnedDimension )
umsg.End()

	for _, ent in ipairs( ents.GetAll() ) do
		if ( ent:GetDimension() == ply.OwnedDimension ) then
			if ( !ent:IsPlayer() and !ent:GetOwner():IsValid() ) then
				ent:Remove()
			else
				ent:SetDimension( 1 )
			end
		end
	end
	
	Dimensions.Dimensions[ ply.OwnedDimension ] = nil
	ply.OwnedDimension = nil
end

end

timer.Create( “CleanupDimensions”, 1, 0, function()
for i = 2, #Dimensions.Dimensions do
if ( !Dimensions.Dimensions*.Owner:IsValid() ) then
table.remove( Dimensions.Dimensions, i )
end
end
end )

concommand.Add( “dimensions_create”, function( ply )
if ( ply:IsValid() ) then
Dimensions:CreateDimension( ply, ply:Nick() … “'s dimension” )
end
end )

concommand.Add( “dimensions_destroy”, function( ply )
if ( ply:IsValid() ) then
Dimensions:DestroyDimension( ply )
end
end )

concommand.Add( “dimensions_select”, function( ply, com, args )
if ( ply:IsValid() and Dimensions.Dimensions[ tonumber( args[1] ) ] ) then
ply.SelectedDimension = tonumber( args[1] )
end
end )

concommand.Add( “dimensions_sync”, function( ply )
for id, dimension in ipairs( Dimensions.Dimensions ) do
umsg.Start( “dimension_created”, ply )
umsg.Short( id )
umsg.String( dimension.Title )
umsg.Entity( dimension.Owner )
umsg.End()
end
end )

–[[------------------------------------------------------------------------------------------------------------------
Basic set and get dimension functions
------------------------------------------------------------------------------------------------------------------]]–

function _R.Entity:SetDimension( dimension )
self:SetDTInt( 3, dimension )
if ( !self.UsingCamera ) then self:SetViewDimension( dimension ) end
end

function _R.Entity:SetViewDimension( dimension )
self:SetDTInt( 2, dimension )
end

function _R.Entity:GetDimension( default )
return self:GetDTInt( 3 )
end

–[[------------------------------------------------------------------------------------------------------------------
Collision handling
------------------------------------------------------------------------------------------------------------------]]–

function Dimensions:ShouldCollide( ent1, ent2 )
return ent1:GetDimension() == ent2:GetDimension() or ent1:IsWorld() or ent2:IsWorld()
end

function ShouldEntitiesCollide( ent1, ent2 )
if ent1 == ent2 then return false end
return Dimensions:ShouldCollide( ent1, ent2 )
end

hook.Add( “ShouldCollide”, “DimensionsCollisionHandling”, ShouldEntitiesCollide )

–[[------------------------------------------------------------------------------------------------------------------
Trace modification
------------------------------------------------------------------------------------------------------------------]]–

Dimensions.OriginalPlayerTrace = util.GetPlayerTrace
function util.GetPlayerTrace( ply, dir )
local originalResult = Dimensions.OriginalPlayerTrace( ply, dir )
originalResult.filter = { ply }

for _, ent in ipairs( ents.GetAll() ) do
	if ( ent:GetDimension() != ply:GetDimension() ) then
		table.insert( originalResult.filter, ent )
	end
end

return originalResult

end

–[[------------------------------------------------------------------------------------------------------------------
Gravity gun handling
------------------------------------------------------------------------------------------------------------------]]–

function Dimensions.GravGunPickup( ply, ent )
if ( ply:GetDimension() != ent:GetDimension() ) then return false end
end
hook.Add( “GravGunOnPickedUp”, “DimensionsGravGunPickup”, Dimensions.GravGunPickup )

–[[------------------------------------------------------------------------------------------------------------------
Constraint handling
------------------------------------------------------------------------------------------------------------------]]–

Dimensions.OldKeyframeRope = constraint.CreateKeyframeRope
function constraint.CreateKeyframeRope( pos, width, material, constr, ent1, lpos1, bone1, ent2, lpos2, bone2, kv )
local rope = Dimensions.OldKeyframeRope( pos, width, material, constr, ent1, lpos1, bone1, ent2, lpos2, bone2, kv )

if ( rope ) then
	if ( ent1:IsWorld() and !ent2:IsWorld() ) then
		rope:SetNWEntity( "CEnt", ent2 )
	elseif ( !ent1:IsWorld() and ent2:IsWorld() ) then
		rope:SetNWEntity( "CEnt", ent1 )
	else
		// For a pulley, the two specified entities are both the world for the middle rope, so we just remember the entity from the first rope
		rope:SetNWEntity( "CEnt", Dimensions.KeyframeEntityCache )
	end
end

Dimensions.KeyframeEntityCache = ent1

return rope

end

–[[------------------------------------------------------------------------------------------------------------------
Camera handling
------------------------------------------------------------------------------------------------------------------]]–

Dimensions.OldSetViewEntity = _R.Player.SetViewEntity
function _R.Player:SetViewEntity( ent )
self:SetViewDimension( ent:GetDimension() )
return Dimensions.OldSetViewEntity( self, ent )
end

–[[------------------------------------------------------------------------------------------------------------------
Set the dimension of spawned entities
------------------------------------------------------------------------------------------------------------------]]–

function Dimensions.EntitySpawnDimension( ply, ent )
ent:SetDimension( ply:GetDimension() )
end

function Dimensions.EntitySpawnDimensionProxy( ply, mdl, ent )
Dimensions.EntitySpawnDimension( ply, ent )
end

Dimensions.OriginalAddCount = _R.Player.AddCount
function _R.Player:AddCount( type, ent )
ent:SetDimension( self:GetDimension() )
return Dimensions.OriginalAddCount( self, type, ent )
end

Dimensions.OriginalCleanup = cleanup.Add
function cleanup.Add( ply, type, ent )
if ( ent ) then ent:SetDimension( ply:GetDimension() ) end
return Dimensions.OriginalCleanup( ply, type, ent )
end

function Dimensions.InitializePlayerDimension( ply )
ply:SetDimension( 1 )
end

hook.Add( “PlayerSpawnedSENT”, “DimensionEntityInitialization”, Dimensions.EntitySpawnDimension )
hook.Add( “PlayerSpawnedNPC”, “DimensionEntityInitialization”, Dimensions.EntitySpawnDimension )
hook.Add( “PlayerSpawnedVehicle”, “DimensionEntityInitialization”, Dimensions.EntitySpawnDimension )
hook.Add( “PlayerSpawnedProp”, “DimensionEntityInitialization”, Dimensions.EntitySpawnDimensionProxy )
hook.Add( “PlayerSpawnedEffect”, “DimensionEntityInitialization”, Dimensions.EntitySpawnDimensionProxy )
hook.Add( “PlayerSpawnedRagdoll”, “DimensionEntityInitialization”, Dimensions.EntitySpawnDimensionProxy )
hook.Add( “PlayerInitialSpawn”, “DimensionPlayerInitialization”, Dimensions.InitializePlayerDimension )[/lua]

My Version:
cl_dimensionscore.lua:
[lua]–[[------------------------------------------------------------------------------------------------------------------
Clientside dimensions core
------------------------------------------------------------------------------------------------------------------]]–

Dimensions = {}
–for debugging purposes -Zyler
_R = debug.getregistry()
–[[------------------------------------------------------------------------------------------------------------------
Get dimension function
------------------------------------------------------------------------------------------------------------------]]–

function _R.Entity:GetDimension()
if ( !self:IsValid() ) then return 1 end

local val = self:GetDTInt( 3 )

if ( val == 0 and self != LocalPlayer() ) then val = LocalPlayer():GetDimension() end

return val

end

function _R.Entity:GetViewDimension()
local val = self:GetDTInt( 2 )

if ( val == 0 ) then val = LocalPlayer():GetDimension() end

return val

end

–[[------------------------------------------------------------------------------------------------------------------
Collision prediction
------------------------------------------------------------------------------------------------------------------]]–

function Dimensions.ShouldCollide( ent1, ent2 )
if ( ent1:GetDimension() != ent2:GetDimension() && !ent1:IsWorld() && !ent2:IsWorld() ) then
return false
end
end
hook.Add( “ShouldCollide”, “DimensionsCollisionHandling”, Dimensions.ShouldCollide )

–[[------------------------------------------------------------------------------------------------------------------
Trace modification
------------------------------------------------------------------------------------------------------------------]]–

Dimensions.OriginalTraceLine = util.TraceLine
function util.TraceLine( td, dimension )
if ( !dimension ) then dimension = LocalPlayer():GetDimension() end

local originalResult = Dimensions.OriginalTraceLine( td )

if ( !originalResult.Entity:IsValid() or originalResult.Entity:GetDimension() == dimension ) then
	return originalResult
else
	if ( td.filter ) then
		if ( type( td.filter ) == "table" ) then
			table.insert( td.filter, originalResult.Entity )
		else
			td.filter = { td.filter, originalResult.Entity }
		end
	else
		td.filter = originalResult.Entity
	end
	
	return util.TraceLine( td )
end

end

Dimensions.OriginalPlayerTrace = util.GetPlayerTrace
function util.GetPlayerTrace( ply, dir )
local originalResult = Dimensions.OriginalPlayerTrace( ply, dir )
originalResult.filter = { ply }

for _, ent in ipairs( ents.GetAll() ) do
	if ( ent:GetDimension() != ply:GetDimension() ) then
		table.insert( originalResult.filter, ent )
	end
end

return originalResult

end

–[[------------------------------------------------------------------------------------------------------------------
Rendering
------------------------------------------------------------------------------------------------------------------]]–

function Dimensions:SetEntityVisiblity( ent, dimension )
if ( ent:EntIndex() < 0 or !ent:IsValid() ) then return end

local visible = false
local localDimension = LocalPlayer():GetViewDimension()

--if ( ent:GetOwner():IsValid() ) then
--	visible = ent:GetOwner():GetDimension() == dimension
--elseif ( ent:GetClass() == "C_RopeKeyframe" ) then
--	if ent:GetNWEntity( "CEnt", ent ):GetDimension() == localDimension then
--	visible = true
--	else
--	visible = false 
--	end
--	print(visible)
--	print(ent:GetNWEntity( "CEnt", ent ):GetDimension())
--else
--	visible = ent:GetDimension() == dimension
--end

if ( ent:GetOwner():IsValid() ) then
	if ent:GetOwner() == LocalPlayer() then
		if ent:GetDimension() == localDimension then
			visible = true
		end
	end	
elseif ( ent:GetClass() == "class C_RopeKeyframe" ) then
	if ent:GetNWEntity( "CEnt", ent ):GetDimension() == localDimension then
	visible = true
	print(visible)
	end
else
	if ent:GetDimension() == localDimension then
	visible = true
	else
	visible = false
	end
end

if ( ent:GetClass() == "C_RopeKeyframe" ) then
	if ( visible ) then
		ent:SetColor(255, 255, 255, 255)
	else
		ent:SetColor(255,255,255,0)
		ent:SetRenderMode(RENDERMODE_TRANSALPHA)
	end
else
	ent:SetNoDraw( !visible )
	
	if ( visible and !ent.DimensionVisibility ) then
		ent:CreateShadow()
	end
end

ent.DimensionVisibility = visible
end

function Dimensions.RenderEntities()
local localDimension = LocalPlayer():GetViewDimension()

for _, ent in ipairs( ents.GetAll() ) do
	Dimensions:SetEntityVisiblity( ent, localDimension )
	
	if ( ent.Dimension and ent.Dimension != ent:GetDimension() and ( ent.Dimension != localDimension and ent:GetDimension() == localDimension ) or ( ent.Dimension == localDimension and ent:GetDimension() != localDimension ) and !ent:GetOwner():IsValid() ) then
		local ed = EffectData()
		
		ed:SetEntity( ent )
		util.Effect( "entity_remove", ed, true, true )	
	end
	
	ent.Dimension = ent:GetDimension()
end

end
hook.Add( “RenderScene”, “DimensionsEntityDrawing”, Dimensions.RenderEntities )

// <3 PinkFoxi
[/lua]

sv_dimensionscore.lua:
[lua]–[[------------------------------------------------------------------------------------------------------------------
Serverside layers core
------------------------------------------------------------------------------------------------------------------]]–
–for debugging purposes -Zyler
_R = debug.getregistry()

–AddCSLuaFile( “autorun/vgui/layerlist.lua” )
–AddCSLuaFile( “autorun/vgui/layerlist_layer.lua” )
–AddCSLuaFile( “autorun/client/cl_layerscore.lua” )

Dimensions = {}

–[[------------------------------------------------------------------------------------------------------------------
Dimension management
------------------------------------------------------------------------------------------------------------------]]–

Dimensions.Dimensions = {
{ Owner = NULL, Title = “Default” },
}

function Dimensions:CreateDimension( ply, title )
if ( !ply.OwnedDimension ) then
local id = table.insert( Dimensions.Dimensions, { Owner = ply, Title = title } )

	umsg.Start( "dimension_created" )
		umsg.Short( id )
		umsg.String( title )
		umsg.Entity( ply )
	umsg.End()
	
	ply.OwnedDimension = id
end

end

function Dimensions:DestroyDimension( ply )
if ( ply.OwnedDimension ) then
umsg.Start( “dimension_destroyed” )
umsg.Short( ply.OwnedDimension )
umsg.End()

	for _, ent in ipairs( ents.GetAll() ) do
		if ( ent:GetDimension() == ply.OwnedDimension ) then
			if ( !ent:IsPlayer() and !ent:GetOwner():IsValid() ) then
				ent:Remove()
			else
				ent:SetDimension( 1 )
			end
		end
	end
	
	Dimensions.Dimensions[ ply.OwnedDimension ] = nil
	ply.OwnedDimension = nil
end

end

timer.Create( “CleanupDimensions”, 1, 0, function()
for i = 2, #Dimensions.Dimensions do
if ( !Dimensions.Dimensions*.Owner:IsValid() ) then
table.remove( Dimensions.Dimensions, i )
end
end
end )

concommand.Add( “dimensions_create”, function( ply )
if ( ply:IsValid() ) then
Dimensions:CreateDimension( ply, ply:Nick() … “'s dimension” )
end
end )

concommand.Add( “dimensions_destroy”, function( ply )
if ( ply:IsValid() ) then
Dimensions:DestroyDimension( ply )
end
end )

concommand.Add( “dimensions_select”, function( ply, com, args )
if ( ply:IsValid() and Dimensions.Dimensions[ tonumber( args[1] ) ] ) then
ply.SelectedDimension = tonumber( args[1] )
end
end )

concommand.Add( “dimensions_sync”, function( ply )
for id, dimension in ipairs( Dimensions.Dimensions ) do
umsg.Start( “dimension_created”, ply )
umsg.Short( id )
umsg.String( dimension.Title )
umsg.Entity( dimension.Owner )
umsg.End()
end
end )

–[[------------------------------------------------------------------------------------------------------------------
Basic set and get dimension functions
------------------------------------------------------------------------------------------------------------------]]–

function _R.Entity:SetDimension( dimension )
self:SetDTInt( 3, dimension )
if ( !self.UsingCamera ) then self:SetViewDimension( dimension ) end
end

function _R.Entity:SetViewDimension( dimension )
self:SetDTInt( 2, dimension )
end

function _R.Entity:GetDimension( default )
return self:GetDTInt( 3 )
end

–[[------------------------------------------------------------------------------------------------------------------
Collision handling
------------------------------------------------------------------------------------------------------------------]]–

function Dimensions:ShouldCollide( ent1, ent2 )
return ent1:GetDimension() == ent2:GetDimension() or ent1:IsWorld() or ent2:IsWorld()
end

function ShouldEntitiesCollide( ent1, ent2 )
if ent1 == ent2 then return false end
return Dimensions:ShouldCollide( ent1, ent2 )
end

hook.Add( “ShouldCollide”, “DimensionsCollisionHandling”, ShouldEntitiesCollide )

–[[------------------------------------------------------------------------------------------------------------------
Trace modification
------------------------------------------------------------------------------------------------------------------]]–

Dimensions.OriginalPlayerTrace = util.GetPlayerTrace
function util.GetPlayerTrace( ply, dir )
local originalResult = Dimensions.OriginalPlayerTrace( ply, dir )
originalResult.filter = { ply }

for _, ent in ipairs( ents.GetAll() ) do
	if ( ent:GetDimension() != ply:GetDimension() ) then
		table.insert( originalResult.filter, ent )
	end
end

return originalResult

end

–[[------------------------------------------------------------------------------------------------------------------
Gravity gun handling
------------------------------------------------------------------------------------------------------------------]]–

function Dimensions.GravGunPickup( ply, ent )
if ( ply:GetDimension() != ent:GetDimension() ) then return false end
end
hook.Add( “GravGunOnPickedUp”, “DimensionsGravGunPickup”, Dimensions.GravGunPickup )

–[[------------------------------------------------------------------------------------------------------------------
Constraint handling
------------------------------------------------------------------------------------------------------------------]]–

Dimensions.OldKeyframeRope = constraint.CreateKeyframeRope
function constraint.CreateKeyframeRope( pos, width, material, constr, ent1, lpos1, bone1, ent2, lpos2, bone2, kv )
local rope = Dimensions.OldKeyframeRope( pos, width, material, constr, ent1, lpos1, bone1, ent2, lpos2, bone2, kv )

if ( rope ) then
	if ( ent1:IsWorld() and !ent2:IsWorld() ) then
		rope:SetNWEntity( "CEnt", ent2 )
	elseif ( !ent1:IsWorld() and ent2:IsWorld() ) then
		rope:SetNWEntity( "CEnt", ent1 )
	else
		// For a pulley, the two specified entities are both the world for the middle rope, so we just remember the entity from the first rope
		rope:SetNWEntity( "CEnt", Dimensions.KeyframeEntityCache )
	end
end

Dimensions.KeyframeEntityCache = ent1

return rope

end

–[[------------------------------------------------------------------------------------------------------------------
Camera handling
------------------------------------------------------------------------------------------------------------------]]–

Dimensions.OldSetViewEntity = _R.Player.SetViewEntity
function _R.Player:SetViewEntity( ent )
self:SetViewDimension( ent:GetDimension() )
return Dimensions.OldSetViewEntity( self, ent )
end

–[[------------------------------------------------------------------------------------------------------------------
Set the dimension of spawned entities
------------------------------------------------------------------------------------------------------------------]]–

function Dimensions.EntitySpawnDimension( ply, ent )
ent:SetDimension( ply:GetDimension() )
ent:SetCustomCollisionCheck(true)
end

function Dimensions.EntitySpawnDimensionProxy( ply, mdl, ent )
Dimensions.EntitySpawnDimension( ply, ent )
end

Dimensions.OriginalAddCount = _R.Player.AddCount
function _R.Player:AddCount( type, ent )
ent:SetDimension( self:GetDimension() )
return Dimensions.OriginalAddCount( self, type, ent )
end

Dimensions.OriginalCleanup = cleanup.Add
function cleanup.Add( ply, type, ent )
if ( ent ) then ent:SetDimension( ply:GetDimension() ) end
return Dimensions.OriginalCleanup( ply, type, ent )
end

function Dimensions.InitializePlayerDimension( ply )
ply:SetDimension( 1 )
ply:SetCustomCollisionCheck(true)
end

hook.Add( “PlayerSpawnedSENT”, “DimensionEntityInitialization”, Dimensions.EntitySpawnDimension )
hook.Add( “PlayerSpawnedNPC”, “DimensionEntityInitialization”, Dimensions.EntitySpawnDimension )
hook.Add( “PlayerSpawnedVehicle”, “DimensionEntityInitialization”, Dimensions.EntitySpawnDimension )
hook.Add( “PlayerSpawnedProp”, “DimensionEntityInitialization”, Dimensions.EntitySpawnDimensionProxy )
hook.Add( “PlayerSpawnedEffect”, “DimensionEntityInitialization”, Dimensions.EntitySpawnDimensionProxy )
hook.Add( “PlayerSpawnedRagdoll”, “DimensionEntityInitialization”, Dimensions.EntitySpawnDimensionProxy )
hook.Add( “PlayerInitialSpawn”, “DimensionPlayerInitialization”, Dimensions.InitializePlayerDimension )[/lua]

Thanks for the help if you can help me.

Edit: I don’t know why the code is commented out in my post. It isn’t like that in notepad++.

BUMP

Again, Still having problems with this