change the skybox texture in lua?

is that possible?

Yes. Replace the Up/Down/Left/Right texture’s basetexture with what you want to replace it with.

how do i do that?

[lua]
local Suffixes = {"_rt", “_lf”, “_up”, “_ft”, “_dn”, “_bk”}
local Skybox = GetConVarString(“sv_skyname”)
local Replacement = “whateverskyboxyouwant”
for k,v in pairs(Suffixes) do
Material(Skybox…v):SetMaterialTexture("$basetexture", Material(Replacement…v))
end
[/lua]

Something like that.
I’m pretty sure it’s possible with like, half as many Material() calls.

attempt to concatenate local ‘Replacement’ (a userdata value)

Line 3 of portal gods code should be
[lua]
local Replacement = “whateverskyboxyouwant”
[/lua]

it still dont work


nvm

¨local SourceSkyname = GetConVar(“sv_skyname”):GetString() --We need the source of the maps original skybox texture so we can manipulate it.
local SourceSkyPre = {“lf”,“ft”,“rt”,“bk”,“dn”,“up”,}
local SourceSkyMat = {
Material(“skybox/”…SourceSkyname…“lf”),
Material(“skybox/”…SourceSkyname…“ft”),
Material(“skybox/”…SourceSkyname…“rt”),
Material(“skybox/”…SourceSkyname…“bk”),
Material(“skybox/”…SourceSkyname…“dn”),
Material(“skybox/”…SourceSkyname…“up”),
}

function ChangeSkybox(skyboxname)
for i = 1,6 do
local D = Material(“skybox/”…skyboxname…SourceSkyPre*):GetMaterialTexture("$basetexture")
SourceSkyMat*:SetMaterialTexture("$basetexture",D)
end
end

Theres all ready a thread on this exact issue.

[lua]local SourceSkyname = GetConVar(“sv_skyname”):GetString() --We need the source of the maps original skybox texture so we can manipulate it.
local SourceSkyPre = {“lf”,“ft”,“rt”,“bk”,“dn”,“up”,}
local SourceSkyMat = {
Material(“skybox/”…SourceSkyname…“lf”),
Material(“skybox/”…SourceSkyname…“ft”),
Material(“skybox/”…SourceSkyname…“rt”),
Material(“skybox/”…SourceSkyname…“bk”),
Material(“skybox/”…SourceSkyname…“dn”),
Material(“skybox/”…SourceSkyname…“up”),
}

function ChangeSkybox(skyboxname)
for i = 1,6 do
local D = Material(“skybox/”…skyboxname…SourceSkyPre*):GetMaterialTexture("$basetexture")
SourceSkyMat*:SetMaterialTexture("$basetexture",D)
end
end[/lua]

[editline]14th May 2011[/editline]

:ninja:ninja’d

What i do with there code,

lua/autorun/client/<name>.lua?

Sorry for the bump.

I’m still new to LUA. Been doing “Learn LUA The Hard Way” and I want to get tangible results in GMod.

I am trying to create a night / day system. I already have a timer that hooks the server start and plays a howl sound like in Zelda when it hits the target. Now I’m trying to switch the skybox with the same hook…

I’m using Science’s code, and I think I understand it, but I’m a little lost as to where I plug in the 2nd skybox for the switch.

Thx.

If you don’t need to do in on the fly ( Change it multiple times / after server starts ) you can just use RunConsoleCommand(“sv_skyname”,“painted”) SERVERSIDE.

My plan to do it at the end of a timer, without the server restarting. This is what my code looks like:



  -- \\ Global Timer = cycleTime -- 30 minutes per phase on default.
  
 cycleTime = 30
 
  -- \\ The timer is hooked to 'DarkRPDBInitialized' - the server must be restarted when adding this.
  -- The nightCycle function plays when the timer hits the target.
  -- It grabs the players current aim vector (3D) and plays 'seagull_idle1' on that position to indicate
  -- the beginning of the night cycle.
 
 function nightCycle -- plays a sound after 30 minutes to indicate night.
			Player:GetAimVector() = x
			sound.Play("sound\ambient\creatures\seagull_idle1", x, 80, 100, 1)
			-- replace this sound with wolf howling
			
			local SourceSkyname = GetConVar("sv_skyname"):GetString() --We need the source of the maps original skybox texture so we can manipulate it.
			local SourceSkyPre  = {"lf","ft","rt","bk","dn","up",}
			local SourceSkyMat  = {
				Material("skybox/"..SourceSkyname.."lf"),
				Material("skybox/"..SourceSkyname.."ft"),
				Material("skybox/"..SourceSkyname.."rt"),
				Material("skybox/"..SourceSkyname.."bk"),
				Material("skybox/"..SourceSkyname.."dn"),
				Material("skybox/"..SourceSkyname.."up"),
				}
 
			function ChangeSkybox(skyboxname)
				for i = 1,6 do
				local D = Material("skybox/"..skyboxname..SourceSkyPre*):GetMaterialTexture("skybox\sky_borealis")
				SourceSkyMat*:SetMaterialTexture("skybox\sky_borealis",D)
				end
			end
			
end
  
  hook.Add( DarkRPDBInitialized, world_timer, function() ) 
	function timer.Create("timeCycle_1", 60*cycleTime, 1, nightCycle)
end

I would strongly recommend using sv_skyname painted and env_skypaint entity to edit its colors for smooth transitions. Using the hack suggested before me just adds a ton of complexity. You’ll need to change the texture on every client ( its SetTexture, not SetMaterialTexture. ) Using my method you can do everything serverside.