Material Replacement Problem

Hey everyone, I’m trying to get a material replacement script working but can’t seem to work it correctly and for it to actually replace the materials. Anyways, the code is below. Some help would be much appreciated, thanks in advance!

cl_materials.lua:


local ReplacementMaterials = {	
{ Material("test/grass_material"), Material("test/grass_material_v2") },
{ Material("test/concrete_material"), Material("test/concrete_material_v2") }
			      }
							
function ReplaceMaterials()
	for k, v in pairs(ReplacementMaterials) do
		v[1]:SetMaterialTexture("$basetexture", v[2]:GetMaterialTexture("$basetexture"))
	end
end
hook.Add("Initialize", "ReplaceMaterials", ReplaceMaterials)

init.lua:


resource.AddSingleFile("materials/test/grass_material_v2.vtf")
resource.AddSingleFile("materials/test/grass_material_v2.vmt")
resource.AddSingleFile("materials/test/concrete_material_v2.vmt")
resource.AddSingleFile("materials/test/concrete_material_v2.vtf")

try:



v[1]:SetTexture("$basetexture", v[2]:GetTexture("$basetexture"):GetName())


Doesn’t work :confused: Thanks for trying though.

[editline]25th June 2013[/editline]

I experimented with the code and eventually got it to work, thanks anyways.