Server fog

Hello,

I’ve been looking around some places for a fog mod or ways to enable fog for my server.
Is there any fog mod addon created by anyone? I couldn’t find one on garrysmod.org or is there a way to enable fog using server rcon commands?

Please help!
Thanks!

I’ve seen this asked before, and it is relatively simple to do from within a map. (i.e. made in Valve’s hammer editor) However, i’m not sure about creating/modifying fog effects from Gmod Lua. There are some basic controls built into The Garry’s Mod ‘Q’ Menu that allow you to control Serverside fog on a map:

http://wiki.garrysmod.com/?title=Options_Menu#Fog

I have some free time, so i’ll do a bit of research into Lua-controlled fog if it is actually possible.

[editline]Edit:[/editline]
Had a conversation with my brother, (simonjb) he is a mapper. He explained to me exactly how env_fog_controller works. If this entity could be created and managed through Gmod Lua then this could be possible. I’m gonna try it in gmod now, my concern is that the entity might need to be present when the server starts.

[editline]Edit Again:[/editline]
Right after playing around a bit, i found you can get hold of an existing env_fog_controller or create a new one if one hasn’t been included on the map. This however would be complicated and you can easily use the controls that garry has included in the options tab of the ‘Q’ menu. You can also control this using console commands. (fog_<param>) I believe it may be a clientside thing, but you can use a Lua script to force all players to configure their fog to the same settings if this is true.

Screenshot:

Hope this helps.

Considering he said “For my server” you would need to pure lua the fog, Since the fog controller in garrysmod Q Menu does nothing in Multiplayer.

It wont do anything cause you are simply running it clientside. If you got the server to run the console commands could this work?

Good luck finding the fog functions. I would check Overv’s Lua Bin.


--[[
	Wrap the fog entity
]]

Fog = { }
Fog._ent = NULL

function Fog:FindFogEntity( bDontCreate )
	local k, v
	
	for k, v in ipairs( ents.GetAll( ) ) do
		if v:GetClass( ) == "env_fog_controller" then
			self._ent = v
			break
		end
	end
	
	if not bDontCreate and not self._ent:IsValid( ) then
		v = ents.Create( "env_fog_controller" )
		v:Spawn( )
		self._ent = v
	end
end

function Fog:IsValid( )
	return self._ent:IsValid( )
end
function Fog:SetStartDistance( fStartDistance )	
	return self:IsValid( ) and self._ent:Input( "SetStartDist", self, self, fStartDistance )
end
function Fog:SetEndDistance( fEndDistance )	
	return self:IsValid( ) and self._ent:Input( "SetEndDist", self, self, fEndDistance )
end
function Fog:TurnOn( )	
	return self:IsValid( ) and self._ent:Input( "TurnOn", self, self )
end
function Fog:TurnOff( )	
	return self:IsValid( ) and self._ent:Input( "TurnOff", self, self )
end
function Fog:SetPrimaryColor( color )
	return self:IsValid( ) and self._ent:Input( "SetColor", self, self, string.format( "%d %d %d", color.r, color.g, color.b ) )
end
function Fog:SetSecondaryColor( color )
	return self:IsValid( ) and self._ent:Input( "SetColorSecondary", self, self, string.format( "%d %d %d", color.r, color.g, color.b ) )
end
function Fog:SetColorPrimaryLerpTo( color )
	return self:IsValid( ) and self._ent:Input( "SetColorLerpTo", self, self, string.format( "%d %d %d", color.r, color.g, color.b ) )
end
function Fog:SetColorSecondaryLerpTo( color )
	return self:IsValid( ) and self._ent:Input( "SetColorSecondaryLerpTo", self, self, string.format( "%d %d %d", color.r, color.g, color.b ) )
end
function Fog:SetStartDistLerpTo( fStartDistance )	
	return self:IsValid( ) and self._ent:Input( "SetStartDistLerpTo", self, self, fStartDistance )
end
function Fog:SetEndDistLerpTo( fStartDistance )	
	return self:IsValid( ) and self._ent:Input( "SetEndDistLerpTo", self, self, fStartDistance )
end
function Fog:StartFogTransition( )
	return self:IsValid( ) and self._ent:Input( "StartFogTransition",  self, self )
end
function Fog:SetFarZ( iFarZ )
	return self:IsValid( ) and self._ent:Input( "SetFarZ", self, self, iFarZ )
end
function Fog:SetAngles( ang )
	return self:IsValid( ) and self._ent:Input( "SetAngles", self, self, tostring( ang ) )
end
function Fog:SetDensity( fDensity )
	return self:IsValid( ) and self._ent:SetKeyValue( "FogMaxDensity", fDensity )
end
function Fog:SetBlend( bBlend )
	return self:IsValid( ) and self._ent:SetKeyValue( "FogBlend", bBlend and 1 or 0 )
end
function Fog:SetLerpTime( fDelay )
	return self:IsValid( ) and self._ent:SetKeyValue( "foglerptime", fDelay )
end

Goes in autorun/server

Usage:



Fog:FindFogEntity( )
Fog:SetLerpTime( 8 )
Fog:SetDensity( .7 )
Fog:SetStartDistance( 32 )
Fog:SendEndDistance( 768 )
Fog:SetEndDistLerpTo( 128 )
Fog:StartFogTransition( )


It mostly works but some settings seem to require having TurnOn or StartFogTransition called to apply.



"fog_override"
"fog_start"
"fog_startskybox"
"fog_end"
"fog_endskybox"
"fog_color_r"
"fog_color_g"
"fog_color_b"

All of them require cheats to be enabled.
If you want to use them without cheats enabled, you’ll have to use haza55’s cvar2 module to remove the FCVAR_CHEAT flag from the commands clientside (They don’t exist serverside).

[EDITLINE]-[/EDITLINE]
Use Kogitsune’s code, it’s a better solution.

Hey I am having some issues following this. Where do I place the commands
Fog:FindFogEntity( )
Fog:SetLerpTime( 8 )
Fog:SetDensity( .7 )
Fog:SetStartDistance( 32 )
Fog:SendEndDistance( 768 )
Fog:SetEndDistLerpTo( 128 )
Fog:StartFogTransition( )