Problem with NPC

Hello, I have made an NPC, based off of a base: http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index7853.html

Now, I have made my derma menu, inside cl_init.lua:



include("shared.lua")

local function myMenu()

local DLabel1
local DButton3
local DButton2
local DButton1
local DFrame1

DFrame1 = vgui.Create('DFrame')
DFrame1:SetSize(300, 139)
DFrame1:Center()
DFrame1:SetTitle('Police Station Armory')
DFrame1:SetSizable(true)
DFrame1:SetDeleteOnClose(false)
DFrame1:MakePopup()

DButton1 = vgui.Create('DButton')
DButton1:SetParent(DFrame1)
DButton1:SetSize(90, 20)
DButton1:SetPos(7, 106)
DButton1:SetText('Request Armor')
DButton1.DoClick = function armor1( ply )
end

DButton2 = vgui.Create('DButton')
DButton2:SetParent(DFrame1)
DButton2:SetSize(90, 20)
DButton2:SetPos(107, 106)
DButton2:SetText('Request M4A1')
DButton2.DoClick = function rifle1( ply )
end

DButton3 = vgui.Create('DButton')
DButton3:SetParent(DFrame1)
DButton3:SetSize(90, 20)
DButton3:SetPos(207, 106)
DButton3:SetText('Request Shotgun')
DButton3.DoClick = function shotgun1( ply )
end

DLabel1 = vgui.Create('DLabel')
DLabel1:SetParent(DFrame1)
DLabel1:SetPos(10, 39)
DLabel1:SetText('Hello, how may I help you?')
DLabel1:SizeToContents()
DLabel1:SetTextColor(Color(255, 0, 0, 255))

end
 
usermessage.Hook("ShopNPCUsed",myMenu)

usermessage.Hook("armorcheck",armor1) 

usermessage.Hook("riflecheck",rifle1) 

usermessage.Hook("shotguncheck",Shotgun1) 

Now what I am trying to do is make an NPC, (this) which is spawned inside the police station and has a menu that has 3 buttons, “Request Armor”, “Request M4A1” and “Request Shotgun”.

I understand that I will have to use usermessage as the check “ply:IsCP()” has to be done server side, but I am not sure what I have done wrong…

Here is my init.lua of the entity:


AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")

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/player/combine_soldier.mdl" ) -- Sets the model of 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: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
		umsg.Start("ShopNPCUsed", Caller) -- Prepare the usermessage to that same player to open the menu on his side.
		umsg.End() -- We don't need any content in the usermessage so we're sending it empty now.
	end
end

function armorcheck( ply )

	if ply:IsCP() then
		if (ply:CanAfford(200) == true) then
		ply:SetArmor( 100 )
		ply:AddMoney(-200)
		umsg.Start("armorcheck", ply) -- Prepare the usermessage to that same player to open the menu on his side.
		umsg.End() -- We don't need any content in the usermessage so we're sending it empty now.

		end
	end
end

function riflecheck( ply )

	if ply:IsCP() then
		if (ply:CanAfford(500) == true) and (ply:HasWeapon(weapon_mad_m4) ~= true) then
		ply:Give("weapon_mad_m4")
		umsg.Start("riflecheck", ply) -- Prepare the usermessage to that same player to open the menu on his side.
		umsg.End() -- We don't need any content in the usermessage so we're sending it empty now.
		end
	end

end

function shotguncheck( ply )

	if ply:IsCP() then
		if (ply:CanAfford(500) == true) and (ply:HasWeapon(weapon_mad_m3) ~= true) then
		ply:Give("weapon_mad_m3")
		umsg.Start("shotguncheck", ply) -- Prepare the usermessage to that same player to open the menu on his side.
		umsg.End() -- We don't need any content in the usermessage so we're sending it empty now.
		end
	end

end



The error I get is: https://dl.dropboxusercontent.com/u/88717145/error2.PNG

If I am doing something wrong, please help. I have no idea what to do to fix it.

Thanks

I don’t believe you are allowed to create a function for [lua] DButton1.DoClick = function armor1( ply )
end[/lua] it has to be [lua] DButton1.DoClick = function() end[/lua] or [lua]DButton1.DoClick = armor1()[/lua]
The same for the other DoClicks.

How then do I make it run a check to see if

is true when a button is pressed, followed by the other checks?