Im New To Derma

What do function do i use to call a dpanel? I want to use “KEY_F4”, how do i do this, and i made my dframe, but what files do i need in order for it to work, and were do i put these files? Im really new to derma.

Derma will always be on the client. As for calling it with KEY_F4 here’s what I do.



//DFrame code taken from the wiki
function MyDFrame()
     local Frame = vgui.Create( "DFrame" )
     Frame:SetPos( 5, 5 )
     Frame:SetSize( 300, 150 )
     Frame:SetTitle( "Name window" )
     Frame:SetVisible( true )
     Frame:SetDraggable( false )
     Frame:ShowCloseButton( true )
     Frame:MakePopup()
end

function OpenWindow(key)
     if key == KEY_F4 then
          MyDFrame()
     end
end
hook.Add("KeyPress", "CoolName", OpenWindow)


For opening by F4 key you can use something like this:

(clientside, gamemode hook)



function GM:PlayerBindPress(client, bind, pressed)
    bind = bind:lower()
    
    print("binding")

    if (bind:find("gm_showhelp") and pressed) then
        return true
    elseif (bind:find("gm_showteam") and pressed) then
        return true
    elseif (bind:find("gm_showspare1") and pressed) then
        return true
    elseif (bind:find("gm_showspare2") and pressed) then
        -- F4 key
        vgui.Create("yourPanelName")
        return true
    end
end
    


You can also use the serverside function: http://wiki.garrysmod.com/page/GM/ShowSpare2
But then you will have to send a message to the client.

For placing scripts, look into these Tutorials: http://wiki.garrysmod.com/page/Beginner_Tutorial_Intro
http://wiki.garrysmod.com/page/Gamemode_Creation

Edit: Also look at this: http://wiki.garrysmod.com/page/Hook_Library_Usage as my version above with overriding GM:PlayerBindPress directly is for gamemodes, you may want to make a hook.

Ok thanks, that helped alot, but how can i make it check if a player is a certain team? Im making this for darkrp at the moment so how does one go about this?

Why not just use ShowSpare2?

ShowSpare2 is serversided and it’s easier to use GM:KeyPress instead of creating a serverside file and setting up a net message/concommand to call the derma window.

Wait ShowSpare2 is better than using KEY_F4?

Yes, as it will respect your keymapping in Garrysmod options. (see my solution above, it uses ShowSpare2 client side).

From the user friendliness stand point - yes.

ShowSpare2 is called whenever user presses a key bound to gm_showspare2.

This means that if you use the KeyDown method, and say the user has “kill” bound to F4, you’d cause the user to suicide.

If you use ShowSpare2 and user presses F4 he will suicide if F4 is bound to “kill”, BUT they can bind “gm_showspare2” to any other key they like, and ShowSpare2 will still be called, unline the KeyDown method.

If you do not want to use the serverside variation, use PlayerBindPress hook on client and look for “gm_showspare2” binding.

[editline]25th August 2015[/editline]

Ninjad to the max.

Ok, thanks :), how can i make it so that the panel closes and print something in chat do i create two functions like this


 Button.DoClick = function()
		print( "/group Im a new officer, does any one need any help?" )
		Frame:CloseFunctionThatIDontKnow
end



And what is the derma function to close it, i dont like the default buttons at the top it reminds me that my server is not a linux one…

Here is the function for closing a panel: http://wiki.garrysmod.com/page/Panel/Remove

For the default look look here: http://wiki.garrysmod.com/page/derma/DefineSkin / https://github.com/garrynewman/garrysmod/blob/master/garrysmod/lua/skins/default.lua
(Its the derma skin)

RunConsoleCommand( “say”, “shit” )
Frame:Remove()

Thanks. So were does this go


 function GM:PlayerBindPress(client, bind, pressed)
    bind = bind:lower()
    
    print("binding")

    if (bind:find("gm_showhelp") and pressed) then
        return true
    elseif (bind:find("gm_showteam") and pressed) then
        return true
    elseif (bind:find("gm_showspare1") and pressed) then
        return true
    elseif (bind:find("gm_showspare2") and pressed) then
        -- F4 key
        vgui.Create("Police")
        return true
    end
end 

Spad?

It depends, do you modify the gamemode directly or is this an addon?

If you modify the gamemode you can place it in any client side file. (cl_…) But make sure that this functions is nowhere else.

If your doing an addon you need to add a hook, see http://wiki.garrysmod.com/page/Hook_Library_Usage

The name of the Hook is also PlayerBindPress

*Sapd

Im great a spelling its an addon.

[editline]25th August 2015[/editline]

Do i need to put the Hook.Add at the top of the file?

hook.Add, pay attention Lua is case sensitive

Ok but, do i put it at the top of the file or does it not matter?

[editline]25th August 2015[/editline]

Hrmmmm i stuck, so iv done


 hook.Add( "PlayerBindPress", ) 

I dont know what to do from here?



hook.Add("PlayerBindPress", "MyHookname", function(client, bind, pressed)
    bind = bind:lower()
    
    print("binding")

    if (bind:find("gm_showhelp") and pressed) then
        return true
    elseif (bind:find("gm_showteam") and pressed) then
        return true
    elseif (bind:find("gm_showspare1") and pressed) then
        return true
    elseif (bind:find("gm_showspare2") and pressed) then
        -- F4 key
        vgui.Create("Police")
        return true
    end
end)



 local Police = vgui.Create ( "DFrame" )

Frame:SetPos( 5, 5 )
Frame:SetSize( 900, 600 )
Frame:SetTitle( "CivilisationRP: Police Radio Codes" )
Frame:SetVisable( "true" )
Frame:SetDraggable( "true" )
Frame:ShowCloseButton( "true" )
Frame:MakePopup()
Frame:Paint = function( self, w, h )
		draw.RoundedBox( 0, 0, 0, w, h, Color( 0, 0, 0, 200 ) )
end

local Button = vgui.Create ( "DButton", Frame )
Button:SetText( "I Under Stand." )
Button:SetTextColor( Color(" 255, 255, 255, 255 ") )
Button:SetPos( 800, 500 )
Button:SetSize( 100, 30 )
Button.Paint = function( self, w, h )
		draw.RoundedBox( 0, 0, 0, w, h, Color( 0, 0, 0, 200 ))
end

Button.DoClick = function()
		RunConsoleCommand( "say", "/group Im a new officer, whats are my orders?" )
		Frame:Remove() 
end

hook.Add( "PlayerBindPress", "F4", function(client, bind, pressed)
	bind = bind:lower()
	
	print("binding")
	
	if (bind:find("gm_showhelp") and pressed) then
		return true 
	 elseif (bind:find("gm_showspare1") and pressed) then
        return true
    elseif (bind:find("gm_showspare2") and pressed) then
        -- F4 key
        vgui.Create("Police")
        return true
    end
end)
	


So far i have this, though i have it all in one folder addons\police\lua\client.lua, i assume thats wrong in some way or an other, but you know learning :confused:

[editline]25th August 2015[/editline]

What do i do from here?

lua/autorun/client*