Hello guys, I need a small tidbit of help with spawning an NPC with a set of body groups.
I recently learned about the nifty Skin function in NPC coding that allows you to spawn an npc with a skin.
I've made 2 NPCs so far, one with a skin, and one without. I have intentions of making 2 more NPCS with the same model (one with a skin and one without), but both varients use body groups. The closest thing I've found to adding body groups is SetBodyGroup and SetBodyGroups but I don't know how to implement it. Can anyone give me a hand?
Here's the coding so far:
local Category = "FEAR 3 Enemy Forces"
local NPC = { Name = "ATC Replica Soldier",
Class = "npc_combine_s",
Model = "models/fear3/npc_combine_s/replica1.mdl",
Weapons = { "weapon_smg1", "weapon_ar2" },
Health = "100",
Squadname = "fear3_s",
Numgrenades = "6",
Category = Category }
list.Set( "NPC", "npc_atc_replica", NPC )
local NPC = { Name = "ATC Replica Shotgun Soldier",
Class = "npc_combine_s",
Model = "models/fear3/npc_combine_s/replica1.mdl",
Skin = 1,
Weapons = { "weapon_shotgun" },
Health = "100",
Squadname = "fear3_s",
Numgrenades = "6",
Category = Category }
list.Set( "NPC", "npc_atc_replica_shotgunner", NPC )
You could add a OnEntityCreated() hook and check for the NPC like this
hook.Add("OnEntityCreated", "fear2bg", function()
if (SERVER) then
timer.Simple(0.1, function() --Just to be safe
if ent:IsNPC() and ent:GetClass() == "npc_combine_s" then
ent:SetBodygroup(0, 0)
end
end)
end
end)
However this also means that all Combine soldiers get their bodygroup set, you might want to check their name or something instead of Class.
I will look into adding bodygroup support to the "NPC" list for a future update.
Awesome, thanks for considering adding a form of bodygroups to NPCS. Hopefully implementation won't be too crazy or troublesome.
The format will be as follows:
AddNPC( {
Name = "Zombie",
Class = "npc_zombie",
Category = Category,
KeyValues = {
SquadName = "zombies" },
BodyGroups = {
[ 1 ] = 0,
[ 2 ] = 2,
}
} )
Don't mind the formatting, the forum code tags fucks it up.
So will 1 and 2 be based on the amount of body groups, or the actual name of said bodygroup?
1 and 2 are the IDs, 0 and 2 are the values to Entity/SetBodygroup
Sorry, you need to Log In to post a reply to this thread.