Adding all entity classes to an entities relationship

I’m trying to make the NPC I’m creating neutral to all entity classes, I know how to use **[NPC.AddRelationship

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=NPC.AddRelationship)** for single classes, but I don’t know how to make it neutral to all classes.

Would I have to do that for every single class? (Could be done using a loop, but I’d need some sort of function which returns a table containing all the possible entity classes (which I can’t find))

Here’s the valve wiki, it has all default npc classes, hope that helps.

Just don’t set any enemys in the first place, by default every npc should be neutral to your snpc.

I’m not making a SNPC, I’m using the default ones, and for example, if you spawn a zombie and an antlion they will attack each other.

It’s sorted now, I took all the entities in the list Fantym420 provided and put them into a table to loop through.

Thats a bad way of doing that…

This is of the top of my head here, but you should do something like this instead, its compatible with the snpcs too, also dosn’t f up if you set its relashionship afterwards, just implement something like that to your code.


local RelSetTimer = CurTime()+ 1
local RSNPC = <<your npc>>

hook.Add("Think", "RelSetThink", function()
    if CurTime() >= RelSetTimer then
        for _,npc in pairs(ents.GetAll()) do
            if npc:IsNPC() and !table.HasValue(npc.RSEntList,RSNPC) then
            npc:AddEntityRelationship(RSNPC, 4) table.Insert(npc.RSEntList, RSNPC)
            end
        end
    RelSetTimer = CurTime()+ 1
    end
end

You are going to loop through every ENT every 1 second just to set an entity relationship?

Yea, the table of classes idea is a smaller loop and if you called it in GM:OnEntityCreated() hook it won’t add that much overhead.

Yeah :confused: I guess you’re right, too much consumption just for that, tho its only done every 1 second, so its not really noticeable. It works when an npc is spawned not through the spawn menu too.