So, people have been helping with derma, now i want to move into the more advance level.
How can i add a text box, wich a user enters an rp name, then a button that runs the command and inputs the name a user entered.
An example would be nice ;)
First, you'll make the frame.
Second, you'll set up the DTextEntry.
Finally, you'll set up the button.
[CODE]
local frame = vgui.Create("DFrame")
frame:SetSize(200,100)
frame:SetTitle("Change your RPName")
frame:Center()
local TextEntry = vgui.Create("DTextEntry")
TextEntry:AlignTop(0)
TextEntry:Dock(FILL)
local Button = vgui.Create("DButton")
Button:SetText("Change RPName")
Button:SetImage("icon16/accept.png")
Button:AlignBottom(0)
Button:Dock(FILL)
Button.DoClick = function()
RunConsoleCommand("say","/rpname " .. TextEntry:GetValue())
end
[/CODE]
This [I]should[/I] (untested) change their RPName.
The button makes them run the console command say (which makes the player chat) /rpname <TextEntry Value>
The docking and aligns may not be perfect.
[code] local frame = vgui.Create( "DFrame" )
frame:SetSize( 750, 900 )
frame:Center()
frame:MakePopup()
local sheet = vgui.Create( "DPropertySheet", frame )
sheet:Dock( FILL )
local panel1 = vgui.Create( "DPanel", sheet )
panel1.Paint = function( self, w, h ) draw.RoundedBox( 4, 0, 0, w, h, Color( 0, 128, 255, 0 ) ) end
sheet:AddSheet( "Character", panel1, "icon16/user.png" )
local panel2 = vgui.Create( "DPanel", sheet )
panel2.Paint = function( self, w, h ) draw.RoundedBox( 4, 0, 0, w, h, Color( 255, 128, 0 ) ) end
sheet:AddSheet( "test 2", panel2, "icon16/tick.png" )
hook.Add( "PlayerBindPress", "F4", function(client, bind, pressed)
bind = bind:lower()
print("binding")
if (bind:find("gm_showhelp") and pressed) then
elseif (bind:find("gm_showspare1") and pressed) then
elseif (bind:find("gm_showspare2") and pressed) then
CreatePanel()
end
end)
[/code] Dont work, as in the F4 button does not open it :?
[QUOTE=Borris_Squad;48582708][code] local frame = vgui.Create( "DFrame" )
frame:SetSize( 750, 900 )
frame:Center()
frame:MakePopup()
local sheet = vgui.Create( "DPropertySheet", frame )
sheet:Dock( FILL )
local panel1 = vgui.Create( "DPanel", sheet )
panel1.Paint = function( self, w, h ) draw.RoundedBox( 4, 0, 0, w, h, Color( 0, 128, 255, 0 ) ) end
sheet:AddSheet( "Character", panel1, "icon16/user.png" )
local panel2 = vgui.Create( "DPanel", sheet )
panel2.Paint = function( self, w, h ) draw.RoundedBox( 4, 0, 0, w, h, Color( 255, 128, 0 ) ) end
sheet:AddSheet( "test 2", panel2, "icon16/tick.png" )
hook.Add( "PlayerBindPress", "F4", function(client, bind, pressed)
bind = bind:lower()
print("binding")
if (bind:find("gm_showhelp") and pressed) then
elseif (bind:find("gm_showspare1") and pressed) then
elseif (bind:find("gm_showspare2") and pressed) then
CreatePanel()
end
end)
[/code] Dont work, as in the F4 button does not open it :?[/QUOTE]
PlayerBindPress doesn't work like that.
Use [URL="http://wiki.garrysmod.com/page/GM/ShowSpare2"]this[/URL] hook instead. It's serverside so you will need to do some networking.
[QUOTE=YaYaBinks3;48582746]PlayerBindPress doesn't work like that.
Use [URL="http://wiki.garrysmod.com/page/GM/ShowSpare2"]this[/URL] hook instead. It's serverside so you will need to do some networking.[/QUOTE]
It worked a few mins ago before i started adding tabs though?
[QUOTE=Borris_Squad;48582764]It worked a few mins ago before i started adding tabs though?[/QUOTE]
Then your problem is the tabs!
Try removing those Paints and see if the tabs show up.
Yea, see this was my old code [code] local function CreatePanel()
local Utility = vgui.Create ( "DFrame" )
Utility:SetPos( 5, 5 )
Utility:SetSize( 700, 900 )
Utility:SetTitle( "CivilisationRP Utility Menu" )
Utility:SetVisible( "true" )
Utility:SetDraggable( "true" )
Utility:ShowCloseButton( "true" )
Utility:MakePopup()
Utility:Center()
local Btn = vgui.Create ( "DButton", Utility )
Btn:SetText( "Click to connect 4Late Jailbreak." )
Btn:SetTextColor( Color( 0, 0, 0, 255) )
Btn:SetPos( 25, 50 )
Btn:SetSize( 60, 15 )
Btn.DoClick = function()
RunConsoleCommand("connect", "193.0.159.39:27490")
Utility:Remove()
end
end
hook.Add( "PlayerBindPress", "F4", function(client, bind, pressed)
bind = bind:lower()
print("binding")
if (bind:find("gm_showhelp") and pressed) then
elseif (bind:find("gm_showspare1") and pressed) then
elseif (bind:find("gm_showspare2") and pressed) then
CreatePanel()
end
end)
[/code] and my new code
[code] local frame = vgui.Create( "DFrame" )
frame:SetPos( 5, 5 )
frame:SetSize( 750, 900 )
frame:Center()
frame:MakePopup()
frame:SetTitle( "CivilisationRP Main Menu" )
frame:SetDraggable("true")
frame:ShowCloseButton("true")
local sheet = vgui.Create( "DPropertySheet", frame )
sheet:Dock( FILL )
local panel1 = vgui.Create( "DPanel", sheet )
panel1.Paint = function( self, w, h ) draw.RoundedBox( 4, 0, 0, w, h, Color( 0, 128, 255, 0 ) ) end
sheet:AddSheet( "Character", panel1, "icon16/user.png" )
local TextEntry = vgui.Create("DTextEntry")
TextEntry:Center()
TextEntry:SetPos( 5, 5 )
TextEntry:SetSize( 700, 20 )
local Button = vgui.Create("DButton")
Button:SetText("Change RPName")
Button:SetImage("icon16/accept.png")
Button:SetSize( 20, 20)
Button:SetPos(25, 15 )
Button.DoClick = function()
RunConsoleCommand("say","/rpname " .. TextEntry:GetValue())
end
local panel2 = vgui.Create( "DPanel", sheet )
panel2.Paint = function( self, w, h ) draw.RoundedBox( 4, 0, 0, w, h, Color( 255, 128, 0 ) ) end
sheet:AddSheet( "test 2", panel2, "icon16/tick.png" )
hook.Add( "PlayerBindPress", "F4", function(client, bind, pressed)
bind = bind:lower()
print("binding")
if (bind:find("gm_showhelp") and pressed) then
elseif (bind:find("gm_showspare1") and pressed) then
elseif (bind:find("gm_showspare2") and pressed) then
CreatePanel()
end
end)
[/code]
Wich is an utter mess and im gonna need help if im to ever get this finished dont work
[editline]31st August 2015[/editline]
Now i get this error [code]
[ERROR] addons/updates/lua/autorun/client/cl_updates.lua:37: attempt to call global 'CreatePanel' (a nil value)
1. fn - addons/updates/lua/autorun/client/cl_updates.lua:37
2. unknown - addons/ulib/lua/ulib/shared/hook.lua:179
[/code] Im still new to this so you know :P
You're getting that error because you removed the CreatePanel function.
I'd say recode it with help from [URL="http://wiki.garrysmod.com/page/Category:DPropertySheet"]here[/URL].
Hang on i think i just fixed it
[editline]31st August 2015[/editline]
Nope i added the CreatePanel function and restarted but did not work.
Ehh im so bad at this :\ urmm, so i restarted using that exact code. Now i have removed the blue paint because it looks awful. Now i want to make it so F4 (F1 Mainly to open it).
[editline]31st August 2015[/editline]
[code] local function CreatePanel()
local frame = vgui.Create( "DFrame" )
frame:SetSize( 666, 800 )
frame:Center()
frame:MakePopup()
frame:SetTitle(" CivilisationRP Main Menu")
local sheet = vgui.Create( "DPropertySheet", frame )
sheet:Dock( FILL )
local panel1 = vgui.Create( "DPanel", sheet )
panel1.Paint = function( self, w, h ) end
sheet:AddSheet( "Character", panel1, "icon16/user.png" )
local panel2 = vgui.Create( "DPanel", sheet )
panel2.Paint = function( self, w, h ) end
sheet:AddSheet( "Inventory", panel2, "icon16/box.png" )
hook.Add( "PlayerBindPress", "F4", function(client, bind, pressed)
bind = bind:lower()
print("binding")
if (bind:find("gm_showhelp") and pressed) then
elseif (bind:find("gm_showspare1") and pressed) then
elseif (bind:find("gm_showspare2") and pressed) then
CreatePanel()
end
end)
[/code] This does not work either.
You did not add an end for the function.
Explain, how do i end it? Please understand this is my second ever language learnt.
[CODE]end[/CODE]
[QUOTE=YaYaBinks3;48583314][CODE]end[/CODE][/QUOTE]
I know that but where do i put it xD
Sorry, you need to Log In to post a reply to this thread.