gui.OpenURL not opening when I type the set command (Broken Code!)

hook.Add( “PlayerSay”, “OpenURL”, function( ply, text, public )
local args = string.Explode( " ", text )

if args[1] == “!workshop” then
gui.OpenURL( “http://steamcommunity.com/sharedfiles/filedetails/?id=199805963” )
end
end )

This code looks fine to me but when I type “!workshop” the URL does not open?

You need to wrap your code in


 tags.

Where are you placing the code?

Do you get any client or server errors?

PlayerSay is a server-only hook, and gui is client only. You’re going to have to network the command to open the url to the client.

Can someone give me some working code?

And I have it in lua/autorun

Spon feeding is fun :slight_smile:
[lua]if SERVER then
util.AddNetworkString( “OpenUrl” )

hook.Add( “PlayerSay”, “OpenURL”, function( ply, text, public )
local args = string.Explode( " ", text )
if string.lower(args[1]) == “!workshop” then
net.Start( “OpenUrl” )
net.WriteString( “http://steamcommunity.com/sharedfiles/filedetails/?id=199805963” )
net.Send( ply )
end
end )
else
net.Receive( “OpenUrl”, function()
URL = net.ReadString()
if URL == nil then return end
gui.OpenURL( URL )
end )
end[/lua]
Typed on phone, should work but may have 1 or 2 typo’s :v:

I made this for some guy earlier today. (Coincidence?)
[lua]
util.AddNetworkString( “openwebsite” )

if CLIENT then
net.Receive(‘openwebsite’,function(len)
local url = (net.ReadString() or ‘http://error.com’)
gui.OpenURL(‘http://google.com/’)
end)
end

function Chatss(ply, text)
if (string.sub(text, 1, 6) == “/forum”) then
net.Start(‘openwebsite’)
net.WriteString(‘http://forum.com’)
net.Send(ply)
return false
end
if (string.sub(text, 1, 7) == “/donate”) then
net.Start(‘openwebsite’)
net.WriteString(‘http://donatelink.com’)
net.Send(ply)
return false
end
end
hook.Add(‘PlayerSay’, ‘adlwaofkoekxxxxf90we213e’, Chatss)
[/lua]

that’ll cause a lua error since it’s invalid clientside, fyi

[editline]22nd June 2014[/editline]


if SERVER then util.AddNetworkString( "openwebsite" ) end

Delete this post