Oh my... this sounds awesome! Definitely gonna download.
Nice work![]()
Wiki entry: Wire Expression2 - GMod Wiki
These functions allow you to control NPCs.
Controlling them completely is difficult due to overriding AI, but you can tell them how to feel about certain things, where to go, etc. You can also equip NPCs with weapons
Done:
E:npcStop() N
Stops all activities NPC E is doing.
E:npcGoWalk(V) N
Makes NPC E walk to position V.
E:npcGoRun(V) N
Makes NPC E run to position V.
E:npcFace(V) N
Makes NPC E face position V.
E:npcAttack() N
Makes NPC E attack with melee.
E:npcShoot() N
Makes NPC E shoot their gun if they have one.
E:npcGiveWeapon(S)
Gives NPC E weapon S. If no weapon is specified, gives an smg. eg. "smg1", "pistol"
Relationships:
E:npcRelationship(E,S,N)
Sets relationship to the specified entity to the string disposition, with N priority.
E:npcRelationship(S,S,N)
Same as above, except sets relationship to class string.
E:npcRelationshipByOwner(E,S,N) N
Same as above, except sets relationship to all NPCs owned by player E. Returns number of entities added to relationship.
NOTE: Entities spawned after running this function aren't automatically added.
E:npcDisp(E)
Returns string disposition of first entity to the second.
Dispositions:
- neutral
- hate
- like
- fear
Example of usage:
E:npcRelationship("npc_manhack", "fear", 999)
E:npcRelationship(entity(), "fear", 10)
This will make NPC E fear manhacks and the chip, but it'll fear manhacks a lot more.
With the help of arrays and tables, you can control a large amount of NPCs at once and guard your bases! Or, just make remote controlled NPC avatars.
Put npc.lua into your addons\wire\lua\entities\gmod_wire_expression2\cor e\custom folder.
Post suggestions, criticism, etc.
Example dupe:
The attached dupe is a simple example of how to use the functions. Hit 0 on the numpad and the nearest NPC will become a "pet", following you.
CREDITS:Code:@name NPC pet @inputs Find @outputs @persist NPC:entity if(Find&~Find) { findByClass("npc_*") NPC = findClosest(owner():pos()) NPC:npcRelationship("player","neutral",900) NPC:npcRelationship(owner(),"like",999) } if(NPC) { interval(1000) OwnerPos = owner():pos() DPos = OwnerPos - NPC:pos() WalkPos = OwnerPos - DPos:normalized()*100 if(DPos:length()>120) { NPC:npcGoRun( WalkPos ) } else { NPC:npcStop() } }
-ZeikJT helped a lot with lua functions.
-AphisNano for the Disposition() lua function.
UPDATE: Added another version with the npcSpawn() function removed.
UPDATE: Added E:npcFace(V) and E:npcStop()
UPDATE: Relationships and E:npcGiveWeapon(), also fixed server crashing bug when telling an unarmed NPC to shoot.
UPDATE: Add relationships to all NPCs belonging to owner with npcRelationshipByOwner(), find disposition of an entity to another using npcDisp()
UPDATE: Fixed bugs and attached an example dupe.
Last edited by Bobsymalone; 03-25-2009 at 11:52 AM.
Oh my... this sounds awesome! Definitely gonna download.
Nice work![]()
Against stupidity the Gods themselves contend in vain.
-Friedrich Schiller
The flame puts me in the mood to "Do it!".
-Dart, Legend of Dragoon
Is there any reason real why the functions would not be successful? (return 0)
Otherwise I'd suggest just having them return nothing instead at all times (because people should use isNPC() to make sure it is an NPC before anyway).
But this really sounds nice yes!
EDIT: I could recommend adding some helper functions for having NPCs turn to a world position... and it doesn't seem like they can attack anything else but straight ahead right now?
EDIT: Although if you want this on the official SVN later, I will not allow the npcspawn-function, it is way to abuseable.
Last edited by Syranide; 01-31-2009 at 03:59 AM.
Mmmm, NPC control through Wire, sounds great. Shame I don't understand E2 enough to use it.
Well, they all return 0 if you try to use it on a non-NPC entity. Is there a significant performance loss if they return 0 or 1? I don't know, I've never coded before.
Yeah, turning is on my to-do list, it'd be super useful. Right now you can turn NPCs by moving a short distance in a direction, but yeah, it needs a helper function.
Most servers don't allow NPCs anyway, and npcSpawn() is just a quick way to repopulate your "army". (Speaking of which, I need some way of killing and removing bodies, if anyone has any ideas).
I wouldn't say it's much different from a prop spawner or adv dupe paster really. Except with the added protection of servers not usually allowing NPCs, and if they do, not many.
(In fact, you can spam NPCs with an adv dupe paster anyway).
I would like to keep npcSpawn() in there in some way, but if it's really a problem I can remove it. If you have any ideas for restrictions that would make this SVNable without removing it, let me know.
I could limit the area you can spawn an NPC in to within a certain distance from the Egate maybe?
EDIT: Added new lua file with npcSpawn() commented out in the meantime.
Last edited by Bobsymalone; 01-31-2009 at 12:21 PM.
Uhh...I don't know if this is a stupid thing but in my server i get an error in the console saying: Error SENDING CLIENTSIDE file: File Not Found: custom.lua I assume this means that I am missing that... Where do i get it or is my wiremod broken or something?
Well, you should have custom.lua anyway if you have the SVN. It's because I started making these functions in there, then copied it over to its own file, but I forgot to remove this at the top:
AddCSLuaFile('custom.lua')
I'll sort it out now.
EDIT: Done, sorry about that. I've never done this before.
I replaced AddCSLuaFile('custom.lua') with AddCSLuaFile('npc.lua'), is that right?
Last edited by Bobsymalone; 01-31-2009 at 12:42 PM.
and the zero NPC on the server ... how will that be handed
i mean like the crate maker tool is working (with limit 0 on)
how about this?
Youtube :http://www.youtube.com/user/oen2oen
UPDATE: Added two new functions, E:npcStop() and E:npcFace(V). Check descriptions in the first post.
One problem (of many) that I'm having is giving a weapon to an NPC.
Another is knowing when an NPC has a weapon. This is important because if you use npcShoot() on an unarmed NPC, you'll crash Gmod (and presumably the server).
Lastly: After facing the NPC in a direction with npcFace(), if you try to shoot it'll turn back around. Not very useful at all.
The problem is probably that I resorted to SetPos()ing the NPC around, which doesn't really tell the AI anything as far as I'm aware. Doesn't tell it to stay there. It's generally a bad way of doing things and I need a new way.
Any ideas anyone?
Last edited by Bobsymalone; 02-01-2009 at 01:36 PM.
Bookmarks