The Ultimate Guide to Derma - Everything there is to know about Derma
217 replies, posted
Yea I usually use the standard calculator that windows XP came with to position things. Or I just use GetWide() and GetTall().
There are such commands?! [b]Hacks![/b]
Right here:
[lua]surface.DrawRect( 0, 0, TestingPanel:GetWide(), TestingPanel:GetTall() )[/lua]
So, you could set the panel resolution to the screen's resolution?
Would this signify sufficient interest in Derma to quality finishing my offline editor?
It might Olivier :P
PC Camp,can you make a new part to this Ultimate Guide on what to name the lua files,where to put them,where to put the folders etc?
-Thanks!
All derma related files must be somewhere were the client can find it and load it. Other then that pretty much anything goes.
Just make a lua file and put it in lua/autorun/client/ to test it out.
I'll be uploading how to use DComboBox which was a [b]pain in the fucking ass[/b] to figure out. :lol:
I figured it was somewhere in the autorun folder!Thanks :P
[QUOTE=PC Camp]Just make a lua file and put it in lua/autorun/client/ to test it out.
I'll be uploading how to use DComboBox which was a [b]pain in the fucking ass[/b] to figure out. :lol:[/QUOTE]
:blank: I would have thought that DComboBox would have been included in the first revision.
No, that one was a pain in the ass and I just didn't think people needed it yet because I've never seen it used in any mod.
[b]Edit:[/b]
Here's DComboBox.
[release]
[highlight]DComboBox[/highlight]
[b]Description:[/b]
This creates a list of options you can add to it then work with them later.
[b]Code:[/b]
[lua]
DermaFrame = vgui.Create( "DFrame" )
DermaFrame:SetPos( 50, 50 )
DermaFrame:SetSize( 400, 225 )
DermaFrame:SetTitle( "Derma Testing" )
DermaFrame:SetVisible( true )
DermaFrame:SetDraggable( true )
DermaFrame:ShowCloseButton( true )
DermaFrame:MakePopup()
local TestingComboBox = vgui.Create( "DComboBox", DermaFrame )
TestingComboBox:SetPos( 10, 35 )
TestingComboBox:SetSize( 100, 185 )
TestingComboBox:SetMultiple( false ) -- Don't use this unless you know extensive knowledge about tables
TestingComboBox:AddItem( "Add" ) -- Add our options
TestingComboBox:AddItem( "Some" )
TestingComboBox:AddItem( "Options" )
TestingComboBox:AddItem( "Here" )
local MainMenuSheet = vgui.Create( "DPanel", DermaFrame ) -- We create a panel so we can draw shit on; if we use the frame, it comes up transparent for some reason
MainMenuSheet:SetPos( 125, 50 )
MainMenuSheet:SetSize( DermaFrame:GetWide() - 25, DermaFrame:GetTall() - 25 )
MainMenuSheet.Paint = function()
if TestingComboBox:GetSelectedItems() and TestingComboBox:GetSelectedItems()[1] then -- make sure something is selected if not we get uber spam of errors
local OurStringThing = "Your selection is: "..TestingComboBox:GetSelectedItems()[1]:GetValue().."!" -- This was a pain in the ass to figure out; this gets the name of the option chosen
surface.SetFont( "default" )
surface.SetTextColor( 255, 255, 255, 255 )
surface.SetTextPos( 50, 50 )
surface.DrawText( OurStringThing ) -- Draws the text
end
end
[/lua]
[b]Outcome:[/b]
[img]http://img229.imageshack.us/img229/8841/42204851fw7.png[/img]
[/release]
[highlight]HUGE EDIT:[/highlight]
Garry you might want to look into this bug. When I use the release tags, they only work if i edit it again three times exactly. Not sure why.
[b]Edit:[/b]
And when I try and edit the first post, it comes up blank.
This is good work. You've come a long way.
The only thing I would say is that in your last example, the spawn menu type menu, you should be using enumerations when you are checking for key presses.
[QUOTE=tjl]This is good work. You've come a long way.
The only thing I would say is that in your last example, the spawn menu type menu, you should be using enumerations when you are checking for key presses.[/QUOTE]
Thank you. :)
What are enumerations?
I used the keypress and keyrelease hooks because it made sense and works perfect.
What other way should I do it?
The enumerations are the IN_ key enumerations for keystrokes.
Garry: Get us a gods be enumeration for NPC conditions and fix the damn schedule execution bug. :argh:
Enumerations (in Lua at least) are just global variables that store a number (the key number). For the "R" key it would just look like this: [code]IN_RELOAD = 8192[/code]For example, in your KeyPress and KeyRelease hooks you are checking if the "R" key has been pressed or released using the constant 8192. This is where you should be using an enumeration.
So why bother?
If garry decides that he wants to change the key numbers for whatever reason, your script is now broken. However, if you use the enums, your script will still work because garry is smart enough to change the number the enum stores to the new key number.
I hope that made sense..
Also, here is the page with all the key enums:
[url]http://wiki.garrysmod.com/wiki/?title=IN_KEYS[/url]
My brain just died, but I understand it. :loleyes:
[QUOTE=tjl]
I hope that made sense..[/QUOTE]
That made perfect sense. :lol:
But I don't see why garry would change the numbers.
Well here's one reason:
[url]http://forums.facepunchstudios.com/showpost.php?p=9838124&postcount=4[/url]
I didn't find the DComboBox that complicated at all. This code uses DoClick on the ComboBoxItems so you can execute code once a player selects a new item:
[lua]
-- 'Class' label
local cllabel = vgui.Create("DLabel",subframe)
cllabel:SetText( "Class" )
cllabel:SetPos( 5, 30 )
cllabel:SetSize( 60, 25 )
-- List of choosable classes
local classlist = vgui.Create("DComboBox",subframe)
classlist:SetPos( 5, 50 )
classlist:SetSize( 160, 100 )
-- Insert all the class options
if (team == TEAM_HUMAN) then
for k = 1, #HumanClass do
if (HumanClass[k].Choosable) then
class[k] = classlist:AddItem( HumanClass[k].Name )
else
class[k] = nil
end
end
else
for k = 1, #UndeadClass do
if (UndeadClass[k].Choosable) then
class[k] = classlist:AddItem( UndeadClass[k].Name )
else
class[k] = nil
end
end
end
---- Bla bla bla
-- every option in the combobox needs to update the loadout list
for k = 1, #class do
if (class[k] ~= nil) then
class[k].DoClick = function( btn )
local selectedClass = getSelectedClass()
if (team == TEAM_HUMAN) then
numLoadouts = (#HumanClass[selectedClass].SwepLoadout)
elseif (team == TEAM_UNDEAD) then
numLoadouts = (#UndeadClass[selectedClass].SwepLoadout)
end
updateLoadoutList()
updateDescription( DESC_CLASS )
end
end
end
[/lua]
Example from my Infected Wars gamemode.
Also useful for using table data in a DComboBox.
[QUOTE=PC Camp]-snip- LOONNNG POST[/QUOTE]
Ehmm... This is awesome. I'm definitely creating some derma shit for fun this weekend.
[b]Edit:[/b]
Now I'm into Derma. Could you post the general syntax for all the things. Also the parameters. Thanks.
Well take a look here.
[lua]
vgui.Create( "Control_Name", Control_Parent )
[/lua]
Then use the wiki to fill out the rest. If you have any problems, just post.
It's not always garry who changes the numbers - the engine may have changed enum values. So, if another bind is added, IN_RELOAD or whatever could have a different value than normal.
I've only just started attempting derma thanks to your guide. I get everything except for this one thing.
[lua]local CheckBoxThing = vgui.Create( "DCheckBoxLabel", DermaPanel )
CheckBoxThing:SetPos( 10,50 )
CheckBoxThing:SetText( "God Mode" )
CheckBoxThing:SetConVar( "sbox_godmode" ) -- ConCommand must be a 1 or 0 value
CheckBoxThing:SetValue( 1 )
CheckBoxThing:SizeToContents()[/lua]
That's all well and good, however whenever I open the panel I have placed it in, it automatically sets the convar to 1. Naturally I just removed [lua]CheckBoxThing:SetValue( 1 )[/lua]
However, I assume this command is only intended for sbox convars. For example if I wanted to toggle a gamemode specific variable, how would I go about doing it? Because at the moment if I use a gamemode specific variable it will automatically set it to 1 regardless of whether I have declared the value or not. And if possible can it be made to display the current status of the convar? i.e. If the variable is already set to 1 by default, display the box with a tick. Thanks for any help.
Well if you want it to be set to 0, then do this.
[lua]CheckBoxThing:SetValue( 0 )[/lua]
That will set the value to 0 instead of just removing that line.
For your gamemode question, you need to use your autoexec.cfg file to set your convars. Then set the values of your checkboxes accordingly to the set values in the autoexec.cfg.
I made a simple script that opens up some derma stuff with buttons that connects to a bunch of server (noxiousnet servers) The first thing i have ever done in lua. Granted most of it was copy and pasted and playing around.
I had to find out about functions myself.
:blank:
Anyways, can I have permission to use the pictures and prototypes in this thread for the GMLua Editor?
I think you can,PC Camp is a nice guy,but ask him first. :P
Does anyone know what lines to put in to make a command to open/close the derma?Of course you can enter the command into console.
[QUOTE=OlivierHamel]:blank:
Anyways, can I have permission to use the pictures and prototypes in this thread for the GMLua Editor?[/QUOTE]
Yea I don't mind one bit. :lol:
What's GMod Lua Editor if you don't mind me asking?
-snip- nevermind
[QUOTE=PC Camp]Yea I don't mind one bit. :lol:
What's GMod Lua Editor if you don't mind me asking?[/QUOTE]
:blank:
What does it say? I read: 'GMod Lua Editor'. I'd have to conclude that it means it's a dedicated full featured editor for GMod that include templates limited intellisense and a derma form creator.
Sorry, you need to Log In to post a reply to this thread.