My computer crashed in the middle of posting this so I lost all my progress, so this is going to be short.
I want to have an NPC on my server that players can walk up to and press their activate/action key (E) and have a derma menu pop up.
I can do the derma myself, but is the function ENT:Use that allows me to hook the derma opening to it?
Other than that, I have no idea where to start. Thanks.
[URL="https://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index7853.html"]https://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index7853.html[/URL]
Replace the Derma from the Shop to your own stuff.
NPC is basically a glorified Entity, in Lua you treat it like a entity. Before you start programming the npc you are going to need to build a folder in which contains your Shared.lua, your init.lua, and your cl_init.lua. The code I am showing you right now is used in the init.lua as it is the server side file it will be generated in the server.
[code]
// how to spawn in a NPC
local function SpawnNPC()
local NPCSPAWN = ents.Create("Folder_name") // file name IE the folder name were you store init, cl_init, and shared for the NPC
NPCSPAWN:SetPos( Vector( X, Y ,Z)) // type getpos in console to obtain the position in which you are currently standing. In other words use this command to find a place on the map to put your NPC.
NPCSPAWN:SetAngles( Angle(A,B,C)) // when you use getpos it gives you two sets of numbers, I believe the bottom three numbers is the angle position. (it has been a while since I programmed NPCS)
NPCSPAWN:Spawn() // spawns the NPC
NPCSPAWN: Activate()
end
hook.Add("InitPostEntity", "SpawnNPC", "SpawnNPC") // hook the entity == (create entity, spawnnpc file, function name)
[/code]
you will also have to initialize your npc, in init which is done here:
[code]
function ENT:Initialize()
// I believe most of these variables can be found on the garrys-mod wiki so I wont explain each one.
self:SetModel( "models/gman_high.mdl" ) // model
self:SetNPCState(NPC_STATE_SCRIPT)
self:CapabilitiesAdd(bit.bor(CAP_ANIMATEDFACE, CAP_TURN_HEAD) )
end
[/code]
This is just a section of the code to initialize the NPC entity, there is a lot that can be done here.
cl_init is used for all your client side affects, for example setting a text box design if a player hits 'e' on the npc the text box will pop up.
Anyways good luck with your NPC build!
If you would like some help I created a thread about this not that long ago : [url]https://facepunch.com/showthread.php?t=1504602[/url]
Sorry, you need to Log In to post a reply to this thread.