The Ultimate Guide to Derma - Everything there is to know about Derma
217 replies, posted
how do you load the derma screen. i saved the lua file in my lua folder. i went to my console and typed lua_openscript derma.lua but in won't work
[QUOTE=PC Camp]
When using
[lua]for k, v in pairs(player.GetAll()) do[/lua]
your cycling through all the players to see if they have that key down.[/QUOTE]
Can you not see what is wrong with what you are doing there?
[b]Edit:[/b]
[QUOTE=gamerfan987]how do you load the derma screen. i saved the lua file in my lua folder. i went to my console and typed lua_openscript derma.lua but in won't work[/QUOTE]
Derma is clientside so use lua_openscript_cl
[QUOTE=Ben Build]wouldn't
hook.Add("OnSpawnMenuOpen", "OpenMyPanel", CreatePanel())
and
hook.Add("OnSpawnMenuClose", "CloseMyPanel", OnSpawnMenuClose())
be better?
don't forget to create your panel with a variable eg
myqpanel = vgui.Create("dpanel")
so on close you can do
myqpanel:Remove()
if that hook fails you can always check the concommand +menu and -menu
I think that hook i used is in the base so you shouldn't have to use the concommand also if you don't want the spawnmenu to come up either don't derive from sandbox or return false at the end of the CreatePanel() function.[/QUOTE]
The problem is that when you use that, it only returns true if the spawn menu is enabled. Like if you derive from base and use that function, holding Q will still make it return false. Anyways it's a pretty hacky way to do it. What if I wanted to do the same thing with a different button?
[QUOTE=Ben Build]Can you not see what is wrong with what you are doing there?
[b]Edit:[/b]
Derma is clientside so use lua_openscript_cl[/QUOTE]
Thanks it worked. for all the lua scripts that put stuff on your derma do you create another file or do you add it to your first derma script?
[QUOTE=superadamwo]The problem is that when you use that, it only returns true if the spawn menu is enabled. Like if you derive from base and use that function, holding Q will still make it return false. Anyways it's a pretty hacky way to do it. What if I wanted to do the same thing with a different button?[/QUOTE]
You could use one of the IN_ keys instead of KEY_, the IN ones seem to work flawlessly.
Yeah I just noticed that. Using IN_USE in the keypressed and keyreleased hooks you mentioned above makes it work for some reason. Maybe the KEY_ ones are only supposed to be for the input functions?
I thought the KEY_ enums were messed up and you had to use the corresponding numbers.
if you derive from base and use that function it will still work because it is the code for base and it just calls that hook on the concommands. If you want to use a different key you would probally have to do it a different way. As you asked how to do it with the q button I don't see how it is a "hacky" way to do it
I'm in love with the Derma controls. They kick so much ass, I wanna thank the people that put so much work into it. :D
Great guide PC Camp, hopefully people will start using it.
Alright everyone! Here is a solution to what everyone arguing about.
This VGUI script here will allow you to hold down a key and have a panel pop up but when you release the key, it goes away. This does what the Qmenu (spawnmenu) does.
[lua]
YourModName = {} -- Create a table for our panel
function YourModName:WhenGameStarts()
self.frame = nil -- Make sure the frame is nil when we start. Refer to the timer.Simple() bellow
end
function YourModName:BuildYourPanel()
local frame = vgui.Create( "DFrame" )
self.frame = frame -- Set frame to self.frame
self.frame:SetTitle( "Derma Testing Stuff" )
self.frame:ShowCloseButton( false ) -- Make sure no one presses the close button and get UBER error spam
self.frame:SetPos( 50,50 )
self.frame:SetSize( 250, 250 )
self.frame:SetDraggable( false ) -- Make sure they can't move it
/*
ADD YOUR DERMA ITEMS HERE
*/
self:HidePanel() -- Run the function that hides the panel
end
timer.Simple( 1, function() -- Make a timer when the game starts so we don't get errors
YourModName:WhenGameStarts()
YourModName:BuildYourPanel() -- Make the panel itself
end )
function YourModName:HidePanel() -- Function that hides the panel
self.frame:SetVisible( false )
gui.EnableScreenClicker( false )
end
function YourModName:ShowPanel() -- Function that opens the panel
self.frame:SetVisible( true )
gui.EnableScreenClicker( true )
end
concommand.Add( "+yourpanel", function() YourModName:ShowPanel() end ) -- Our concommand that opens the panel when pressed
concommand.Add( "-yourpanel", function() YourModName:HidePanel() end ) -- Our concommand that closes the panel when released
[/lua]
Not tested, but it should work.
Just bind a key to "+yourpanel" and when you press that key, it opens the panel. When you release that key, it closes.
Now say you don't want to have the player bind a key. Then do this.
[lua]
function SeeIfTheirKeyIsDown()
for k, v in pairs(player.GetAll()) do
if v:KeyDown( IN_USE ) then
RunConsoleCommand("+yourpanel")
end
end
end
hook.Add("Think", "Your Think Hook", SeeIfTheirKeyIsDown)
[/lua]
Hopefully that works out great.
why don't you check if the key is being pressed on the clientside as you are using a clientside panel. You don't want it to do too much on think
It's one loop. That won't do anything.
Most of the time, those client key hooks are all messed up. They only worked for me once and only for one key. I trust IN_KEYS a hell of a lot more than client key hooks.
Plus, it works just as good.
[QUOTE=PC Camp]It's one loop. That won't do anything.
Most of the time, those client key hooks are all messed up. They only worked for me once and only for one key. I trust IN_KEYS a hell of a lot more than client key hooks.
Plus, it works just as good.[/QUOTE]
Because it's not like they work using the same system or anything :sigh:
And it's both shorter and faster to use one of the hooks rather than a think, so the hooks work much better in my opinion.
Alright then I'm convinced. I took a look at the hook and from the looks of it, it's better to use the hook.
So can you provide me an example on how to use it?
[QUOTE=PC Camp]Alright then I'm convinced. I took a look at the hook and from the looks of it, it's better to use the hook.
So can you provide me an example on how to use it?[/QUOTE]
Works much the same.
[lua]
function HookMe(ply,key)
if key = IN_FORWARD then
print(ply:Nick() .. " pressed forward.")
end
end
hook.Add("KeyPress","lol",HookMe)
[/lua]
Just a small note about the DSysButton you can use these types for it:
[code]up
down
left
right
updown
close
grip
tick
question
none[/code]
Man, where did you get that info from? The wiki only said close, up, & down.
Other than that, thanks for the tip. :D
Ok I have another question now. Is it possible to make a smooth animation for a derma panel so that it slides onto the screen instead of appearing out of nowhere?
Yes that is very possible. If fact, that was going to be my next tutorial to add to the tips/tricks. This possible by using math.Approach() and math.FadeIn().
I will be contributing a lot more on friday night when I don't have school.
[QUOTE=PC Camp]Yes that is very possible. If fact, that was going to be my next tutorial to add to the tips/tricks. This possible by using math.Approach() and math.FadeIn().
I will be contributing a lot more on friday night when I don't have school.[/QUOTE]
You mean math.EaseInOut?
Ops. Yea your right. Just forgot some of my math functions.
Well I'm able to be on my comp and code shit for 2 hours a day. Which means I should be able to get a few more libraries figured out.
Where to put it and what should you name the file? :D
It doesn't matter what you name it, and put them in lua/autorun/client/
What if I wanted this to be used with a new tool I would make? Would I have to even bother making a new derma menu, or will it just appear autmatically if I just use the correct terms based on one of the base tools?
Bump, because this shit is freakin' [b]vital![/b] Could someone please make it a sticky? Everyone needs this as a sticky, even if no one posts in it anymore!
If your making a stool, you can use the default spawnmenu vgui stuff like, CPanel() or something. I don't recall exactely what it was (I'm in school), but check other stools.
If your not using basic stool controles, then make a custom derma panel.
Sorry I haven't updated this thread in a while. My prom is coming up and I gotta spend time with my girl and friends. But as soon as that's all done, I'll update this thread more.
Add DForm and DPropertySheet that would be [b]very[/b] useful
He might add if you give a nice lua example. No linkies! Just your own typed lua stuff (copy + pasting works too).
I know how to use them, I just need to write one all out with full details. I'll update this whole thread later.
[b]Edit:[/b]
[release]
[b] Spawn Menu (or ASSmod) Type Panel[/b]
This VGUI script will allow you to bind a key which will open a panel when pressed, then when released it closes just like the spawn menu.
[b]Code:[/b]
[lua]
YourModName = {} -- Create a table for our panel
function YourModName:WhenGameStarts()
self.frame = nil -- Make sure the frame is nil when we start. Refer to the timer.Simple() bellow
end
function YourModName:BuildYourPanel()
local frame = vgui.Create( "DFrame" )
self.frame = frame -- Set frame to self.frame
self.frame:SetTitle( "Derma Testing Stuff" )
self.frame:ShowCloseButton( false ) -- Make sure no one presses the close button and get UBER error spam
self.frame:SetPos( 50,50 )
self.frame:SetSize( 250, 250 )
self.frame:SetDraggable( false ) -- Make sure they can't move it
/*
ADD YOUR DERMA ITEMS HERE
*/
self:HidePanel() -- Run the function that hides the panel
end
timer.Simple( 1, function() -- Make a timer when the game starts so we don't get errors
YourModName:WhenGameStarts()
YourModName:BuildYourPanel() -- Make the panel itself
end )
function YourModName:HidePanel() -- Function that hides the panel
self.frame:SetVisible( false )
gui.EnableScreenClicker( false )
end
function YourModName:ShowPanel() -- Function that opens the panel
self.frame:SetVisible( true )
gui.EnableScreenClicker( true )
gui.SetMousePos( 75, 75 )
end
function KeyPressed(ply, key)
Msg( ply:Nick().." pressed "..key.."\n")
if key == 8192 then -- 8192 is the R key
YourModName:ShowPanel()
end
end
hook.Add( "KeyPress", "KeyPressedHook", KeyPressed )
function KeyRelease(ply, key)
Msg(ply:Nick().." released "..key.."\n")
if key == 8192 then
YourModName:HidePanel()
end
end
hook.Add( "KeyRelease", "KeyReleasedHook", KeyRelease )
[/lua]
Now when a player presses R the panel will open. Then when they release R it closes. Here is a list of [b][url=http://garrysmod.com/wiki/?title=IN_KEYS]IN_KEY[/url][/b]. Use an IN_KEY number in the key hooks.
[/release]
Fixed that whole thing.
[b]Edit:[/b]
Can someone please tell me where my spelling mistake is? :lol:
[b]Edit:[/b]
And now for some weird ass reason, just posting that edit above me fixed it. :excited:
Added more stuff.
[release]
[highlight]DPropertySheet[/highlight]
[b]Description:[/b]
Creates tabs so you can have multiple tabs in one frame with many items in them. Mainly used for organization.
[b]Code:[/b]
[lua]
local DermaPanel = vgui.Create( "DFrame" )
DermaPanel:SetPos( 50, 50 )
DermaPanel:SetSize( 350, 400 )
DermaPanel:SetTitle( "Testing Derma Stuff" )
DermaPanel:SetVisible( true )
DermaPanel:SetDraggable( false )
DermaPanel:ShowCloseButton( true )
DermaPanel:MakePopup()
local PropertySheet = vgui.Create( "DPropertySheet" )
PropertySheet:SetParent( DermaPanel )
PropertySheet:SetPos( 5, 30 )
PropertySheet:SetSize( 340, 315 )
local SheetItemOne = vgui.Create( "DCheckBoxLabel" )
SheetItemOne:SetText( "Use Props?" )
SheetItemOne:SetConVar( "some_convar" )
SheetItemOne:SetValue( 1 )
SheetItemOne:SizeToContents()
local SheetItemTwo = vgui.Create( "DCheckBoxLabel" , CategoryContentTwo )
SheetItemTwo:SetText( "Use SENTs?" )
SheetItemTwo:SetConVar( "some_convar" )
SheetItemTwo:SetValue( 1 )
SheetItemTwo:SizeToContents()
PropertySheet:AddSheet( "Some Menu", SheetItemOne, "gui/silkicons/user", false, false, "WOW It's a text box!!!" )
PropertySheet:AddSheet( "Super Menu", SheetItemTwo, "gui/silkicons/group", false, false, "Can I haz meh cheezburger now?" )
[/lua]
[b]Outcome:[/b]
[img]http://img225.imageshack.us/img225/2973/73419877pa2.png[/img]
[/release]
[release]
[highlight]DPanel[/highlight]
[b]Description:[/b]
This creates a blank frame (almost like DFrame) where you can use it as a parent and use SetPos() with items. This item can be added inside other items like DPropertySheet.
[b]Code:[/b]
[lua]
local DermaPanel = vgui.Create( "DFrame" )
DermaPanel:SetPos( 50, 50 )
DermaPanel:SetSize( 300, 325 )
DermaPanel:SetTitle( "Testing Derma Stuff" )
DermaPanel:SetVisible( true )
DermaPanel:SetDraggable( true )
DermaPanel:ShowCloseButton( true )
DermaPanel:MakePopup()
local TestingPanel = vgui.Create( "DPanel", DermaPanel )
TestingPanel:SetPos( 25, 50 )
TestingPanel:SetSize( 250, 250 )
TestingPanel.Paint = function() -- Paint function
surface.SetDrawColor( 50, 50, 50, 255 ) -- Set our rect color below us; we do this so you can see items added to this panel
surface.DrawRect( 0, 0, TestingPanel:GetWide(), TestingPanel:GetTall() ) -- Draw the rect
end
local DermaButton = vgui.Create( "DButton", TestingPanel )
DermaButton:SetText( "Click here for cheezburger!" )
DermaButton:SetPos( 20, 10 )
DermaButton:SetSize( 200, 100 )
DermaButton.DoClick = function ()
RunConsoleCommand( "kill" )
end
[/lua]
[b]Outcome:[/b]
[img]http://img134.imageshack.us/img134/7564/28459274vj6.png[/img]
[/release]
Nice,
Now i know how to use them to :D
Only this...
I'm very bad in the position things
Sorry, you need to Log In to post a reply to this thread.