Ive been playing around with Vgui elements ect and i'm having trouble getting my vgui stuff to appear when i want it to. For example, When i put in a chat command(!amb), i want it to appear but im having trouble setting this part up.
[CODE]
local shouldpopup = false
local ply = LocalPlayer()
local makeVguipopup = false
--Look at chat
local function OpenAmbThing (ply, text, team )
if (string.sub( text, 1, 8 ) =="!amb" ) then
local makeVguipopup = true
print("worked")
end
end
if makeVguipopup == true then
---Main Derma pannel
local adminHelp = vgui.Create( "DFrame" )
adminHelp:Center()
adminHelp:SetSize( 600, 100 )
adminHelp:SetTitle( "Ambient admin help v0.1" )
adminHelp:SetDraggable( true )
adminHelp:MakePopup()
--command combo box
local commandBox = vgui.Create( "DComboBox", adminHelp )
commandBox:SetPos( 20, 50 )
commandBox:SetSize( 80, 20 )
commandBox:AddChoice( "kick" )
commandBox:AddChoice( "Ban" )
commandBox:AddChoice( "Gag" )
commandBox:AddChoice( "jail" )
--Time scale combobox
local TimeScaleAmb = vgui.Create( "DComboBox", adminHelp )
TimeScaleAmb:SetPos( 220, 50 )
TimeScaleAmb:SetSize( 80, 20 )
TimeScaleAmb:AddChoice("minutes")
TimeScaleAmb:AddChoice( "hours" )
TimeScaleAmb:AddChoice( "weeks" )
TimeScaleAmb:AddChoice( "years" )
TimeScaleAmb:AddChoice( "perma" )
--player Combo Box
local PlayerBox = vgui.Create( "DComboBox", adminHelp )
PlayerBox:SetPos(120,50)
PlayerBox:SetSize( 80, 20)
for k,v in pairs(player.GetAll()) do
PlayerBox:AddChoice(v:Nick() )
end
--Time input textEntry
local DermaText = vgui.Create( "DTextEntry", adminHelp )
DermaText:SetPos( 350,50 )
DermaText:SetSize( 200, 20)
DermaText:AllowInput( true )
DermaText.OnEnter = function()
local timescaleamb1 = TimeScaleAmb:GetSelected()
if timescaleamb1 == "hours" then
timescaleambfin = "h"
end
if timescaleamb1 == "weeks" then
timescaleambfin = "w"
end
if timescaleamb1 == "years" then
timescaleambfin = "y"
end
if timescaleamb1 == "perma" then
timescaleambfin = "perma"
end
if timescaleamb1 == "minutes" then
timescaleambfin = "m"
end
ply:ChatPrint( "!"..commandBox:GetSelected().." "..PlayerBox:GetSelected().." "..DermaText:GetValue()..timescaleambfin )
print(isMenuOpenAmb)
Msg("!"..commandBox:GetSelected().." "..PlayerBox:GetSelected().." "..DermaText:GetValue()..timescaleambfin ) -- What happens when you press enter
local thirdselect = DermaText:GetValue()
end
end
hook.Add("playerSay","openAmbPannel",OpenAmbThing)
[/CODE]
Thank you for any help
I see multiple issues with this script.
[code]
if (string.sub( text, 1, 8 ) =="!amb" ) then --hint: 1, 8
[/code]
Simply changing the variable makeVguipopup to true will not open your menu from what it looks like. If that check isn't inside a recurring timer or hook, then that if statement will only be called on script load. Instead I would put your menu inside a function and call it after the open command is typed in chat.
Someone can help you with the rest, I'm on mobile so this isn't easy.
I hope you don't mind but could somebody show me how to set that up and thank you so much
[QUOTE=Ambient_1;52083622]I hope you don't mind but could somebody show me how to set that up and thank you so much[/QUOTE]
I guess I'll continue on my phone anyways.
Edit:
The more I look at this, the more issues arise. In order for this to work how you want it to (efficiently) you'd pretty much have to do a full rewrite.
You seem to be very new to lua in general and I recommend looking into the lua pil or other learning sources.
For my VGUI menu that im currently making; i used a server side hook that looked at when the command was typed in chat. Then sent a network message to the client which then created the DFrame and all elements inside it... i found this substantially easier
[QUOTE=yoloman707;52083765]For my VGUI menu that im currently making; i used a server side hook that looked at when the command was typed in chat. Then sent a network message to the client which then created the DFrame and all elements inside it... i found this substantially easier[/QUOTE]
and more secure
[QUOTE=tgandrew2468;52083680]I guess I'll continue on my phone anyways.
Edit:
The more I look at this, the more issues arise. In order for this to work how you want it to (efficiently) you'd pretty much have to do a full rewrite.
You seem to be very new to lua in general and I recommend looking into the lua pil or other learning sources.[/QUOTE]
Yeah i'm new to gmod lua and wanted to practice some vgui, but ill look into rewriting it, thank you for your help though
[editline]10th April 2017[/editline]
Ok so i did my best job at rewriting it and setting up a function but its seems to not wanna work(the files is lua/autorun/client right now)
[CODE]local ply = LocalPlayer()
local function OpenAmbThing (ply, text, team )
if (string.sub( text ) =="!amb" ) then
openVguiThing()
end
end
local function openVguiThing()
local adminHelp = vgui.Create( "DFrame" )
adminHelp:Center()
adminHelp:SetSize( 600, 100 )
adminHelp:SetTitle( "Ambient admin help v0.1" )
adminHelp:SetDraggable( true )
adminHelp:MakePopup()
local commandBox = vgui.Create( "DComboBox", adminHelp )
commandBox:SetPos( 20, 50 )
commandBox:SetSize( 80, 20 )
commandBox:AddChoice( "kick" )
commandBox:AddChoice( "Ban" )
commandBox:AddChoice( "Gag" )
commandBox:AddChoice( "jail" )
local TimeScaleAmb = vgui.Create( "DComboBox", adminHelp )
TimeScaleAmb:SetPos( 220, 50 )
TimeScaleAmb:SetSize( 80, 20 )
TimeScaleAmb:AddChoice("minutes")
TimeScaleAmb:AddChoice( "hours" )
TimeScaleAmb:AddChoice( "weeks" )
TimeScaleAmb:AddChoice( "years" )
TimeScaleAmb:AddChoice( "perma" )
local PlayerBox = vgui.Create( "DComboBox", adminHelp )
PlayerBox:SetPos(120,50)
PlayerBox:SetSize( 80, 20)
for k,v in pairs(player.GetAll()) do
PlayerBox:AddChoice(v:Nick() )
end
local DermaText = vgui.Create( "DTextEntry", adminHelp )
DermaText:SetPos( 350,50 )
DermaText:SetSize( 200, 20)
DermaText:AllowInput( true )
DermaText.OnEnter = function()
local timescaleamb1 = TimeScaleAmb:GetSelected()
if timescaleamb1 == "hours" then
timescaleambfin = "h"
end
if timescaleamb1 == "weeks" then
timescaleambfin = "w"
end
if timescaleamb1 == "years" then
timescaleambfin = "y"
end
if timescaleamb1 == "perma" then
timescaleambfin = "perma"
end
if timescaleamb1 == "minutes" then
timescaleambfin = "m"
end
local thirdselect = DermaText:GetValue()
ply:ChatPrint( "!"..commandBox:GetSelected().." "..PlayerBox:GetSelected().." "..DermaText:GetValue()..timescaleambfin )
--Msg("!"..commandBox:GetSelected().." "..PlayerBox:GetSelected().." "..DermaText:GetValue()..timescaleambfin ) -- What happens when you press enter
local thirdselect = DermaText:GetValue()
end
end
hook.Add("playerSay","openAmbPannel",OpenAmbThing)[/CODE]
Don't use PlayerSay, use OnPlayerChat. That's clientside and it should work
[editline]11th April 2017[/editline]
[CODE]
hook.Add("OnPlayerChat","openAmbPannel",OpenAmbThing)
[/CODE]
[editline]11th April 2017[/editline]
[QUOTE=yoloman707;52083765]For my VGUI menu that im currently making; i used a server side hook that looked at when the command was typed in chat. Then sent a network message to the client which then created the DFrame and all elements inside it... i found this substantially easier[/QUOTE]
Or just use OnPlayerChat as it was supposed to be used
Thank you so much, its been a massive help and i really appreciate you taking time out of your day to help me
Sorry, you need to Log In to post a reply to this thread.