Author Topic: Custom command to open a webpage  (Read 33625 times)

0 Members and 1 Guest are viewing this topic.

Offline Prentice

  • Newbie
  • *
  • Posts: 9
  • Karma: 0
Custom command to open a webpage
« on: December 08, 2012, 04:47:40 PM »
Hey,
I was wondering how I could set it so that if someone typed "!donate" for example it would open "http://myurl.com/donate" in a motd type window?
Any support would be appreciated...
Thanks!

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: Custom command to open a webpage
« Reply #1 on: December 10, 2012, 07:05:36 AM »
Code: [Select]
function DonateMOTD( ply, text, _ )

    if ( string.sub( string.lower( text ), 1, 7 ) == "!donate" ) then
local url = "\"http://www.google.com\""
ply:ConCommand( "ulx motd " .. url )
return false
    end

end
hook.Add( "PlayerSay", "DonateMOTD", DonateMOTD )




^^
Not tested.. but it should work?

You could put this in a file and drop it in your garrysmod/lua/autorun/server folder.

Offline Prentice

  • Newbie
  • *
  • Posts: 9
  • Karma: 0
Re: Custom command to open a webpage
« Reply #2 on: December 13, 2012, 09:36:48 AM »
That code just opens my motd :(

Offline bender180

  • Full Member
  • ***
  • Posts: 217
  • Karma: 42
    • Benders Villa
Re: Custom command to open a webpage
« Reply #3 on: December 13, 2012, 11:23:05 AM »
Code: [Select]
function donateCommand( pl, text, teamonly )
    if (text == "!donate") then
    pl:SendLua([[gui.OpenURL("http://myurl.com/donate")]]) -- Change ADDRESS to your chosen page.
    for k, v in pairs(player.GetAll()) do v:ChatPrint( "Player " .. pl:Nick() .. " has donated to the server via !donate" )

end
end
end
hook.Add( "PlayerSay", "Chat", donateCommand )

Like MrPresident said,
You could put this in a file and drop it in your garrysmod/lua/autorun/server folder.
Made community pool and community bowling and for the life of me couldn't tell you why they are popular.
Also made the ttt ulx commands.

Offline Deemony07

  • Newbie
  • *
  • Posts: 3
  • Karma: 0
Re: Custom command to open a webpage
« Reply #4 on: January 11, 2013, 05:33:11 PM »
When i did that. I typed !donate and it didnt open the url. It just said Deemoney07 donated.

Offline nathan736

  • Full Member
  • ***
  • Posts: 143
  • Karma: 4
Re: Custom command to open a webpage
« Reply #5 on: January 16, 2013, 09:30:22 AM »
do you have steam in game on (shift + tab)
a person asked me how to code lua and i said this " its like building a rocket up side down then  realizing you did it all wrong."

Offline LuaTenshi

  • Hero Member
  • *****
  • Posts: 545
  • Karma: 47
  • Just your ordinary moon angel!
    • Mirai.Red
Re: Custom command to open a webpage
« Reply #6 on: January 16, 2013, 01:41:07 PM »
do you have steam in game on (shift + tab)

Yes he does how ever he wants a window to show his donation page when some says "!donate" on his server.

Speaking of the steam in-game menu, what ever happened to being able to open a webpage through a game, it was in Portal 2, but I have never seen it again ever sense...
I cry every time I see that I am not a respected member of this community.

Offline nathan736

  • Full Member
  • ***
  • Posts: 143
  • Karma: 4
Re: Custom command to open a webpage
« Reply #7 on: January 18, 2013, 06:47:30 AM »
im confused can't you do this in gmod ?  ???
a person asked me how to code lua and i said this " its like building a rocket up side down then  realizing you did it all wrong."

Offline LuaTenshi

  • Hero Member
  • *****
  • Posts: 545
  • Karma: 47
  • Just your ordinary moon angel!
    • Mirai.Red
Re: Custom command to open a webpage
« Reply #8 on: January 18, 2013, 07:29:12 AM »
im confused can't you do this in gmod ?  ???

It depends on how you want the webpage to open, how ever I am yet to see a lua function that actually initialises shift+tab and then opens a webpage. How ever you can still open webpages just fine through Gmods GUI.
I cry every time I see that I am not a respected member of this community.

Offline nathan736

  • Full Member
  • ***
  • Posts: 143
  • Karma: 4
Re: Custom command to open a webpage
« Reply #9 on: January 18, 2013, 07:31:13 AM »
oh well i had it working fine on my server a few days ago lol ?
a person asked me how to code lua and i said this " its like building a rocket up side down then  realizing you did it all wrong."

Offline Twiztidkiller

  • Newbie
  • *
  • Posts: 4
  • Karma: 0
Re: Custom command to open a webpage
« Reply #10 on: April 13, 2013, 04:22:36 PM »
I hate to bump, but this thread seemed lik a good spot to ask this question.
I have the above given lua script installed, but when Me and/or my friends use the !donate command, it tosses this into my console.

Code: [Select]
[ERROR] LuaCmd:1: unfinished string near '<eof>'
  1. unknown - LuaCmd:0


Offline nathan736

  • Full Member
  • ***
  • Posts: 143
  • Karma: 4
Re: Custom command to open a webpage
« Reply #11 on: April 15, 2013, 08:53:18 AM »
its because you  screwed up the "" so the code cant find the end of the string so it yells <censor>WHAT?!<censor> we cant find the end if this string.... simple error just fix your " "

ps: when ever you get <eof> you 9/10 did something wrong or removed something when your editing existing code like the important things here
 end "string" , -- if for
pss: heres a easier version to work with

local myurl = "http://www.google.com"     -- "http://YOUR-URL.com"
function donateCommand( pl, text, teamonly )
          if (text == "!donate") then
             pl:SendLua([[gui.OpenURL(myurl)]]) -- Change ADDRESS to your chosen page.
             for k, v in pairs(player.GetAll()) do v:ChatPrint( "Player " .. pl:Nick() .. " has donated to the server via !donate" )

      end
   end
end
hook.Add( "PlayerSay", "Chat", donateCommand )
« Last Edit: April 15, 2013, 02:21:29 PM by JamminR »
a person asked me how to code lua and i said this " its like building a rocket up side down then  realizing you did it all wrong."

Offline Twiztidkiller

  • Newbie
  • *
  • Posts: 4
  • Karma: 0
Re: Custom command to open a webpage
« Reply #12 on: April 15, 2013, 12:35:22 PM »
Ahh, ok. So then, with my current code being this.
Code: [Select]
function donateCommand( pl, text, teamonly )
    if (text == "!donate") then
    pl:SendLua([[gui.OpenURL(http://cur.lv/mifq)]]) -- Change ADDRESS to your chosen page.
    for k, v in pairs(player.GetAll()) do v:ChatPrint( "Player " .. pl:Nick() .. " has considered donating $1.00 to the cause!" )

end
end
end
hook.Add( "PlayerSay", "Chat", donateCommand )

I would instead want this.
Code: [Select]
function donateCommand( pl, text, teamonly )
    if (text == "!donate") then
    pl:SendLua([[gui.OpenURL("http://myurl.com/donate")]]) -- Change ADDRESS to your chosen page.
    for k, v in pairs(player.GetAll()) do v:ChatPrint( "Player " .. pl:Nick() .. " has donated to the server via !donate" )

end
end
end
hook.Add( "PlayerSay", "Chat", donateCommand
)
I notice the bottom *correct* one has both of these "", which I'm guessing makes the difference?

Offline nathan736

  • Full Member
  • ***
  • Posts: 143
  • Karma: 4
Re: Custom command to open a webpage
« Reply #13 on: April 16, 2013, 08:27:57 AM »
yeah that would fix it  you MUST have the "" or your not  telling it a url(a string) your telling it a var (which im 90% would throw a billion errors anyways)
a person asked me how to code lua and i said this " its like building a rocket up side down then  realizing you did it all wrong."

An Error Has Occurred!

array_keys(): Argument #1 ($array) must be of type array, null given