How do you create in game commands that lead to links?

Im wondering how to create in game commands such as !donate that leads to a steam overlay link

Anyone know how?

Ive done it before but I cant remember how

GM:PlayerSay() runs every time a player sends a chat message.

gui.OpenURL() opens any URL in the Steam Overlay (Shift+Tab)

You can probably figure everything else out from there.

I’ve got you, I just recently figured this out using ULX:

Create a folder in your addons directory, call it ‘Aliases’ or something.
In \addons\Aliases\lua\ulx\modules\sh create a new .lua file.
In that lua file, create something that looks like this:



--Website
function ulx.website( calling_ply ) -- Name of the Function, calling_ply is the variable

  calling_ply:SendLua([[gui.OpenURL("http://website.domain")]]) --This is the command that is run by the user when it is triggered

end
local website = ulx.command( "Links", "ulx website", ulx.website, { "!website", "!homepage", "/website", "/homepage" } ) --Names of the ULX entry/command followed by the chat commands
website:defaultAccess( ULib.ACCESS_ALL ) --Gives everyone access by default
website:help( "Opens Website" ) --Description


You can do this for other chat commands like !donate, !forums, and even stuff that isn’t website related like !pac that executes:



  calling_ply:ConCommand( "pac_editor" )


Doing it this way registers a ulx console command (i.e. ‘ulx website’) as well as adds an XGUI section called ‘links’ and places a button called ‘website’ in that section. All of these avenues opens the website in the steam shift+tab browser.

What’s up with the dumb ratings? Just trying to help somebody out.

:tried:

That’s just Sir TE5T, he does that a lot, I wouldn’t worry about it.

I don’t like spoon feeding but… In a new file called cl_commands (in /lua/autorun) put this:


function Commands( ply, text, team )
    -- 1, 7 is when you want it to start. So if you do 2, 5 then if someone says "hi friend" H is removed, and it is only reading i friend because its starting at the 2nd value, just copy and paste ELSEIF to add more commands. Thanks - Jacob.
    if ( string.sub( text, 1, 7 ) == "!donate" ) then
        gui.OpenURL( "http://garrysmodserver/donate" )
    elseif ( string.sub( text, 1, 5 ) == "!youtube" ) then
         gui.OpenURL( "http://youtube.com" )
    end

end
hook.Add( "OnPlayerChat", "Commands", Commands) 

gui.OpenURL is CLIENTSIDE, so you need to be using

GM:OnPlayerChat in a CLIENTSIDE file instead

Oh yeah, sorry. I did say, untested.



hook.Add( "OnPlayerChat", "OpenSomeWebsite", function( ply, strText, bTeam, bDead )
    if strText == '!donate' and ply == LocalPlayer() then
        gui.OpenURL( "http://garrysmodserver/donate" )
    end
end )


[editline]29th August 2016[/editline]

automerge failed me again