Problems creating an NPC

So, first off I’d like to say that I have no experience with LUA scripting. I do however have some experience with Pawn, which is used in San Andreas Multi-Player, and it highly resembles the c syntax.

I’ve been looking around the internet trying to find out how to make npc’s (NPC shops in particular, where the NPC does not move and allows you to press the use key on him to enter a vgui. I’ve barely found anything on it, and I only found one. This one, however, is 4 years old and probably unreliable. Although old, I decided to try it out considering there weren’t any more tutorials on it. After doing it, I got a ton of errors and managed to fix a few of them, but I am still receiving errors and have no idea if the npc will even work.

This is there error I am getting (I am getting it twice:



[ERROR] gamemodes/carp/gamemode/shared.lua:12: attempt to index global 'ENT' (a nil value)
  1. unknown - gamemodes/carp/gamemode/shared.lua:12
   2. include - [C]:-1
    3. unknown - gamemodes/carp/gamemode/cl_init.lua:1


This is what I got so far:

shared.lua
[lua]
GM.Name = “Cooperative Association Role-Play”
GM.Author = “Steven”
GM.Email = “N/A”
GM.Website = “N/A”

function GM.Initialize()

end

– NPC information

ENT.Base = “base_ai” – Entity is based on “base_ai”
ENT.Type = “ai” – What type of entity it is, in this case it is an AI
ENT.AutomaticFrameAdvance = true – This entity will animate itself

function ENT:SetAutomaticFrameAdvance( bUsingAnim ) – This is called by the game to tell the entity if it should animate itself
self.AutomaticFrameAdvance = bUsingAnim
end
[/lua]

init.lua

[lua]
AddCSLuaFile( “cl_init.lua” )
AddCSLuaFile( “shared.lua” )
include ( “shared.lua” )

– NPC stuff

function ENT:Initialize( ) – This function is run when the entity is created so it’s a good place to setup our entity

self:SetModel( "models/humans/group01/male_01.mdl" ) -- Sets the model for the NPC
self:SetHullType( HULL_HUMAN ) -- Sets the hull type, used for movement calculations amongst other things
self:SetHullSizeNormal( )
self:SetNPCState( NPC_STATE_SCRIPT )
self:SetSolid( SOLID_BBOX ) -- This entity uses a solid bounding box for collisions.
self:CapabilitiesAdd( CAP_TURN_HEAD ) -- Adds what the NPC is allowed to do ( It cannot move in this case ).
self:SetUseType( SIMPLE_USE ) -- Makes the ENT.Use hook only get called once at every use.
self:SetPos(-7880.031250, -7736.325684, 72.031250)
self:DropToFloor()

self:SetMaxYawSpeed( 90 ) --Sets the angle by which an NPC can rotate at once.

end

function ENT:AcceptInput( Name, Activator, Caller )
if Name == “Use” and Caller:IsPlayer() then
end
end
[/lua]

cl_init

[lua]
include( “shared.lua” )
local function drugMenu()
– Derma stuff
end

hook.Add(“ShopNPCUsed”, “DrugMenu”, drugMenu) – Hook the menu, so we can use it serverside

local function GetPlayerPos(ply)
MsgN( ply:GetPos() )
end

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

Before you respond, please don’t post saying to google it. I already searched but cannot find it, hence forth why I am searching it here on the forums. As you can see, I am trying to make a Drug Dealer NPC. The coordinates in SetPos are for the map rp_evocity_v4b1, and I got it using the GetPlayerPos console command in cl_init.lua

I can’t seem to find anything on up-to-date Garry’s Mod 13 lua coding.

Thanks if you can help,
Stevolas

EDIT: Obviously these are probably outdated, so if anyone could post how to correctly make NPC’s, that would be great and highly appreciative.

Why do you have ENT stuff in your shared.lua?

[editline]13th July 2014[/editline]

And init.lua. What are you doing?

God, please read before you post. I linked to the NPC shop tutorial (http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index7853.html) and it says to put that stuff there. Like I said, I am new to lua. Please don’t post unless you read my thread, because I’d like to fix this and not have to explain things that are related to the tutorial.

EDIT: By the way, before you ask, the link was on the word “one”.

Maybe you should take your own advice. It says to put that stuff in the shared.lua and init.lua of the ENTITY, not the gamemode.