Hi people, I'm trying to do a (yet another) headcrab remover addon, that can be toggled inside the game. For this reason, I can't simply replace the material files with blanks. What I'm doing is replacing the materials when a zombie npc spawns. It works, but there's a little problem...
When a zombie is cut in half, and he's still alive, this crawling zombie doesn't seem to trigger the "OnEntityCreated" hook, so he still has a headcrab. I really don't want to use a Think() hook with Ents.GetAll(), so I need to find another way. Is there any function to completely replace a texture with another one in every instance? Like replacing a material file, but with lua?
EDIT: I tried this:
[CODE]local mat = Material("models/headcrab_classic/headcrabsheet")
local mat2 = Material("models/effects/vol_light001")
mat:SetTexture("$basetexture", mat2:GetTexture("$basetexture"))[/CODE]
But it replaced the headcrab textures with a black one. I guess I need to do something else to make it invisible, but I really don't know much about materials. Any ideas?
Try this:
[lua]
ZOMBIE_BODYGROUP_HEADCRAB = 1
npc:SetBodygroup(ZOMBIE_BODYGROUP_HEADCRAB, 0)
[/lua]
Will remove the headcrab.
[QUOTE=Zeh Matt;52025722]Try this:
[lua]
ZOMBIE_BODYGROUP_HEADCRAB = 1
npc:SetBodygroup(ZOMBIE_BODYGROUP_HEADCRAB, 0)
[/lua]
Will remove the headcrab.[/QUOTE]
Yeah, both that and replacing the texture of every NPC works, but like I said in the original post, when you cut a zombie in half without killing him, the OnEntityCreated hook doesn't trigger (its the same zombie), so I can't do anything with that crawler unless I iterate over Ents:GetAll() in a Think hook or a timer, which I don't want to do. Thats why I want to find a way to replace the texture for a blank one in every headcrab material.
EDIT: Nevermind. I solved it by disabling the bodygroup and storing the NPC's in a table when they spawn. Then a Think hook checks if the entities in that table changed their models. That means they turned into a crawler, and I have to disable the bodygroup again. That should be much better than looping over Ents:GetAll()
When a zombie was splited, what hook it should be call ? If it's the same entity, can you register the body group on is metatable (and not in a general global table)?
Cause if it's the same ent, the splited body group should be define somewhere. Or the function who splite the zombie (i think ^^" )
[QUOTE=Nyhu;52027200]When a zombie was splited, what hook it should be call ? If it's the same entity, can you register the body group on is metatable (and not in a general global table)?
Cause if it's the same ent, the splited body group should be define somewhere. Or the function who splite the zombie (i think ^^" )[/QUOTE]
I checked the half zombie npc with the entity inspector, and it's an npc_zombie instead of an npc_zombie_torso, so when you cut them in half, it doesn't create a new entity, it's the same zombie. To see if the zombie was cut in half I check if its model changed, in a think hook. I don't think there's another hook for that.
It does seem odd that there's no way to catch it. Unfortunately I've found nothing. The think hook is unlikely to cause issues though. Make sure you remove invalid entities from your table as soon as they become invalid.
Sorry, you need to Log In to post a reply to this thread.