Settings Skybox Texture

I grab the skyname with this:

[lua]
hook.Add(“EntityKeyValue”, “JSSkybox:KeyValue”,
function (ent,key,val)
if (ent:GetClass() == “worldspawn” && key == “skyname”) then
SetGlobalString(“JSSkybox:SkyName”, val)
end
end

)

[/lua]

So therefore the skybox textures are the following:
[lua]
local skyname = GetGlobalString(“JSSkybox:SkyName”)
JSSkybox.Materials[1] = Material(“skybox/” … skyname … “up”)
JSSkybox.Materials[2] = Material(“skybox/” … skyname … “dn”)
JSSkybox.Materials[3] = Material(“skybox/” … skyname … “lf”)
JSSkybox.Materials[4] = Material(“skybox/” … skyname … “rt”)
JSSkybox.Materials[5] = Material(“skybox/” … skyname … “bk”)
JSSkybox.Materials[6] = Material(“skybox/” … skyname … “ft”)
[/lua]

I then try to change them with:

[lua]
JSSkybox.Materials[1]:SetMaterialString( “$basetexture”, “skybox/” … customsky … “up” )
[/lua]

However I always get purple and black squares, even if I set it to the same skybox textures.

I used to be able to do it using this method, did I miss anything?

Setting the colour with this works however:
[lua]
JSSkybox.Materials[1]:SetMaterialVector("$color", Vector(CurrentSkyboxR, CurrentSkyboxG, CurrentSkyboxB))
[/lua]

Thanks!

EDIT:

Also, are the functions PostDrawSkybox and PreDrawSkybox broken?

EDIT:

It seems using:

[lua]
v:SetMaterialTexture("$basetexture",Material(“skybox/” … customsky … skybox_suffix[k]):GetMaterialTexture("$basetexture"))
[/lua]

Works instead.

http://img210.imageshack.us/img210/9200/rpdowntownv20009.jpg

Thanks! I’ve been having trouble finding a solution.

I’ve reported the malfunctioning hooks:
http://getsatisfaction.com/facepunch/topics/predrawskybox_and_postdrawskybox_are_never_called

Be sure to vote it up, if you want Garry to consider this feature. Facebook or Google accounts will work.

[editline]01:47PM[/editline]

Also, I’ve implemented your method in my gamemode and I thought I’d share the module:

Note that you can get the sky name from the sv_skyname cvar.

[lua]
local SkyBoxName = nil
local SkyBoxMaterials = {}
local SkyBoxSuffixes = { “up”, “dn”, “lf”, “rt”, “bk”, “ft” }

// Change the skybox texture
function GM:SetSkyBox( Name )
for Suffix, SkyMat in pairs( SkyBoxMaterials ) do
SkyMat:SetMaterialTexture( “$basetexture”, Material( “skybox/” … Name … Suffix ):GetMaterialTexture("$basetexture") )
end
end

// Cache the skybox materials
local function InitPostEntity()

SkyBoxName = GetConVarString( "sv_skyname" )

for _, Suffix in ipairs( SkyBoxSuffixes ) do
	SkyBoxMaterials[ Suffix ] = Material("skybox/" .. SkyBoxName .. Suffix)  
end

GAMEMODE:SetSkyBox( "starbox_" )

end
hook.Add( “InitPostEntity”, “SkyBox.InitPostEntity”, InitPostEntity )
[/lua]