+ Reply to Thread
Page 1 of 6 123 ... LastLast
Results 1 to 10 of 51

Thread: NPC functions - Egate2

  1. #1
    Wire Sofaking Bobsymalone's Avatar
    Join Date
    Jul 2008
    Posts
    770

    Default NPC functions - Egate2

    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.

    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()
       }
    
    }
    CREDITS:
    -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.
    Attached Files Attached Files
    Last edited by Bobsymalone; 03-25-2009 at 11:52 AM.

  2. #2
    Wire Sofaking ZeikJT's Avatar
    Join Date
    Dec 2008
    Location
    California
    Posts
    1,391

    Default Re: NPC functions - Egate2

    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

  3. #3
    Expressionism 2.0 Syranide's Avatar
    Join Date
    Mar 2007
    Location
    Sweden
    Posts
    4,573

    Default Re: NPC functions - Egate2

    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.

  4. #4
    Wire Amateur hexpunK's Avatar
    Join Date
    Sep 2008
    Location
    Thetford, England
    Posts
    45

    Default Re: NPC functions - Egate2

    Mmmm, NPC control through Wire, sounds great. Shame I don't understand E2 enough to use it.

  5. #5
    Wire Sofaking Bobsymalone's Avatar
    Join Date
    Jul 2008
    Posts
    770

    Default Re: NPC functions - Egate2

    Quote Originally Posted by Syranide View Post
    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.
    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.

  6. #6
    http://somone77.net somone77's Avatar
    Join Date
    Jun 2008
    Location
    <Smart ass location>
    Posts
    613

    Default Re: NPC functions - Egate2

    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?

  7. #7
    Wire Sofaking Bobsymalone's Avatar
    Join Date
    Jul 2008
    Posts
    770

    Default Re: NPC functions - Egate2

    Quote Originally Posted by somone77 View Post
    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.

  8. #8
    Wire Sofaking oenmaster's Avatar
    Join Date
    Jan 2008
    Location
    fak where is my satnav (NL)
    Posts
    717
    Blog Entries
    1

    Default Re: NPC functions - Egate2

    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?

  9. #9
    Wire Sofaking Bobsymalone's Avatar
    Join Date
    Jul 2008
    Posts
    770

    Default Re: NPC functions - Egate2

    Quote Originally Posted by oenmaster View Post
    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?
    If you're asking how it'll be handled if the server has NPC limits set to 0, well I'd imagine you'd be unable to spawn any NPCs. Can you set limits in singleplayer? If so I'll test it and get back to you.

  10. #10
    Wire Sofaking Bobsymalone's Avatar
    Join Date
    Jul 2008
    Posts
    770

    Default Re: NPC functions - Egate2

    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.

+ Reply to Thread
Page 1 of 6 123 ... LastLast

Similar Threads

  1. E-2 some functions.
    By Whodunnit in forum Ideas & Suggestions
    Replies: 12
    Last Post: 03-11-2009, 05:31 AM
  2. Right click functionality (egate2)
    By mjmr89 in forum Ideas & Suggestions
    Replies: 11
    Last Post: 01-23-2009, 06:49 PM
  3. Egate2 Wirelink
    By Jarviar in forum Installation and Malfunctions Support
    Replies: 13
    Last Post: 12-28-2008, 11:49 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
proceed-collector
proceed-collector
proceed-collector
proceed-collector
linguistic-parrots
linguistic-parrots
linguistic-parrots
linguistic-parrots