• Adding all entity classes to an entities relationship
    7 replies, posted
I'm trying to make the NPC I'm creating neutral to all entity classes, I know how to use [b][url=http://wiki.garrysmod.com/?title=NPC.AddRelationship]NPC.AddRelationship [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] 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. [url]http://developer.valvesoftware.com/wiki/List_of_entities#NPC_Entities[/url]
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.[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[/CODE]
[QUOTE=freemmaann;27731810]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.[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.Add(npc.RSEntList, RSNPC) end end RelSetTimer = CurTime()+ 1 end end[/CODE][/QUOTE] 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.
[QUOTE=Fantym420;27735442]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.[/QUOTE]Yeah :/ 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.
Sorry, you need to Log In to post a reply to this thread.