Popup Box On Server Join (Completed)

Hey,

I finally managed to create my very own lua element on my server. I happened to make a pop up box that is shown when you first join the server. I used this to display a link that users could click to go to a page to install custom content.

I am so happy that I’ve finally did something in Lua (in case you havent realized, im a total newb) that I’ve decided to release my code to help others that are in my position!

Here is the code:


-- server
function CrapTasket(ply)
	umsg.Start("customcontent", ply)
	umsg.End()
end
hook.Add( "PlayerInitialSpawn", "ShowStartingMenu", CrapTasket )

-- client

function CustomContent()
	local base = vgui.Create( "DFrame" )
        base:SetPos(ScrW()/2 - 150, ScrH()/2 - 100 )
        base:SetSize( 300, 200 )
        base:SetVisible( true )
        base:SetTitle( "Custom Content" )
        base:SetDraggable( false )
        base:ShowCloseButton( true )
        base:MakePopup()
        
    local label = vgui.Create( "RichText", base )
        label:SetPos( 75, 50 )
        label:SetSize( 150, 50 )
        label:SetVerticalScrollbarEnabled(false)
        label:SetText( "This server uses custom content, click here to learn how to install it." )
        
	local button = vgui.Create( "DButton" )
        button:SetParent( base )
        button:SetPos(75,100)
        button:SetText( "Install Custom Content" )
        button:SetSize( 150, 50 )
        button.DoClick = function() gui.OpenURL("YOUR WEBSITE HERE") end
end
usermessage.Hook("customcontent", CustomContent)

I would also like to give credit to circuitbawx for helping me with the code to get started!

To use this, make a file in /lua/autorun/ of your server and paste this code in it!

Thanks

-snip-

Its very kind of you to share this. Thank you and good luck in future projects!

When you release code, you should probably edit it so, it’s a general template and not made for your server.

For example on one line, you have:


button.DoClick = function() gui.OpenURL("http://hobonationrp.com/") end

But that not my website, so you probably should’ve left that blank or left a // comment on the side, indicating to put your own thing in.

It may seem like an obvious thing to do, but lots of people are lazy and will just straight up copy/paste this.

Psh people who rate him dumb, at least he’s trying you can at least be supportive! Good job on future projects!

Well if its your first good bit then well done. I am trying to. ^_^". Currently failing. But I’m sure I’ll get there and good work.

I shall add comments.

Thank you everyone for the support!

[editline]29th August 2013[/editline]

I gave credit to him, read next time.