+ Reply to Thread
Page 3 of 6 FirstFirst 12345 ... LastLast
Results 21 to 30 of 51

Thread: NPC functions - Egate2

  1. #21
    Wire Sofaking Beer's Avatar
    Join Date
    Jul 2007
    Location
    Dallas, Texas
    Posts
    1,357

    Default Re: NPC functions - Egate2

    Would it be possible to have the NPCs act hostile towards other groups of the same type of NPC? For example, if Player A wanted to create NPCs that were hostile towards all of Player B's NPCs.

    Also, npcSetHealth() would be nice.

  2. #22
    Wirererer pl0x's Avatar
    Join Date
    Aug 2008
    Posts
    238

    Default Re: NPC functions - Egate2

    couldn't you use isOwner() then if the owner is PLayerB then se them to be hostile towards them.

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

    Default Re: NPC functions - Egate2

    Quote Originally Posted by Beer View Post
    Would it be possible to have the NPCs act hostile towards other groups of the same type of NPC? For example, if Player A wanted to create NPCs that were hostile towards all of Player B's NPCs.

    Also, npcSetHealth() would be nice.
    Well, from what I heard, ownership is a bit shady in GMod. There is a GetOwner() function somewhere in the E2 core folder, I could try that out and see how it goes. Anyone else is free to do so also.

    npcSetHealth() can be done. I was hoping to have a proper npcKill() function though, so you could kill off weakened troops and spawn new ones, which prevents healing during a war (cheating).
    The only thing is, clearing corpses is something I don't know how to do.
    If anyone makes either npcSetHealth() or npcKill(), I'll add them.

    Quote Originally Posted by pl0x View Post
    couldn't you use isOwner() then if the owner is PLayerB then se them to be hostile towards them.
    Well, I could look how isOwner() is done. Probably through the GetOwner() lua function I saw defined somewhere in the core folder. Even then I wouldn't really know how to set an NPC's disposition towards all NPCs owned by a specified person.

    I've looked through a lot of lua functions on the Gmod wiki, I didn't find any built-in ways of setting disposition by ownership. Only by entity data or class string (both of which are added).

    Perhaps Ents.FindByClass, cycling and having their ownership compared to an input entity, and disposition being set as it goes, inside a for loop. There has to be an easier way though.
    Last edited by Bobsymalone; 02-09-2009 at 04:46 PM.

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

    Default Re: NPC functions - Egate2

    Code:
    registerFunction("npcRelationshipByOwner", "e:esn", "n", function(self,args)
       local op1, op2, op3, op4 = args[2], args[3], args[4], args[5]
       local rv1, rv2, rv3, rv4 = op1[1](self,op1), op2[1](self,op2), op3[1](self,op3), op4[1](self,op4)
       local entity = checkEntity(rv1)
       local owner = checkEntity(rv2)
       local disp = NpcDisp(rv3)
       local prior = rv4
       if( !entity:IsNPC() ) then return 0 end
       local Table = Ents.FindByClass("npc_")
       if(Table.Count()==0) then return 0 end
    
       for i=1,Table.Count() do
    
          if(GetOwner(Table[i])==owner) then entity:AddEntityRelationship( Table[i], disp, prior ) end
    
       end
    
       return Table.Count()
    
    end)
    This should apply a relationship to stuff belonging to a specified owner. *Should*. Untested and such, and there might be an easier way of doing it. Adding it to the main file now.

    EDIT: Should there be a function to apply relationship to all entities in an array? Might be useful, less specialised than this too. I can keep this as well though.

    Another EDIT: There was an error generated with one of the new functions. Probably the one in this post. When I have time to debug I'll put them back in (they're just commented out if anyone wants to try them).

    Yet another EDIT: added missing "end" - thanks Polymorph/ZeikJT
    Last edited by Bobsymalone; 03-10-2009 at 10:54 AM.

  5. #25
    Wire Amateur Polymorph's Avatar
    Join Date
    Mar 2008
    Posts
    90

    Default Re: NPC functions - Egate2

    You need another 'end' in that function somewhere.

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

    Default Re: NPC functions - Egate2

    Ah indeed, the:
    for i=1,Table.Count() do

    Doesn't have an end because the next line with the if conditional stole it.
    Against stupidity the Gods themselves contend in vain.
    -Friedrich Schiller

    The flame puts me in the mood to "Do it!".
    -Dart, Legend of Dragoon

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

    Default Re: NPC functions - Egate2

    Quote Originally Posted by ZeikJT View Post
    Ah indeed, the:
    for i=1,Table.Count() do

    Doesn't have an end because the next line with the if conditional stole it.
    Ah! So it was. I'll test it in a bit then add it to the first post.

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

    Default Re: NPC functions - Egate2

    Is this ready for the SVN (if you want) or what's the status?

    (Same as last time, no npcSpawn-function though)

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

    Default Re: NPC functions - Egate2

    Quote Originally Posted by Syranide View Post
    Is this ready for the SVN (if you want) or what's the status?

    (Same as last time, no npcSpawn-function though)
    The status is... nearly done :P. I've been distracted from it for a while. I want to do a test of one of the newer functions first. Also don't worry there are two downloads in the OP, one without npcSpawn().

    EDIT: Just gotta fix a few bugs.
    Last edited by Bobsymalone; 03-23-2009 at 04:29 PM.

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

    Default Re: NPC functions - Egate2

    It works, feel free to SVN it. I took the npcSpawn() version out. If anyone has any multiplayer bugs to report with this version let me know, but there shouldn't be a problem.

    Code for npcSpawn() if anybody wants it:
    Code:
    registerFunction("npcSpawn", "sv", "e", function(self,args)
          local op1, op2 = args[2], args[3]
          local rv1, rv2 = op1[1](self,op1), op2[1](self,op2)
          local entity = ents.Create( rv1 )
          if( !entity:IsNPC() ) then return nil end
          local Vec = Vector( rv2[1], rv2[2], rv2[3] )
          entity:SetPos( Vec )
          entity:Spawn()
          entity:Activate()
          entity:AddRelationship("player", 4, 999)
          return entity
    
    end)

+ Reply to Thread
Page 3 of 6 FirstFirst 12345 ... 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