Hello facepunch,
I am currently learning lua coding by making commands and suchs.
Right now, I am working on a "/help" command for a prophunt server that will open a url with some custom made instructions.
Unfortunetly, I have never worked with urls or the PlayerSay hook before.
I have what I think is a beginning or a part of a code.
[CODE]hook.Add( "PlayerSay", "Help", function( ply, text, team )
if ( string.sub( text, 1, 5 ) == "/help" ) then--if ( the first 5 letters are /help continue
Panel:OpenURL( http://techsource.dk/forum/general-52/how-to-play )
return
end
end )
[/CODE]
I haven't tested it out yet but honestly I can't see why this will work in any possible way.
So can anyone help me from here?
PlayerSay is serverside only. Have you defined Panel?
Firstly, you never defined the HTML Panel (Derma). One second, and I'll throw something together for you.
Take a look at this very recent thread, it should give you some answers.
[url]http://facepunch.com/showthread.php?t=1415021[/url]
[QUOTE=Lolm4te;45602668]Firstly, you never defined the HTML Panel (Derma). One second, and I'll throw something together for you.[/QUOTE]
He's learning, not requesting you to make something for him ;)
I just grabbed this from my modified version of the ULX Motd. Should work, even though I had a "I disagree" button. Just remove it or put something else, I don't know :P
Edit: Commented a few things as your learning.
[lua]
-- Clientside
local pnlColors = { -- Heres our color table. We put colors in here! Then we do for example pnlColors.WhiteBackground to get that color out of the table.
WhiteBackground = Color(120,120,120), WhiteShadow = Color(215,215,215), WhiteMain = Color(243,243,243),
GreenBackground = Color(9, 144, 76), GreenShadow = Color(39, 174, 96), GreenMain = Color(46, 204, 113),
RedBackground = Color(162, 27, 13), RedShadow = Color(192, 57, 43), RedMain = Color(231, 76, 60),
BlueBackground = Color(11, 98, 155), BlueShadow = Color(41, 128, 185), BlueMain = Color(52, 152, 219),
GreyBackground = Color(87, 90, 91), GreyShadow = Color(127, 140, 141), GreyMain = Color(189, 195, 199),
Background = Color(0,0,0), Shadow = Color(55,55,55), Main = Color(35,35,35)
}
function openhelpmenu() -- This is the function, we put everything in there.
local window = vgui.Create( "DFrame" ) -- Defines the "window"
if ScrW() > 640 then -- A little thing we do to size the menu a little better.
window:SetSize( ScrW()*0.9, ScrH()*0.9 )
else
window:SetSize( 640, 480 )
end
window:Center() -- This centers the derma.
window:SetTitle( "" ) -- This puts the title to nothing as we dont really need a title.
window:SetVisible( true ) -- Makes the menu visible. This is needed for it to draw.
window:MakePopup() -- Opens the menu. Also needed.
window:ShowCloseButton(false) -- Dont worry about this one, you already got the button to close the motd.
window.Paint = function( s,w,h ) -- This paints the menu itself. I'll only explain it here as we draw the same thing most of the time.
surface.SetDrawColor( pnlColors.Background ) -- Sets the color of the rectangle were about to draw.
surface.DrawRect( 0,0, w,h ) -- Draws the rectangle at position 0,0, and the size at w(width) and h(height). The width and height are taken from the derma menu.
surface.SetDrawColor( pnlColors.Shadow ) -- Does the same as above, but we just take another color from the table.
surface.DrawRect( 1,1, w-2,h-2 )
surface.SetDrawColor( pnlColors.Main )
surface.DrawRect( 2,2, w-4,h-4 )
end
local button = vgui.Create( "DButton", window ) -- Creates our main window. It's the same as above, pretty self explanatory.
button:SetSize( 365, 50 )
button:SetPos( (window:GetWide() - button:GetWide()) / 5, window:GetTall() - button:GetTall() - 10 )
button.Paint = function( s,w,h )
surface.SetDrawColor( pnlColors.GreenBackground )
surface.DrawRect( 0,0, w,h )
surface.SetDrawColor( pnlColors.GreenShadow )
surface.DrawRect( 1,1, w-2,h-2 )
surface.SetDrawColor( pnlColors.GreenMain )
surface.DrawRect( 2,2, w-4,h-4 )
end
button:SetFont("DermaLarge")
button:SetTextColor( Color(255,255,255,255) )
button.OnCursorEntered = function() button:SetTextColor( Color(55,55,55,255) ) end
button.OnCursorExited = function() button:SetTextColor( Color(255,255,255,255) ) end
button.OnMouseReleased = function() button:SetTextColor( Color(22,22,22,255) ) window:Close() end
button:SetText( "I got it, thanks!" )
local dbutton = vgui.Create( "DButton", window )
dbutton:SetSize( 365, 50 )
dbutton:SetPos( (window:GetWide() - button:GetWide()) / 2 * 2 - (132.5*2/1.5), window:GetTall() - button:GetTall() - 10 )
dbutton.Paint = function( s,w,h )
surface.SetDrawColor( pnlColors.RedBackground )
surface.DrawRect( 0,0, w,h )
surface.SetDrawColor( pnlColors.RedShadow )
surface.DrawRect( 1,1, w-2,h-2 ) // -2 because it's 1 from each end
surface.SetDrawColor( pnlColors.RedMain )
surface.DrawRect( 2,2, w-4,h-4 )
end
dbutton:SetFont("DermaLarge")
dbutton:SetTextColor( Color(255,255,255,255) )
dbutton.OnCursorEntered = function() dbutton:SetTextColor( Color(55,55,55,255) ) end
dbutton.OnCursorExited = function() dbutton:SetTextColor( Color(255,255,255,255) ) end
dbutton.OnMouseReleased = function() dbutton:SetTextColor( Color(22,22,22,255) ) end
dbutton:SetText( "meh idk lol" ) -- Put something here or just remove it.
local html = vgui.Create( "HTML", window )
html:SetSize( window:GetWide() - 20, window:GetTall() - button:GetTall() - 50 + 20 )
html:SetPos( 10, 10 )
html:OpenURL( "http://techsource.dk/forum/general-52/how-to-play" ) -- Here we put the URL you would like to be displayed.
end
concommand.Add("openhelpmenu", openhelpmenu)
-- Serverside
hook.Add( "PlayerSay", "Help", function( ply, text, team ) -- The hook.
if ( string.sub( text, 1, 5 ) == "/help" ) then -- Checks if the player typed "/help" in the chat.
ply:RunConsoleCommand("openhelpmenu") -- Makes the player run the console command.
end
end ) -- Ends the hook. (Thats why we need the ")")
[/lua]
Ok so Beta (lol hi Beta xD), your comment helped me A LOT, and yea I didn't actually know Derma untill now (Ergo the learning part).
I got this code now. Dunno if it will work, I can't test it atm (long story)
[CODE]local function PropHuntHelpPage()
local PeopHuntHelp = vgui.Create( "DFrame" )
frame:SetSize( 1050, 700 )
frame:SetTitle( "PropHunt Help Page" )
frame:SetVisible( true )
frame:SetDraggable( true )
frame:Center( true )
local html = vgui.Create( "DHTML" , frame )
html:Dock( FILL )
html:OpenURL( http://techsource.dk/forum/general-52/how-to-play/ )
frame:MakePopup()
hook.Add( "OnPlayerChat", "Help", function( ply, text )
if ( text == "/help" ) then
PropHuntHelpPage()
end
end )[/CODE]
Btw, if I need some if SERVER then thing before the actual code and I also have other mistakes, don't leave one comment saying that I need that, because it's a really obvious thing....
No. You're not ending the PropHuntHelpPage function. Also, you'll want to check if the caller player is LocalPlayer();
[QUOTE=JasonMan34;45602856]Ok so Beta (lol hi Beta xD), your comment helped me A LOT, and yea I didn't actually know Derma untill now (Ergo the learning part).
I got this code now. Dunno if it will work, I can't test it atm (long story)
[CODE]local function PropHuntHelpPage()
local PeopHuntHelp = vgui.Create( "DFrame" )
frame:SetSize( 1050, 700 )
frame:SetTitle( "PropHunt Help Page" )
frame:SetVisible( true )
frame:SetDraggable( true )
frame:Center( true )
local html = vgui.Create( "DHTML" , frame )
html:Dock( FILL )
html:OpenURL( http://techsource.dk/forum/general-52/how-to-play/ )
frame:MakePopup()
hook.Add( "OnPlayerChat", "Help", function( ply, text )
if ( text == "/help" ) then
PropHuntHelpPage()
end
end )[/CODE]
Btw, if I need some if SERVER then thing before the actual code and I also have other mistakes, don't leave one comment saying that I need that, because it's a really obvious thing....[/QUOTE]
Hiii, I'm mobile ATM and not fully able to look over it, but you got a part wrong.
Change every thing called frame to PropHuntHelp as frame does not exists, and PropHuntHelp is your VGUI DFrame and does exists.
And your link should be in quotes "" as it is a string ;b
[QUOTE=crazyscouter;45602878]No. You're not ending the PropHuntHelpPage function. Also, you'll want to check if the caller player is LocalPlayer();[/QUOTE]
Fixed the function end thing.
What exactly do you mean in the second part?
Use this code instead for your hook.[code]
hook.Add( "OnPlayerChat", "Help", function( ply, text )
if ( ply == LocalPlayer() && text == "/help") then
PropHuntHelpPage()
end
end )
[/code]
[QUOTE=crazyscouter;45602921]Use this code instead for your hook.[code]
hook.Add( "OnPlayerChat", "Help", function( ply, text )
if ( ply == LocalPlayer() && text == "/help") then
PropHuntHelpPage()
end
end )
[/code][/QUOTE]
Oh ok I see what you mean now. Thanks.
So this should work?
[CODE]local function PropHuntHelpPage()
local PeopHuntHelp = vgui.Create( "DFrame" )
frame:SetSize( 1050, 700 )
frame:SetTitle( "PropHunt Help Page" )
frame:SetVisible( true )
frame:SetDraggable( true )
frame:Center( true )
local html = vgui.Create( "DHTML" , frame )
html:Dock( FILL )
html:OpenURL( http://techsource.dk/forum/general-52/how-to-play/ )
frame:MakePopup()
end
hook.Add( "OnPlayerChat", "Help", function( ply, text )
if ( ply == LocalPlayer() && text == "/help") then
PropHuntHelpPage()
end
end )[/CODE]
It makes sure that we won't try to open the panel on everything else than the client if you wondered :)
[B]Edit:[/B] No, you didn't change anything that was clarified in my post
No that won't work. Read what Beta told you, and fix those problems.
[QUOTE=The Beta;45602939]It makes sure that we won't try to open the panel on everything else than the client if you wondered :)
[B]Edit:[/B] No, you didn't change anything that was clarified in my post[/QUOTE]
Oh lol I didn't even see your post xD
[CODE]local function PropHuntHelpPage()
local PeopHuntHelp = vgui.Create( "DFrame" )
PeopHuntHelp:SetSize( 1050, 700 )
PeopHuntHelp:SetTitle( "PropHunt Help Page" )
PeopHuntHelp:SetVisible( true )
PeopHuntHelp:SetDraggable( true )
PeopHuntHelp:Center( true )
local html = vgui.Create( "DHTML" , PeopHuntHelp )
html:Dock( FILL )
html:OpenURL( "http://techsource.dk/forum/general-52/how-to-play" )
PeopHuntHelp:MakePopup()
end
hook.Add( "OnPlayerChat", "Help", function( ply, text )
if ( ply == LocalPlayer() && text == "/help") then
PropHuntHelpPage()
end
end )[/CODE]
This??
No... put the url in quotes
[QUOTE=crazyscouter;45602965]No... put the url in quotes[/QUOTE]
Oh lol, I hate those kinda stuff >_>
Done.
Code should work now? (lol)
-snip-
[QUOTE=Lolm4te;45602990][lua]
-- Put this clientside
local function PropHuntHelpPage()
local PropHuntHelpPage = vgui.Create( "DFrame" )
PropHuntHelpPage:SetSize( 1050, 700 )
PropHuntHelpPage:SetTitle( "PropHunt Help Page" )
PropHuntHelpPage:SetVisible( true )
PropHuntHelpPage:MakePopup()
PropHuntHelpPage:SetDraggable( true )
PropHuntHelpPage:Center( true )
local PropHuntHelpHTML = vgui.Create( "DHTML" , frame )
PropHuntHelpHTML:Dock( FILL )
PropHuntHelpHTML:OpenURL( "http://techsource.dk/forum/general-52/how-to-play" )
end
concommand.Add("PropHuntHelpPage", PropHuntHelpPage)
-- Put this server side.
hook.Add( "OnPlayerChat", "Help", function( ply, text )
if ( ply == LocalPlayer() && text == "/help") then
ply:RunConsoleCommand("PropHuntHelpPage")
end
end )
[/LUA][/QUOTE]
-_-
I want to learn, not to have you change/create a code for me
Lolm4te I know you post code for the good and help, but he is trying to learn, so sticking up a wall of code will pretty much get him nowhere.
And commenting it will be a proper start
[B]Edit:[/B] ninja'dd
[B]Edit2:[/B] it should work now, Jason :p
That code is hideous. It would never work. You are parenting the html to a nonexistent panel( frame ) and you're trying to use RunConsoleCommand() as if it's a meta-method. Wut.
-snip-
One last question:
Where should this file be?
I'm assuming lua/autorun/server but I'm not sure
EDIT: Also fixed the PeopHuntHelp -> PropHuntHelp that appeared many times in the code :P
Ignore Lolm4te's post. The OnPlayerChat hook is CLIENT SIDE, not SERVER SIDE. This would go in lua/autorun/client since everything is client-side here.
[QUOTE=JasonMan34;45603047]One last question:
Where should this file be?
I'm assuming lua/autorun/server but I'm not sure[/QUOTE]
Serverside goes into addons/youraddon/lua/autorun/server
Clientside goes into addons/youraddon/lua/autorun/client
In other words, put it in client. (addons/youraddon/lua/autorun/client/myaddon.lua)
[QUOTE=Lolm4te;45603064]Serverside goes into addons/youraddon/lua/autorun/server
Clientside goes into addons/youraddon/lua/autorun/client[/QUOTE]
Yes, you are right.. For a change..
[QUOTE=ms333;45602664]PlayerSay is serverside only. Have you defined Panel?[/QUOTE]
[QUOTE=crazyscouter;45603059]Ignore Lolm4te's post. The OnPlayerChat hook is CLIENT SIDE, not SERVER SIDE. This would go in lua/autorun/client since everything is client-side here.[/QUOTE]
I'm sorry for mistaking.
[QUOTE=Lolm4te;45603245]I'm sorry for mistaking.[/QUOTE]
Really? You HAD to post that? Anyways thanks for reminding me to mark as solved.
Funny thing: If you look in the link you'll see that the "how to play" is for murder, but the whole code uses the "PropHuntHelp", not that it matters, just so dumb (I changed it) :P
Sorry, you need to Log In to post a reply to this thread.