• Simple script to open a URL?
    13 replies, posted
Hi, I have made a little website that has a donation page for my server. Since it's annoying to see a 'donate here' page upon joining a server, can someone please give me a code that will make a GUI Window pop up when someone types '!donate' or something along those lines? I searched other topics like this and all of the code is outdated and won't work. Thank you very much.
[lua]hook.Add( "OnPlayerChat", "DonateCommand", function( ePlayer, sText ) if ( string.StartWith( string.lower( sText ), "!donate" ) ) then gui.OpenURL( "http://www.google.com/" ); end end );[/lua] That opens it in the steam browser.
[QUOTE=DaneSomdahl;39878134][lua]hook.Add( "OnPlayerChat", "DonateCommand", function( ePlayer, sText ) if ( string.StartWith( string.lower( sText ), "!donate" ) ) then gui.OpenURL( "http://www.google.com/" ); end end );[/lua] That opens it in the steam browser.[/QUOTE] Thanks, but do you have one that opens it in a ULX-MOTD style GUI? Thanks in advance.
Oops sorry for the delay. I was wondering outside aimlessly. I whipped this up for ya. [lua] local donate = { ["URL"] = "http://www.google.com/"; }; function donate.CreatePanel( ) local w = 800; -- Width local h = 600; -- Height local p = 8; -- Padding donate.Frame = vgui.Create( "DFrame" ); donate.Frame:SetTitle( "Donate" ); donate.Frame:SetSize( w + (p * 2), h + (p * 5) ); donate.Panel = vgui.Create( "DPanel", donate.Frame ); donate.Panel:SetPos( 8, 32 ); donate.Panel:SetSize( w, h ); donate.HTML = vgui.Create( "HTML", donate.Panel ); donate.HTML:SetPos( 8, 8 ); donate.HTML:SetSize( w - (p * 2), h - (p * 2) ); donate.HTML:OpenURL( donate.URL ); donate.Frame:Center(); donate.Frame:MakePopup(); end hook.Add( "OnPlayerChat", "DonateCommand", function( ePlayer, sText ) if ( string.StartWith( string.lower( sText ), "!donate" ) ) then donate.CreatePanel( ); end end );[/lua]
[QUOTE=DaneSomdahl;39879593]Oops sorry for the delay. I was wondering outside aimlessly. I whipped this up for ya. [lua] local donate = { ["URL"] = "http://www.google.com/"; }; function donate.CreatePanel( ) local w = 800; -- Width local h = 600; -- Height local p = 8; -- Padding donate.Frame = vgui.Create( "DFrame" ); donate.Frame:SetTitle( "Donate" ); donate.Frame:SetSize( w + (p * 2), h + (p * 5) ); donate.Panel = vgui.Create( "DPanel", donate.Frame ); donate.Panel:SetPos( 8, 32 ); donate.Panel:SetSize( w, h ); donate.HTML = vgui.Create( "HTML", donate.Panel ); donate.HTML:SetPos( 8, 8 ); donate.HTML:SetSize( w - (p * 2), h - (p * 2) ); donate.HTML:OpenURL( donate.URL ); donate.Frame:Center(); donate.Frame:MakePopup(); end hook.Add( "OnPlayerChat", "DonateCommand", function( ePlayer, sText ) if ( string.StartWith( string.lower( sText ), "!donate" ) ) then donate.CreatePanel( ); end end );[/lua][/QUOTE] Right in time! When one person said '!donate' EVERYONE opened the browser :pwn: Mabye I should put it in the 'client' section of lua>autorun? Thanks!
Wait what? It's a clientside script; therefor the only person it should affect is the local player. you should put the script in a clientside file for your gamemode, or its own file in lua/autorun/client/. Then serverside make sure to add the clientside lua file like this: [lua]AddCSLuaFile( "autorun/client/thefileyousaveditas.lua" );[/lua]
You need to do a check to see if ePlayer is LocalPlayer, then run the function.
[QUOTE=Greetings;39881886]You need to do a check to see if ePlayer is LocalPlayer, then run the function.[/QUOTE] Oh yeah, I didn't pay attention to that. Just make the hooking part [lua]hook.Add( "OnPlayerChat", "DonateCommand", function( ePlayer, sText ) if ( string.StartWith( string.lower( sText ), "!donate" ) && ePlayer == LocalPlayer() ) then donate.CreatePanel( ); end end );[/lua]
Wait... so... what? Kinda confused here :/ Can you put the code together for me with the hook you added and such? And once I put the big code in lua>autorun>client where do I put that smaller "as cs lua" file? Please be thorough and specific! Thanks :rolleyes:
[QUOTE=Samg381;39878040]I searched other topics like this and all of the code is outdated and won't work[/QUOTE] Really? Page 2 of this section of the forum, and the scripts are two days old. [url]http://facepunch.com/showthread.php?t=1251075[/url]
[QUOTE=zapha;39885990]Really? Page 2 of this section of the forum, and the scripts are two days old. [url]http://facepunch.com/showthread.php?t=1251075[/url][/QUOTE] I'm looking for a code that: 1) Works. 2) Doesn't open up the Steam browser, yet opens up a GUI Similar to the ULX MOTD.
[QUOTE=Samg381;39894377]I'm looking for a code that: 1) Works. 2) Doesn't open up the Steam browser, yet opens up a GUI Similar to the ULX MOTD.[/QUOTE] Dude. [lua]local donate = { ["URL"] = "http://www.google.com/"; }; function donate.CreatePanel( ) local w = 800; -- Width local h = 600; -- Height local p = 8; -- Padding donate.Frame = vgui.Create( "DFrame" ); donate.Frame:SetTitle( "Donate" ); donate.Frame:SetSize( w + (p * 2), h + (p * 5) ); donate.Panel = vgui.Create( "DPanel", donate.Frame ); donate.Panel:SetPos( 8, 32 ); donate.Panel:SetSize( w, h ); donate.HTML = vgui.Create( "HTML", donate.Panel ); donate.HTML:SetPos( 8, 8 ); donate.HTML:SetSize( w - (p * 2), h - (p * 2) ); donate.HTML:OpenURL( donate.URL ); donate.Frame:Center(); donate.Frame:MakePopup(); end hook.Add( "OnPlayerChat", "DonateCommand", function( ePlayer, sText ) if ( ePlayer ~= LocalPlayer() ) then return; end if ( string.StartWith( string.lower( sText ), "!donate" ) ) then donate.CreatePanel( ); end end );[/lua]
Thanks. No time to install ATM.
worked, thank you.
Sorry, you need to Log In to post a reply to this thread.