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
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
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:
or for the entire _R table:Code:lua_run file.Write("global/_R4.txt",table.ToString(_R[4],"_R[4]",true))
or for the WHOLE _G table, it includes _R:Code:lua_run file.Write("global/_R.txt",table.ToString(_R,"_R",true))
It will dump to a garrysmod/garrysmod/data/global/ folder, you can change that if you want to.Code:lua_run file.Write("global/_G.txt",table.ToString(_G,"_G",true))
Against stupidity the Gods themselves contend in vain.
-Friedrich Schiller
The flame puts me in the mood to "Do it!".
-Dart, Legend of Dragoon
Updated with relationship functions and E:npcGiveWeapon(S)
Any chance of checking to see if an NPC has a certain type of relationship towards an entity?
EDIT: Got bored, and decided to make a patch implementing this functionality.Code:if(A:Likes(B)) ...
Gonna try and test this since I'm pretty sure I screwed up the arguments somehow.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)
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.
Okay I didn't add all those because there are a lot, but I did rewrite them into one function:
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.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 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...
Bookmarks