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.


LinkBack URL
About LinkBacks




Reply With Quote






Bookmarks