Creating a simple SNPC?

Hello just to have a go at looking how SNPC’s work could someone tell me how to make a SNPC that when you press e on it, it would say something? I don’t want it to know how to shoot or walk just if i go up to it and press e it says something. If anyone can help or guide me in the right direction please do so.

There is a thread like this, every single day. Look around for one, and you’ll find that the answer has been posted several times in each one of them.

[editline]04:18AM[/editline]

If you scroll down, just once, you find this one:

http://www.facepunch.com/showthread.php?t=941995

Just because search function is out of order, doesent mean you cant look for stuff, manually.

Ok i had a go after looking at some things and got to this but i didn’t have any luck does any one want to take a look


function ENT:Use( activator, caller )
 
    self.Entity:Remove()
 
    if ( activator:IsPlayer() ) then
 
            local DermaPanel = vgui.Create( "DFrame" ) -- Creates the frame itself
DermaPanel:SetPos( 50,50 ) -- Position on the players screen
DermaPanel:SetSize( 1000, 900 ) -- Size of the frame
DermaPanel:SetTitle( "Hello My Name Is Melony Melon!" ) -- Title of the frame
DermaPanel:SetVisible( true )
DermaPanel:SetDraggable( true ) -- Draggable by mouse?
DermaPanel:ShowCloseButton( true ) -- Show the close button?
DermaPanel:MakePopup() -- Show the frame

local DermaButton = vgui.Create( "DButton" )
DermaButton:SetParent( DermaPanel ) -- Set parent to our "DermaPanel"
DermaButton:SetText( "Turn on Sv_cheats to 1" )
DermaButton:SetPos( 25, 50 )
DermaButton:SetSize( 150, 50 )
DermaButton.DoClick = function ()
    RunConsoleCommand( "sv_cheats 1" ) -- What happens when you press the button
end

local DermaButton = vgui.Create( "DButton" )
DermaButton:SetParent( DermaPanel ) -- Set parent to our "DermaPanel"
DermaButton:SetText( "Turn on god mode (press sv_cheats 1 button first" )
DermaButton:SetPos( 50, 50 )
DermaButton:SetSize( 150, 50 )
DermaButton.DoClick = function ()
    RunConsoleCommand( "god" ) -- What happens when you press the button
end

local DermaButton = vgui.Create( "DButton" )
DermaButton:SetParent( DermaPanel ) -- Set parent to our "DermaPanel"
DermaButton:SetText( "Kills yourself maybe don't press it!!" )
DermaButton:SetPos( 50, 75 )
DermaButton:SetSize( 150, 50 )
DermaButton.DoClick = function ()
    RunConsoleCommand( "kill" ) -- What happens when you press the button
 
    end
 
end

I don’t think it is a 100 percent right. And also would i put it in the init.lua or in cl_init.lua

[editline]02:16PM[/editline]

I got it the first time you don’t need to tell me twice

Anyone? i think it is long enough to bump by now

I posted a reply to a thread like this…hang on let me get it

Original Post:

Well, it is pretty simple in theory. You have to create an entity using the model of the NPC you want. Then you create a command that opens a derma panel, and run this function when ‘use’ is pressed on that entity.

In order to do this you make a directory with the entity’s name you want to make. then create 3 lua files inside, cl_init, shared, and init. In init you have to initialize your entity with
[lua]function ENT:Initialize( )
self.Entity:SetModel( “” )
self.Entity:SetHullType( HULL_HUMAN )
self.Entity:SetUseType( SIMPLE_USE )
self.Entity:SetHullSizeNormal( )
self.Entity:SetSolid( SOLID_BBOX )
self.Entity:CapabilitiesAdd( CAP_MOVE_GROUND | CAP_OPEN_DOORS | CAP_ANIMATEDFACE | CAP_USE_SHOT_REGULATOR | CAP_TURN_HEAD | CAP_AIM_GUN )
self.Entity:SetMaxYawSpeed( 5000 )
local PhysAwake = self.Entity.Entity:GetPhysicsObject( )
if PhysAwake:IsValid( ) then
PhysAwake:Wake( )
end
end[/lua]

Then with

[lua]function ENT:AcceptInput( name, activator, caller )[/lua]

you put the command that it will run when you press ‘use’
then you create a command.

In cl_init you write the function to create the Derma panels you want to appear when you press ‘use’
heres a good tutorial on how to use the basic components of derma panels

then create a console command for this function ex:

[lua]concommand.Add(“nameofcommand”,nameoffunction)[/lua]

then finally in shared you do this to set information about the entity

[lua]ENT.Base = “base_ai”
ENT.Type = “ai”
ENT.PrintName = “”
ENT.Author = “”
ENT.Contact = “”
ENT.Purpose = “t”
ENT.Instructions = “”
ENT.AutomaticFrameAdvance = true – i’m honestly not sure what this does, but just include it. You could look it up on the wiki if you want to find out.

function ENT:SetAutomaticFrameAdvance( bUsingAnim )
self.AutomaticFrameAdvance = bUsingAnim
end[/lua]

Usermessages usermessages usermessages

Put usermessages in then if it bothers you so much.

It doesn’t bother me at all, you can do what you like. I’m just saying that you should use console commands for server->client networking, that is what they are for.

I’m just using it how I know it best, but just add usermessages if you think it would make it more efficient.

mil0001, You have to wait a couple of days before bumping, I think.

Also; Derma is clientside.

We know derma is clientside, I even told him to put the derma code in cl_init.lua in my rally long explanation of creating an SNPC

Was referring to This

He put the Derma code into the serversided function.

Ah okay, sorry for mis-reading :smiley:

But yea, I probably didnt need to mention it, as you had your detailed post up there.

It doesn’t matter, best to tell the guy again and again as to pound it into his brain

Nah I do it with you and it dont seem to work so I dont expect it to on anyone else

Oh…you’re back…hmm…

walks away

I never left

You were banned

For a few hours