prop link to a website

Do anyone know how to script a code that link to a website with that i mean

take a prop like the newspaper prop then when you press e on that a motd thing will popup but its not link to a motd its link to a website so you can make a news paper to your server for like half life 2 rp or some other gamemode can some one script this mode and send back a replay?

**[Gamemode.PlayerUse

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=Gamemode.PlayerUse)**

Enjoy!

yeah but i suck at scripting -.- so i don’t know how to set this up

Then go into the request section and do a fine request about it.

Did it ever occur to you that you should learn Lua before asking for technical help with Lua?

I dont normally use SendLua but i dont see why not in this situation

Serverside (Entity):
[lua]ENT:Use(ply, act)
ply:SendLua(“OpenNews()”)
end[/lua]

Clientside (Autorun):
[lua]function OpenNews()
local pane = {}

pane.head = vgui.Create( “DFrame” )
pane.head:SetSize(ScrW()-10, ScrH()-10)
pane.head:Center()
pane.head:SetTitle(“Newspaper”)
pane.head:SetVisible(true)
pane.head:SetDraggable(false)
pane.head:ShowCloseButton(true)
pane.head:MakePopup()

pane.obj = vgui.Create(“HTML”, pane.head)
pane.obj:SetSize(ScrW()-40, ScrH()-40)
pane.obj:Center()
pane.obj:OpenURL(“http://www.google.com/”)
end[/lua]

Now Science, what if he wants too open a different website? Also, why send 10 bytes when you can send 4? However, I’ll send more to allow more functionality.

[lua]if SERVER then
AddCSLuaFile(“path/to/this/file.lua”)

function _R.Player:OpenURL(url,desc,width,height)
	umsg.Start("OpenURL" , self)
		umsg.String(url)
		umsg.String(desc)
		if width and height then
			umsg.Bool(true)
			umsg.Char(width)
			umsg.Char(height)
		end
		
	umsg.End()
end
return

end

usermessage.Hook(“OpenURL” , function(um)
local url,desc = um:ReadString(),um:ReadString()
local setSize = umsg:ReadBool()
local width,height = 650,400
if setSize then
width,height = um:ReadChar(),um:ReadChar()
end

local frame = vgui.Create("DFrame")
frame:SetSize(width,height)
frame:SetTitle(desc)
frame:Center()
frame:MakePopup()

local html = vgui.Create("HTML" , frame)
html:SetPos(0,22)
html:SetSize(width,height-22)
html:OpenURL(url)
html:StartAnimate(100)

end )[/lua]

And then you could just call self.Owner:OpenURL in the use function.

SendLua really isn’t a big deal in most situations, the issue is that it doesn’t take much more effort to just use usermessages, and if you use usermessages, there’s a lot more reliability and you’re able to send parameters, which makes them an all around better choice.

He gave no specifications so I think a basic script like this is all he needs.

Also, why didn’t you tell me that sending 6 extra bytes is the end of the world!
If he wants a script with more functionality he should learn some simple Lua.

[editline]3rd November 2011[/editline]

yea but I was about to come off my pc so I had to rush.

It took me 3 minutes to write a script with 10x more functionality than yours, with 5x less mistakes.

Good for you.
Is he expected to know how to use that?

Just because he gave no specifications doesn’t invalidate the fact that you should be using usermessages rather than SendLua()

And just because you’re leaving your PC and rushing to reply doesn’t excuse you from having your bad advice criticized.

yes, it’s basic lua. People are capable of reading, you know?

[editline]3rd November 2011[/editline]

Then again, I’m saying that to you. Exceptions to all rules I suppose.

I don’t want to be rude but I think it’s in everyone’s best interests if Science just didn’t help people

You’re using a char, so your width and height are limited to 128?

Wouldn’t it be 256?

128 is the maximum bit value, a char is a byte, which is 256 possible values afaik

umsg.Char is a signed byte. It can contain values from -128 to 127. Unsigning it will allow the value to range from 0 to 255. To unsign it:

[lua]
if SERVER then
umsg.Start(“blah”)
umsg.Char(value - 128)
umsg.End()
else
usermessage.Hook(“blah”, function(um)
local value = um:ReadChar() + 128
end)
end
[/lua]

[editline]4th November 2011[/editline]

Also a better idea would be to use gui.OpenURL to open it.

**[Gui.OpenURL

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Gui.OpenURL)**

Ahh that’s cool. Why are they signed by default though?

When would you need to send a negative char value?

Most networking libraries offer the ability to send either. They’re all unsigned when they go through however, so it’s either at a Valve or Garry end where they’re being signed.

[editline]moreinfo[/editline]

You can easily rework the usermessage library to send unsigned ones by default.

[lua]
if SERVER then
function umsg.UChar( c )
umsg.Char( c - 128 )
end

function umsg.UShort( s )
	umsg.Short( s - 32768 )
end

elseif CLIENT then
function _R.bf_read:ReadUChar()
return ( self:ReadChar() + 128 )
end

function _R.bf_read:ReadUShort()
	return ( self:ReadShort() + 32768 )
end

end
[/lua]

Oh, forgot about the sizes. Still 3x less mistakes than Science made though.