To make a NPC like the players, I did this:
nuEnt:AddEntityRelationship(player.GetAll, 3, 99 )
I'm not sure if that works, but it should. But now I want that NPC to hate every other NPC so, how do I do that?
Actually your code would be this :
[lua]nuEnt:AddEntityRelationship(player.GetAll(), 3, 99 )[/lua]
Since player.GetAll() is a function. :smile:
For making it hate every other NPC regardless of when they're spawned you could use NPC:AddRelationship() on it when it is spawned (or initialized) and do it for each npc class it has to hate.
[url=http://wiki.garrysmod.com/?search=player.GetAll&go=Go][I]player.GetAll[/I] ([B]Wiki link [img]http://wiki.garrysmod.com/favicon.ico[/img][/b])[/url]
[url=http://wiki.garrysmod.com/?search=NPC.AddRelationship&go=Go][I]NPC.AddRelationship[/I] ([B]Wiki link [img]http://wiki.garrysmod.com/favicon.ico[/img][/b])[/url]
:science:
[QUOTE=Crazy Quebec;18319200]Actually your code would be this :
[lua]nuEnt:AddEntityRelationship(player.GetAll(), 3, 99 )[/lua]
Since player.GetAll() is a function. :smile:
[/QUOTE]
Oops, thanks.
[QUOTE=Crazy Quebec;18319200]For making it hate every other NPC regardless of when they're spawned you could use NPC:AddRelationship() on it when it is spawned (or initialized) and do it for each npc class it has to hate.
[/QUOTE]
NPC class? Where can I see which classes there are?
To get any NPC's or entity's class you would use Entity:GetClass().
For a list of all HL2 NPCs go here: [url]http://developer.valvesoftware.com/wiki/Category:NPCs[/url]
[url=http://wiki.garrysmod.com/?search=Entity.GetClass&go=Go][I]Entity.GetClass[/I] [img]http://wiki.garrysmod.com/favicon.ico[/img][/url]
:banjo:
[QUOTE=Crazy Quebec;18320603]To get any NPC's or entity's class you would use Entity:GetClass().
For a list of all HL2 NPCs go here: [url]http://developer.valvesoftware.com/wiki/Category:NPCs[/url]
[url=http://wiki.garrysmod.com/?search=Entity.GetClass&go=Go][I]Entity.GetClass[/I] [img]http://wiki.garrysmod.com/favicon.ico[/img][/url]
:banjo:[/QUOTE]
Ah, that class, like npc_headcrab and npc_headcrab_fast.
There are many NPCs, I'll need to write every class?
[QUOTE=gilmouta;18320799]Ah, that class, like npc_headcrab and npc_headcrab_fast.
There are many NPCs, I'll need to write every class?[/QUOTE]
Well for any class your NPC doesn't hate by default. No need to make it hate classes it won't ever meet as well.
Problem is that the NPC can be any NPC.
Edit:
Isn't there a way to make it hate every entity started with "npc_"?
[lua]
for k,v in pairs(ents.FindByClass("npc_*")) do
v:AddRelationship("player D_HT 99")
end
[/lua]
And don't you steal my fucking avatar now.
Um, that makes every NPC like the player, right?
[QUOTE=gilmouta;18321852]Um, that makes every NPC like the player, right?[/QUOTE]
What? Nooooooo :downs:
[QUOTE=Sippeangelo;18321789][lua]
for k,v in pairs(ents.FindByClass("npc_*")) do
v:AddRelationship("player D_HT 99")
end
[/lua]
And don't you steal my fucking avatar now.[/QUOTE]
[lua]
for k,v in pairs(ents.FindByClass("npc_*")) do
v:AddRelationship("nuEnt D_HT 99")
end
[/lua]
Putting nuEnt (which is a npc) instead of player should work?
And, I didnt steal your avatar. Mine doesn't allow to be poked.
[QUOTE=gilmouta;18322086][lua]
for k,v in pairs(ents.FindByClass("npc_*")) do
v:AddRelationship("nuEnt D_HT 99")
end
[/lua]
Putting nuEnt (which is a npc) instead of player should work?
And, I didnt steal your avatar. Mine doesn't allow to be poked.[/QUOTE]
What you need there is an entity class name. So that code would make every NPC hate the class noEnt.
[lua]
for k,v in pairs(ents.FindByClass("npc_*")) do
nuEnt:AddRelationship(v:GetClass().." D_HT 99")
end
[/lua]
That would make the entity named nuEnt hate every NPC class that is currently spawned.
Oh, thanks.
Currently spawned? If I spawn another NPC he wont be hated? If not, any way to fix that?
Anyways, thanks a lot.
[QUOTE=gilmouta;18322276]Oh, thanks.
Currently spawned? If I spawn another NPC he wont be hated? If not, any way to fix that?
Anyways, thanks a lot.[/QUOTE]
Well that's why you should just make it hate every npc class manually. And the previous code would make it hate any npc class that currently has a member spawned. So if only a manhack was spawned the NPC would hate only manhacks, but forever. So it's not a very reliable way.
[QUOTE=Crazy Quebec;18322449]Well that's why you should just make it hate every npc class manually. And the previous code would make it hate any npc class that currently has a member spawned. So if only a manhack was spawned the NPC would hate only manhacks, but forever. So it's not a very reliable way.[/QUOTE]
This will take some time, heh.
One thing:
entities/ent_pokeball/init.lua:60: bad argument #1 to 'AddEntityRelationship' (Entity expected, got table)
Line 60:
[lua]nuEnt:AddEntityRelationship(player.GetAll(), 3, 99 ) -- likes the player[/lua]
How did I not catch that.. Anyway the error is pretty self-explanatory. It expects an entity and you give it a table of entities.
Just do nu:EntAddRelationship("player D_LI 99")
Thanks. Almost fully working but I made something like this:
[lua]
allclasses = {"npc_zombie","npc_fastzombie","npc_citizen",.......}
nuEnt:AddRelationship("allclasses D_HT 99")
[/lua]
It doesn't work, and I saw no error.
allclasses isn't a npc class, it's a table you've just defined, so it obviously won't work. :smile:
What you need to do is loop trough all elements of the table and use of the values in your function.
[lua]local allclasses = {"npc_zombie","npc_fastzombie","npc_citizen",.......} -- Variables should always be local unless you plan to use them elsewhere.
for k,v in pairs(allclasses) do --See the wiki links for an explanation of this
nuEnt:AddRelationship(v.." D_HT 99")--Here I'm using concatenation, see the links.
end[/lua]
[B]Mandatory wiki links[/B]
[url=http://wiki.garrysmod.com/?search=About the Tutorial][I]Lua Tutorial[/I] [img]http://wiki.garrysmod.com/favicon.ico[/img][/url]
[url=http://wiki.garrysmod.com/?search=Using the for in loop][I]Using the for in loop[/I] [img]http://wiki.garrysmod.com/favicon.ico[/img][/url] (Page from the Lua Tutorial)
[url=http://wiki.garrysmod.com/?search=Variables#Concatenation][I]Concatenation[/I] [img]http://wiki.garrysmod.com/favicon.ico[/img][/url] (Page from the Lua Tutorial)
:dance:
I see, thank you. I took a look at "Using the for in loop", which I don't know why I never did.
Now that nuEnt hates every NPC, how do I make every NPC hate him?
I tried:
[lua]
for k,v in pairs(allclasses) do
v:AddRelationship("nuEnt D_HT 99")
end
[/lua]
Didn't work.
Well if you look at your allclasses table you'll notice that it only contains strings, so you're asking a string to hate your entity.
I would probably do this :
[lua]hook.Add("OnEntityCreated","nuEntHate", function(ent)
if ent:IsNPC() then
ent:AddRelationship("nuEnt D_HT 99")
end
end)[/lua]
nuEnt needs to be a valid entity class name tough, not just a named entity.
[url=http://wiki.garrysmod.com/?search=gamemode.OnEntityCreated][I]gamemode.OnEntityCreated[/I] [img]http://wiki.garrysmod.com/favicon.ico[/img][/url]
[lua]
local nuEnt = ents.Create(self.npctype) -- create the entity
[/lua]
So I guess that wouldn't work.
[QUOTE=gilmouta;18352768][lua]
local nuEnt = ents.Create(self.npctype) -- create the entity
[/lua]
So I guess that wouldn't work.[/QUOTE]
Nope. Then you would need to make it so that each time a nuEnt is spawned every NPC on the map (except maybe other nuEnts) is made to hate them, and each time a NPC is spawned it is made to hate all nuEnts.
[QUOTE=Crazy Quebec;18354153]Nope. Then you would need to make it so that each time a nuEnt is spawned every NPC on the map (except maybe other nuEnts) is made to hate them, and each time a NPC is spawned it is made to hate all nuEnts.[/QUOTE]
How do I make that?
[QUOTE=gilmouta;18354635]How do I make that?[/QUOTE]
Simple, just figure it out.
I've explained it every possible way one can explain things and you might want to work out your brain a bit.
Seriously I already told you everything you need to know, unless you've been blindly copy-pasting that is.
Sorry, you need to Log In to post a reply to this thread.