What is the function to make a basic GUI open when you press E on a entity. What is the function and hook for opening a gui in the cl_init.lua.
include("shared.lua")
function ENT:Initialize ( )
self.AutomaticFrameAdvance = true
end
function ENT:Draw()
self.Entity:DrawModel()
end
function OpenTheSnitchMenu()
local frame = vgui.Create( "DFrame" )
frame:SetPos( 1000, 720 )
frame:SetSize( 500, 250 )
frame:SetTitle( "The Snitch" )
frame:SetDraggable( true )
frame:MakePopup()
frame:Center()
local label = vgui.Create("DLabel" , frame)
label:SetPos(10, 40)
label:SetSize( 500,20)
label:SetText("Hey, I here you're lookin' for some friends of mine.")
local label2 = vgui.Create("DLabel" , frame)
label2:SetPos(10, 80)
label2:SetSize( 500,20)
label2:SetText("The Meth Dealer is in an alley next to the night club")
local label3 = vgui.Create("DLabel" , frame)
label3:SetPos(10, 120)
label3:SetSize( 500,20)
label3:SetText("The Black Market Dealer is behind a wooden door sized wall infront of hospital in the parking lot")
local label4 = vgui.Create("DLabel" , frame)
label4:SetPos(10, 160)
label4:SetSize( 500,20)
label4:SetText("The Drug Dealer is in an alley behind the hospital")
local label4 = vgui.Create("DLabel" , frame)
label4:SetPos(10, 160)
label4:SetSize( 500,20)
label4:SetText("The Drug Dealer is in an alley behind the hospital")
local label5 = vgui.Create("DLabel" , frame)
label5:SetPos(10, 200)
label5:SetSize( 500,20)
label5:SetText("The Chemist is in the radioactive subway go to the subway next to pd and go left when you enter")
usermessage.Hook("npc_snitch_onmenuopen",TheSnitchMenu)
This is what I had so for I put the function above the GUI to make it open and the hook bellow to make it work but it still doesn't work in game.
Start a net message on ent use and receive that message client side with the gui code inside that message.
This is all my entity code.
[B][U]cl_init.lua[/U][/B]
include("shared.lua")
function ENT:Initialize ( )
self.AutomaticFrameAdvance = true
end
function ENT:Draw()
self.Entity:DrawModel()
end
function TheSnitchMenu()
local frame = vgui.Create( "DFrame" )
frame:SetPos( 1000, 720 )
frame:SetSize( 500, 250 )
frame:SetTitle( "The Snitch" )
frame:SetDraggable( true )
frame:MakePopup()
frame:Center()
local label = vgui.Create("DLabel" , frame)
label:SetPos(10, 40)
label:SetSize( 500,20)
label:SetText("Hey, I here you're lookin' for some friends of mine.")
local label2 = vgui.Create("DLabel" , frame)
label2:SetPos(10, 80)
label2:SetSize( 500,20)
label2:SetText("The Meth Dealer is in an alley next to the night club")
local label3 = vgui.Create("DLabel" , frame)
label3:SetPos(10, 120)
label3:SetSize( 500,20)
label3:SetText("The Black Market Dealer is behind a wooden door sized wall infront of hospital in the parking lot")
local label4 = vgui.Create("DLabel" , frame)
label4:SetPos(10, 160)
label4:SetSize( 500,20)
label4:SetText("The Drug Dealer is in an alley behind the hospital")
local label4 = vgui.Create("DLabel" , frame)
label4:SetPos(10, 160)
label4:SetSize( 500,20)
label4:SetText("The Drug Dealer is in an alley behind the hospital")
local label5 = vgui.Create("DLabel" , frame)
label5:SetPos(10, 200)
label5:SetSize( 500,20)
label5:SetText("The Chemist is in the radioactive subway go to the subway next to pd and go left when you enter")
usermessage.Hook("SnitchMenuUsed", TheSnitchMenu)
[B][U]init.lua[/U][/B]
AddCSLuaFile('cl_init.lua')
AddCSLuaFile('shared.lua')
include("shared.lua")
function ENT:Initialize()
self:SetModel( "models/Humans/Group02/Male_01.mdl" )
self:SetHullType( HULL_HUMAN )
self:SetHullSizeNormal( )
self:SetNPCState( NPC_STATE_SCRIPT )
self:SetSolid( SOLID_BBOX )
self:CapabilitiesAdd( CAP_ANIMATEDFACE )
self:SetUseType( SIMPLE_USE )
self:DropToFloorent()
end
function ENT:AcceptInput( Name, Activator, Caller )
if Name == "Use" and Caller:IsPlayer() then
umsg.Start("SnitchMenuUsed", Caller)
umsg.End()
end
end
[B][U]shared.lua[[/U]/B]
ENT.Type = "ai"
ENT.Base = "base_ai"
ENT.PrintName = "Snitch"
ENT.Author = "AngryBaldMan"
ENT.Category = "Toxstyx"
ENT.Spawnable = true
ENT.AdminSpawnable = true
Use a net message...
cl_init.lua
[lua]
include("shared.lua")
function ENT:Initialize ( )
self.AutomaticFrameAdvance = true
end
function ENT:Draw()
self.Entity:DrawModel()
end
[/lua]
init.lua
[lua]
AddCSLuaFile('cl_init.lua')
AddCSLuaFile('shared.lua')
include("shared.lua")
function ENT:Initialize()
self:SetModel( "models/Humans/Group02/Male_01.mdl" )
self:SetHullType( HULL_HUMAN )
self:SetHullSizeNormal( )
self:SetNPCState( NPC_STATE_SCRIPT )
self:SetSolid( SOLID_BBOX )
self:CapabilitiesAdd( CAP_ANIMATEDFACE )
self:SetUseType( SIMPLE_USE )
self:DropToFloorent()
end
function ENT:AcceptInput( Name, Activator, Caller )
if Name == "Use" and Caller:IsPlayer() then
net.Start("opensnitchmenu")
net.Send(Caller)
end
end
[/lua]
shared.lua
[lua]
ENT.Type = "ai"
ENT.Base = "base_ai"
ENT.PrintName = "Snitch"
ENT.Author = "AngryBaldMan"
ENT.Category = "Toxstyx"
ENT.Spawnable = true
ENT.AdminSpawnable = true
[/lua]
make a new file in lua/autorun. name it anything like usecode.lua etc
put this in:
[lua]
if SERVER then
util.AddNetworkString("opensnitchmenu")
else
function TheSnitchMenu()
local frame = vgui.Create( "DFrame" )
frame:SetPos( 1000, 720 )
frame:SetSize( 500, 250 )
frame:SetTitle( "The Snitch" )
frame:SetDraggable( true )
frame:MakePopup()
frame:Center()
local label = vgui.Create("DLabel" , frame)
label:SetPos(10, 40)
label:SetSize( 500,20)
label:SetText("Hey, I here you're lookin' for some friends of mine.")
local label2 = vgui.Create("DLabel" , frame)
label2:SetPos(10, 80)
label2:SetSize( 500,20)
label2:SetText("The Meth Dealer is in an alley next to the night club")
local label3 = vgui.Create("DLabel" , frame)
label3:SetPos(10, 120)
label3:SetSize( 500,20)
label3:SetText("The Black Market Dealer is behind a wooden door sized wall infront of hospital in the parking lot")
local label4 = vgui.Create("DLabel" , frame)
label4:SetPos(10, 160)
label4:SetSize( 500,20)
label4:SetText("The Drug Dealer is in an alley behind the hospital")
local label4 = vgui.Create("DLabel" , frame)
label4:SetPos(10, 160)
label4:SetSize( 500,20)
label4:SetText("The Drug Dealer is in an alley behind the hospital")
local label5 = vgui.Create("DLabel" , frame)
label5:SetPos(10, 200)
label5:SetSize( 500,20)
label5:SetText("The Chemist is in the radioactive subway go to the subway next to pd and go left when you enter")
net.Receive("opensnitchmenu", TheSnitchMenu)
end
[/lua]
So the NPC works but when I press E on it this comes up in console
[IMG]http://i.imgur.com/3VOrScv.png?1[/IMG]
[QUOTE=AngryBaldMan;50289631]So the NPC works but when I press E on it this comes up in console
[IMG]http://i.imgur.com/3VOrScv.png?1[/IMG][/QUOTE]
That error is pretty self explanatory, somewhere you are using a net message with a name you didn't declare with [URL="https://wiki.garrysmod.com/page/Calling_net.Start_with_unpooled_message_name"]util.AddNetworkString[/URL]. I suggest looking at line 22.
[QUOTE=boxvader;50289722]That error is pretty self explanatory, somewhere you are using a net message with a name you didn't declare with [URL="https://wiki.garrysmod.com/page/Calling_net.Start_with_unpooled_message_name"]util.AddNetworkString[/URL]. I suggest looking at line 22.[/QUOTE]
So put util.AddNetworkString( "opensnitchmenu" ) in init.lua
Sorry, you need to Log In to post a reply to this thread.