materials.Create(name:string, vmt:string):MaterialCreate a material from a VMT string; reuses an existing name; returns an error material on a bad VMT.
Create and inspect materials; model queries.
materials.Create(name:string, vmt:string):MaterialCreate a material from a VMT string; reuses an existing name; returns an error material on a bad VMT.
materials.Find(name:string):MaterialFind a material by name.
materials.Loaded(name:string):booleanWhether a material is loaded.
materials.Remove(name:string):booleanRemove a script-created material; false when not found.
materials.Enumerate(cb:function)Call cb(material) for every loaded material; stops if the callback errors.
models.GetModel(index:number):ModelModel wrapper for a model index.
models.GetModelIndex(name:string):numberModel index for a name; -1 when unknown.
models.GetStudioModel(model:Model):StudioModelHeaderStudio header of a model.
models.GetModelName(model:Model):stringName and path of a model.
models.GetModelMaterials(model:Model):tableList of a model's materials.
models.GetModelRenderBounds(model:Model):Vector3,Vector3Render bounds mins and maxs of a model.
models.GetModelBounds(model:Model):Vector3,Vector3Collision bounds mins and maxs of a model.
Override your weapons with a flat gold material using DrawModel.
local gold = materials.Create("weapon_gold", [[
"UnlitGeneric"
{
"$basetexture" "vgui/white"
"$model" "1"
}
]])
callbacks.Register("DrawModel", function(ctx)
local ent = ctx:GetEntity()
if not ent:IsValid() or not ent:IsWeapon() then return end
local me = client.GetLocalPlayer()
if not me:IsValid() or ent:GetIndex() ~= me:GetIndex() then return end
gold:SetColorModulation(1, 0.8, 0.2)
ctx:ForcedMaterialOverride(gold)
end)