+ Reply to Thread
Page 2 of 6 FirstFirst 1234 ... LastLast
Results 11 to 20 of 51

Thread: NPC functions - Egate2

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

    Default Re: NPC functions - Egate2

    I don't know what works on an NPC and what doesn't so I'll list some commands that can be used on entities:
    entity:EyeAngles( )
    player:SetEyeAngles( Angle )
    entity:SetAngles( Angle angles )

    For the weapon, do the regular routines not work?
    player:HasWeapon( string WeaponClass )
    player:GetWeapons( )
    player:GetWeapon(String Weaponclassname)( )
    Against stupidity the Gods themselves contend in vain.
    -Friedrich Schiller

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

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

    Default Re: NPC functions - Egate2

    Quote Originally Posted by ZeikJT View Post
    I don't know what works on an NPC and what doesn't so I'll list some commands that can be used on entities:
    entity:EyeAngles( )
    player:SetEyeAngles( Angle )
    entity:SetAngles( Angle angles )

    For the weapon, do the regular routines not work?
    player:HasWeapon( string WeaponClass )
    player:GetWeapons( )
    player:GetWeapon(String Weaponclassname)( )
    Thanks a bunch! These will be useful whether I use them for these NPC functions or not. I was using SetAngles() though.

    I can't say if regular routines work, since I didn't know what regular routines were. I'll try them.

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

    Default Re: NPC functions - Egate2

    Quote Originally Posted by Bobsymalone View Post
    Thanks a bunch! These will be useful whether I use them for these NPC functions or not. I was using SetAngles() though.

    I can't say if regular routines work, since I didn't know what regular routines were. I'll try them.
    You can always look here for entities:
    Entity - GMod Wiki

    Here for players:
    Player - GMod Wiki

    Here for npcs... very disappointing though:
    NPC - GMod Wiki

    Oh and this function is also important and not directly linked to on npc page:
    NPC.StartSchedule - GMod Wiki

    EDIT: On testing I found that GetActiveWeapon returns the weapon entity the npc is using. So that should work fine for detection.

    Here's a better NPC functions list:
    http://wiki.garrysmod.com/wiki/?titl...C_.28Object.29
    Last edited by ZeikJT; 02-01-2009 at 03:43 PM.
    Against stupidity the Gods themselves contend in vain.
    -Friedrich Schiller

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

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

    Default Re: NPC functions - Egate2

    Quote Originally Posted by ZeikJT View Post
    You can always look here for entities:
    Entity - GMod Wiki

    Here for players:
    Player - GMod Wiki

    Here for npcs... very disappointing though:
    NPC - GMod Wiki

    Oh and this function is also important and not directly linked to on npc page:
    NPC.StartSchedule - GMod Wiki

    EDIT: On testing I found that GetActiveWeapon returns the weapon entity the npc is using. So that should work fine for detection.

    Here's a better NPC functions list:
    Server Function Dump - GMod Wiki
    Yeah I know about those first links, but the last one solves a fair few problems for me, thanks!

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

    Default Re: NPC functions - Egate2

    Quote Originally Posted by Bobsymalone View Post
    Yeah I know about those first links, but the last one solves a fair few problems for me, thanks!
    No problem. Since there are so many functions in red it could be helpful for you to test these things via console.
    Some noteworthy commands to use for debug in console:
    lua_run
    lua_run_cl
    You put that in the console followed by lua code and it will run, example:
    lua_run print(ents.GetByIndex(1):GetName())
    lua_run PrintTable(debug.getinfo(_R[4].GetNPCState))

    You can test out the NPC functions from there without having to code, restart, code, restart...
    If you want you could even dump the _R table, specifically subtable 4. It has a lot of the NPC available functions:
    Code:
    lua_run file.Write("global/_R4.txt",table.ToString(_R[4],"_R[4]",true))
    or for the entire _R table:
    Code:
    lua_run file.Write("global/_R.txt",table.ToString(_R,"_R",true))
    or for the WHOLE _G table, it includes _R:
    Code:
    lua_run file.Write("global/_G.txt",table.ToString(_G,"_G",true))
    It will dump to a garrysmod/garrysmod/data/global/ folder, you can change that if you want to.
    Against stupidity the Gods themselves contend in vain.
    -Friedrich Schiller

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

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

    Default Re: NPC functions - Egate2

    Updated with relationship functions and E:npcGiveWeapon(S)

  7. #17
    Wire Amateur AphisNano's Avatar
    Join Date
    Feb 2009
    Location
    Somewhere in WA
    Posts
    51

    Default Re: NPC functions - Egate2

    Any chance of checking to see if an NPC has a certain type of relationship towards an entity?
    Code:
    if(A:Likes(B)) ...
    EDIT: Got bored, and decided to make a patch implementing this functionality.

    Code:
    // By AphisNano
    //
    // Checks an entity's disposition to see if it likes another entity.
    //
    registerFunction("npcLikes", "e:e", "n", function(self,args)
       local op1, op2 = args[2], args[3]
       local rv1, rv2 = op1[1](self,op1), op2[1](self,op2)
       local entity = checkEntity(rv1)
       local target = rv2
       local disp = 3
       if( !entity:IsNPC() || disp == 0 ) then return 0 end
       if(entity:Disposition(target)==disp) then return 1 else return 0 end
    
    end)
    
    // By AphisNano
    //
    // Checks an entity's disposition to see if it hates another entity.
    //
    registerFunction("npcHates", "e:e", "n", function(self,args)
       local op1, op2 = args[2], args[3]
       local rv1, rv2 = op1[1](self,op1), op2[1](self,op2)
       local entity = checkEntity(rv1)
       local target = rv2
       local disp = 1
       if( !entity:IsNPC() || disp == 0 ) then return 0 end
       if(entity:Disposition(target)==disp) then return 1 else return 0 end
    
    end)
    
    // By AphisNano
    //
    // Checks an entity's disposition to see if it is neutral towards another entity.
    // (Long name, amazing results [tm])
    //
    registerFunction("npcIsNeutralTowards", "e:e", "n", function(self,args)
       local op1, op2 = args[2], args[3]
       local rv1, rv2 = op1[1](self,op1), op2[1](self,op2)
       local entity = checkEntity(rv1)
       local target = rv2
       local disp = 4
       if( !entity:IsNPC() || disp == 0 ) then return 0 end
       if(entity:Disposition(target)==disp) then return 1 else return 0 end
    
    end)
    
    // By AphisNano
    //
    // Checks an entity's disposition to see if it fears another entity.
    //
    registerFunction("npcFears", "e:e", "n", function(self,args)
       local op1, op2 = args[2], args[3]
       local rv1, rv2 = op1[1](self,op1), op2[1](self,op2)
       local entity = checkEntity(rv1)
       local target = rv2
       local disp = 2
       if( !entity:IsNPC() || disp == 0 ) then return 0 end
       if(entity:Disposition(target)==disp) then return 1 else return 0 end
    
    end)
    Gonna try and test this since I'm pretty sure I screwed up the arguments somehow.

    EDIT[2]: Forgot the return type, lol
    EDIT[3]: E:npcHate(E) works now, the others should, as well.
    Last edited by AphisNano; 02-09-2009 at 03:10 PM.

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

    Default Re: NPC functions - Egate2

    Quote Originally Posted by AphisNano View Post
    Any chance of checking to see if an NPC has a certain type of relationship towards an entity?
    Code:
    if(A:Likes(B)) ...
    EDIT: Got bored, and decided to make a patch implementing this functionality.

    Code:
    // By AphisNano
    //
    // Checks an entity's disposition to see if it likes another entity.
    //
    registerFunction("npcLikes", "e:e", "n", function(self,args)
       local op1, op2 = args[2], args[3]
       local rv1, rv2 = op1[1](self,op1), op2[1](self,op2)
       local entity = checkEntity(rv1)
       local target = rv2
       local disp = 3
       if( !entity:IsNPC() || disp == 0 ) then return 0 end
       return entity:Disposition(target)==disp
    
    end)
    
    // By AphisNano
    //
    // Checks an entity's disposition to see if it hates another entity.
    //
    registerFunction("npcHates", "e:e", "n", function(self,args)
       local op1, op2 = args[2], args[3]
       local rv1, rv2 = op1[1](self,op1), op2[1](self,op2)
       local entity = checkEntity(rv1)
       local target = rv2
       local disp = 1
       if( !entity:IsNPC() || disp == 0 ) then return 0 end
       return entity:Disposition(target)==disp
    
    end)
    
    // By AphisNano
    //
    // Checks an entity's disposition to see if it is neutral towards another entity.
    // (Long name, amazing results [tm])
    //
    registerFunction("npcIsNeutralTowards", "e:e", "n", function(self,args)
       local op1, op2 = args[2], args[3]
       local rv1, rv2 = op1[1](self,op1), op2[1](self,op2)
       local entity = checkEntity(rv1)
       local target = rv2
       local disp = 4
       if( !entity:IsNPC() || disp == 0 ) then return 0 end
       return entity:Disposition(target)==disp
    
    end)
    
    // By AphisNano
    //
    // Checks an entity's disposition to see if it fears another entity.
    //
    registerFunction("npcFears", "e:e", "n", function(self,args)
       local op1, op2 = args[2], args[3]
       local rv1, rv2 = op1[1](self,op1), op2[1](self,op2)
       local entity = checkEntity(rv1)
       local target = rv2
       local disp = 2
       if( !entity:IsNPC() || disp == 0 ) then return 0 end
       return entity:Disposition(target)==disp
    
    end)
    Gonna try and test this since I'm pretty sure I screwed up the arguments somehow.

    EDIT[2]: Forgot the return type, lol
    Okay I didn't add all those because there are a lot, but I did rewrite them into one function:

    Code:
    function DispToString(number)
       if(number == 1) then return "hate" end
       if(number == 2) then return "fear" end
       if(number == 3) then return "like" end
       if(number == 4) then return "neutral" end
       return 0
    end
    
    registerFunction("npcDisp", "e:e", "s", function(self,args)
       local op1, op2 = args[2], args[3]
       local rv1, rv2 = op1[1](self,op1), op2[1](self,op2)
       local entity = checkEntity(rv1)
       local target = checkEntity(rv2)
       local disp = entity:Disposition( target )
       if( !entity:IsNPC() || disp == 0 ) then return "" end
       return DispToString(disp)
    
    end)
    This should return a string of the NPC's disposition. "hate", "fear", etc. I'll test it later, and for now it's added to the files on the first post.

  9. #19
    Wire Amateur AphisNano's Avatar
    Join Date
    Feb 2009
    Location
    Somewhere in WA
    Posts
    51

    Default Re: NPC functions - Egate2

    Quote Originally Posted by Bobsymalone View Post
    Okay I didn't add all those because there are a lot, but I did rewrite them into one function:
    [snip]

    This should return a string of the NPC's disposition. "hate", "fear", etc. I'll test it later, and for now it's added to the files on the first post.
    Okay. I've fixed the functions in my post so they actually work if added as-is. I've tested E:npcHate(E) and E:npcLikes(E) so far, the others are pretty much just copypastes with changed disp values.

  10. #20
    Wire Noob alteron's Avatar
    Join Date
    May 2007
    Posts
    24

    Default Re: NPC functions - Egate2

    This seems pretty cool! Its justa a shame that most servers don't allow npc's...
    This would be cool to turn Npsc's into guards to protect a base...

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