• Turning red/bloody NPC's eyeballs
    4 replies, posted
I am trying to make a zombie (You can probably guess which fictional zombie by the map and the models) and I thought that bloody eyes would be a nice touch. Now I'll just clarify that I have never done any work with modelling/texturing especially on valve stuff so I don't know what all those symbols and words mean when making a custom material, but I just looked up online and hoped it would work. Unfortunately I am not sure what happened and why this happened: https://streamable.com/n8oq9 I am clearly targetting the eyes in the code but it looks as if it's randomized. I might as well say that I did find why they are transparent while writing this, and it was because apparently after creating a material you can't modify it, so I just had to reload the server. Here's the code I'm using (It's inside the ENT:Initialize): CreateMaterial("RedEye", "VertexLitGeneric", { ["$basetexture"] = "models/debug/debugwhite", ["$surfaceprop"] = "flesh", ["$model"] = 1 }):SetVector("$color2", Vector(255,0,0)) for k, v in pairs(self:GetMaterials()) do if(string.find(v, "eyeball")) then self:SetSubMaterial(k, "!RedEye") end end I'm not using the code tags because they are broken and it's unbelievable that they still are. Unless it's just me.
GetMaterials returns materials starting index from 1 but SetSubMaterial indices start from 0. Also did you see the note at https://wiki.garrysmod.com/page/Entity/GetMaterials about material replacement?
Yeah that did it, here's the updated code in case people need it: CreateMaterial("RedEye", "VertexLitGeneric", { ["$basetexture"] = "models/debug/debugwhite", ["$surfaceprop"] = "flesh", ["$model"] = 1 }):SetVector("$color2", Vector(255,0,0)) for k, v in pairs(self:GetMaterials()) do if(string.find(v, "eyeball")) then self:SetSubMaterial(k - 1, "!RedEye") end end
Wait, I never tried to replace a material but. you did if(string.find(v "eyeball") ok but, there are a lot of materials named eyeball.
It targets only the eyeball material on an NPC and it will be used only on human models. It's so if the NPC model has a mask and no eyeball model it won't set the material for something that isn't there.
Sorry, you need to Log In to post a reply to this thread.