gui.OpenURL not opening when I type the set command (Broken Code!)
7 replies, posted
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 [code] 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 :)
[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]
[QUOTE=Coffeee;45186131]I made this for some guy earlier today. (Coincidence?)
[lua]
util.AddNetworkString( "openwebsite" )
[/lua][/QUOTE]
that'll cause a lua error since it's invalid clientside, fyi
[editline]22nd June 2014[/editline]
[code]if SERVER then util.AddNetworkString( "openwebsite" ) end[/code]
Delete this post
Sorry, you need to Log In to post a reply to this thread.