Well, I try to interact with my shop NPC, and I do not know why it isn't working. Here is the code (cl_init.lua):
[code]
include('shared.lua') -- At this point the contents of shared.lua are ran on the client only.
function menu1()
local DLabel3
local DLabel2
local DButton5
local DButton6
local DFrame2
DFrame2 = vgui.Create('DFrame')
DFrame2:SetSize(445, 267)
DFrame2:Center()
DFrame2:SetTitle('John's Jobs')
DFrame2:SetDeleteOnClose(false)
DFrame2:ShowCloseButton(false)
DFrame2:MakePopup()
DButton6 = vgui.Create('DButton')
DButton6:SetParent(DFrame2)
DButton6:SetSize(225, 50)
DButton6:SetPos(107, 68)
DButton6:SetText('Yes, I am.')
DButton6.DoClick = function() menu2()
DButton5 = vgui.Create('DButton')
DButton5:SetParent(DFrame2)
DButton5:SetSize(223, 50)
DButton5:SetPos(107, 153)
DButton5:SetText('No, I really do not know why I am here.')
DButton5.DoClick = function() end
DLabel2 = vgui.Create('DLabel')
DLabel2:SetParent(DFrame2)
DLabel2:SetPos(62, 28)
DLabel2:SetText('Hey there! My name is John, and I own this fine establishment. ')
DLabel2:SizeToContents()
DLabel3 = vgui.Create('DLabel')
DLabel3:SetParent(DFrame2)
DLabel3:SetPos(62, 43)
DLabel3:SetText('Can I interest you in a job?')
DLabel3:SizeToContents()
end
usermessage.Hook("ShopNPCUsed", NPCShopMenu) --Hook to messages from the server so we know when to display the menu.
function menu2()
local DLabel4
local DLabel5
local DButton8
local DButton7
local DFrame3
DFrame3 = vgui.Create('DFrame')
DFrame3:SetSize(445, 267)
DFrame3:Center()
DFrame3:SetTitle('John's Jobs')
DFrame3:SetDeleteOnClose(false)
DFrame3:ShowCloseButton(false)
DFrame3:MakePopup()
DButton7 = vgui.Create('DButton')
DButton7:SetParent(DFrame3)
DButton7:SetSize(225, 50)
DButton7:SetPos(107, 68)
DButton7:SetText('Yeah. Sure.')
DButton7.DoClick = function() DFrame3()
DButton8 = vgui.Create('DButton')
DButton8:SetParent(DFrame3)
DButton8:SetSize(223, 50)
DButton8:SetPos(107, 153)
DButton8:SetText('No, take me away from here.')
DButton8.DoClick = function() end
DLabel5 = vgui.Create('DLabel')
DLabel5:SetParent(DFrame3)
DLabel5:SetPos(62, 28)
DLabel5:SetText('Well I am glad you are so enthusiastic.')
DLabel5:SizeToContents()
DLabel4 = vgui.Create('DLabel')
DLabel4:SetParent(DFrame3)
DLabel4:SetPos(62, 43)
DLabel4:SetText('Would you like to see our selection of jobs?')
DLabel4:SizeToContents()
end
[/code]
Basically, you are sort of talking to an NPC here, and for eeverything he says, there is a yes or no button. Clicking the yes button will make him say something else, and clicking the no button will close the VGUI. I am not sure why when I try to interact with the NPC nothing shows up. Any ideas?
Where are you calling it?
[editline]09:03PM[/editline]
/ how?
[QUOTE=Busymonkey;23851869]Where are you calling it?
[editline]09:03PM[/editline]
/ how?[/QUOTE]
What do you mean? I am using the shop_npc_example from Garrysmod.org and the gmod wiki, and I just used Derma Designer to create my panels.
Where/How are you telling the NPC to open it, when someone "Use's" it?
In the init.lua file there is this:
[code]
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
[/code]
I am pretty sure this is what is doing it.
[QUOTE=Wiki]Note : This tutorial assumes you know how to create a scripted entity and only covers the parts that are required to make a working shop NPC.[/QUOTE]
[editline]09:11PM[/editline]
Mah automerge D:
Anyways, you have to make the entity, having more functions than just the ones shown in the tutorial.
[QUOTE=Busymonkey;23852024][editline]09:11PM[/editline]
Mah automerge D:
Anyways, you have to make the entity, having more functions than just the ones shown in the tutorial.[/QUOTE]
I did not use the Tutorial, I downloaded the NPC from Garrys Mod.org and tested it and it worked, but when I added my own menu and deleted the old one, nothing happened.
This is from my entity
cl_init
[code]include('shared.lua')
ENT.RenderGroup = RENDERGROUP_BOTH
function ENT:Draw()
self.Entity:DrawModel()
end
function ENT:DrawTranslucent()
end
function ENT:BuildBonePositions( NumBones, NumPhysBones )
end
function ENT:SetRagdollBones( bIn )
end
function ENT:DoRagdollBone( PhysBoneNum, BoneNum )
end
--Derma Stuff[/code]
init.lua
[code]AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include('shared.lua')
function ENT:Initialize()
self:SetModel( "models/barney.mdl" )
self:SetHullType( HULL_HUMAN );
self:SetHullSizeNormal();
self:SetSolid( SOLID_BBOX )
self:SetMoveType( MOVETYPE_STEP )
self:CapabilitiesAdd( CAP_ANIMATEDFACE | CAP_TURN_HEAD )
self:SetMaxYawSpeed( 5000 )
self:SetHealth(99999)
end
function ENT:AcceptInput( input, activator, caller )
if not timerforbox then
timerforbox = true timer.Simple(1, function() timerforbox = false end)
if input == "Use" and activator:IsPlayer() and then
umsg.Start("stuff_lol", activator)
umsg.End()
end
end
end
[/code]
shared.lua
[code]ENT.Base = "base_ai"
ENT.Type = "ai"
ENT.PrintName = ""
ENT.Author = ""
ENT.Contact = ""
ENT.Purpose = ""
ENT.Instructions = ""
ENT.AutomaticFrameAdvance = true
function ENT:OnRemove()
end
function ENT:PhysicsCollide( data, physobj )
end
function ENT:PhysicsUpdate( physobj )
end
function ENT:SetAutomaticFrameAdvance( bUsingAnim )
self.AutomaticFrameAdvance = bUsingAnim
end
[/code]
There you go; Structure of an NPC shop.
[editline]09:18PM[/editline]
:ninja: Well, it never worked from me, that NPC Shop you could download.
Try using what I gave you.
[editline]09:19PM[/editline]
Also, for future reference, please dont create another thread, asking about the same subject, but different problem; simply "Edit" the OP or ask the question in the same thread.
Would this work? Or do I not need to start off the Derma Stuff with a function?
cl_init.lua:
[code]
include('shared.lua')
ENT.RenderGroup = RENDERGROUP_BOTH
function ENT:Draw()
self.Entity:DrawModel()
end
function ENT:DrawTranslucent()
end
function ENT:BuildBonePositions( NumBones, NumPhysBones )
end
function ENT:SetRagdollBones( bIn )
end
function ENT:DoRagdollBone( PhysBoneNum, BoneNum )
end
--Derma Stuff
function NPCShopMenu()
local DLabel3
local DLabel2
local DButton5
local DButton6
local DFrame2
DFrame2 = vgui.Create('DFrame')
DFrame2:SetSize(445, 267)
DFrame2:Center()
DFrame2:SetTitle('John's Jobs')
DFrame2:SetDeleteOnClose(false)
DFrame2:ShowCloseButton(false)
DFrame2:MakePopup()
DButton6 = vgui.Create('DButton')
DButton6:SetParent(DFrame2)
DButton6:SetSize(225, 50)
DButton6:SetPos(107, 68)
DButton6:SetText('Yes, I am.')
DButton6.DoClick = function() menu2()
DButton5 = vgui.Create('DButton')
DButton5:SetParent(DFrame2)
DButton5:SetSize(223, 50)
DButton5:SetPos(107, 153)
DButton5:SetText('No, I really do not know why I am here.')
DButton5.DoClick = function() end
DLabel2 = vgui.Create('DLabel')
DLabel2:SetParent(DFrame2)
DLabel2:SetPos(62, 28)
DLabel2:SetText('Hey there! My name is John, and I own this fine establishment. ')
DLabel2:SizeToContents()
DLabel3 = vgui.Create('DLabel')
DLabel3:SetParent(DFrame2)
DLabel3:SetPos(62, 43)
DLabel3:SetText('Can I interest you in a job?')
DLabel3:SizeToContents()
end
hook.Add("ShopNPCUsed", NPCShopMenu) --Hook to messages from the server so we know when to display the menu.
function menu2()
local DLabel4
local DLabel5
local DButton8
local DButton7
local DFrame3
DFrame3 = vgui.Create('DFrame')
DFrame3:SetSize(445, 267)
DFrame3:Center()
DFrame3:SetTitle('John's Jobs')
DFrame3:SetDeleteOnClose(false)
DFrame3:ShowCloseButton(false)
DFrame3:MakePopup()
DButton7 = vgui.Create('DButton')
DButton7:SetParent(DFrame3)
DButton7:SetSize(225, 50)
DButton7:SetPos(107, 68)
DButton7:SetText('Yeah. Sure.')
DButton7.DoClick = function() DFrame3()
DButton8 = vgui.Create('DButton')
DButton8:SetParent(DFrame3)
DButton8:SetSize(223, 50)
DButton8:SetPos(107, 153)
DButton8:SetText('No, take me away from here.')
DButton8.DoClick = function() end
DLabel5 = vgui.Create('DLabel')
DLabel5:SetParent(DFrame3)
DLabel5:SetPos(62, 28)
DLabel5:SetText('Well I am glad you are so enthusiastic.')
DLabel5:SizeToContents()
DLabel4 = vgui.Create('DLabel')
DLabel4:SetParent(DFrame3)
DLabel4:SetPos(62, 43)
DLabel4:SetText('Would you like to see our selection of jobs?')
DLabel4:SizeToContents()
end
[/code]
I am sorta iffy on the hook.Add("ShopNPCUsed", NPCShopMenu).
Use this instead of the hook
[lua]
usermessage.Hook("ShopNPCUsed", NPCShopMenu)
[/lua]
Alright, thanks man, but should I add it after the second derma menu, too (which is just a chain reaction of the first panel)?
[QUOTE=BrightLiteFilms;23877446]Alright, thanks man, but should I add it after the second derma menu, too (which is just a chain reaction of the first panel)?[/QUOTE]
Yes i do believe so.
But won't that make it so that it appears when you use the NPC, not after you click a button on the first menu?
[QUOTE=BrightLiteFilms;23877741]But won't that make it so that it appears when you use the NPC, not after you click a button on the first menu?[/QUOTE]
Oh okay i see what your talking about know. Yes your correct. Leave it in the same location
Sorry, you need to Log In to post a reply to this thread.