Changing a model's base texture (not MaterialOverride) help.
0 replies, posted
So basically I've got a little SENT I made and when it gets damaged I want to change the material of the model.
I tried like:
[LUA]
function ENT:Draw()
local mat = self.ChangeMaterial
if mat then
print(mat)
render.SetMaterial(Material(mat))
self.Entity:DrawModel()
render.SetMaterial(nil)
self.ChangeMaterial = nil
else
self:DrawModel()
end
end[/lua]
And like:
[lua]function ENT:Draw()
local mat = self.ChangeMaterial
if mat then
--local curtexture = self:GetMaterial() --This just returns a line break? Very useful...
local oldtex = Material("models/cube_1x1")
local oldbase = oldtex:GetTexture("$basetexture")
local newtex = Material(mat)
oldtex:SetTexture("$basetexture", newtex:GetTexture("$basetexture"))
self:DrawModel()
self.ChangeMaterial = nil
oldtex:SetTexture("$basetexture", oldbase)
else
self:DrawModel()
end
end[/lua]
But I think the problem is that I have no idea which texture the model is actually using, I'm pretty sure that I'm using the right one, and it doesn't return an error, but even if I have the right one it's still probably not working.
When I try to do just a simple SetMaterial() on the model, it applies the texture like a MaterialOverride which is stretched and tiled poorly instead of looking the way I want.
also self.ChangeMaterial is set on the Client Side whenever the prop's health goes below a certain number, and I'm sure this function is being called as the actual one I have is full of print"stupid stuff"
Sorry, you need to Log In to post a reply to this thread.