Add timer to HTML

I was wondering how I could add a timer to
[lua]CATEGORY_NAME = “Site Links”

// D4nny
function ulx.d4nny(ply)
ply:SendLua([[
HTMLTest = vgui.Create(“HTML”)
HTMLTest:SetPos(50,50)
HTMLTest:SetSize(ScrW() - 100, ScrH() - 100)
HTMLTest:OpenURL(“http://www.garrysmod.com”)
]])
end
local d4nny = ulx.command( CATEGORY_NAME, “ulx d4nny”, ulx.d4nny, “!d4nny” )
d4nny:defaultAccess( ULib.ACCESS_SUPERADMIN )
d4nny:help( “Torture an innocent soul!” )
[/lua]
I would like to make it so the admins could put something like !d4nny playername seconds and I think it has something to do with timer.simple but I am not sure. Any advice and help is greatly appreciated :slight_smile:

All the info is there, assuming you know Lua, you just need to repeat the timer once so it only runs once, then feed in the number of seconds

First of all, 99% of the time you shouldn’t be using Player.SendLua. Try rewriting this using net messages. I’ve never used ULX, but hopefully the following will point you in the right direction:

[lua]AddCSLuaFile()

local CATEGORY_NAME = ‘Site Links’

if SERVER then

util.AddNetworkString('OpenSiteLink')


function ulx.d4nny(ply, seconds)
	net.Start('OpenSiteLink')
		net.WriteUInt(seconds, 32)
	net.Send(ply)
end


-- I have no idea how ULX works, you'll have to figure out whether this is 
-- right place to put this code
local d4nny = ulx.command( CATEGORY_NAME, "ulx d4nny", ulx.d4nny, "!d4nny" )
d4nny:defaultAccess( ULib.ACCESS_SUPERADMIN )
d4nny:help( "Torture an innocent soul!" )

else – CLIENT

net.Receive('OpenSiteLink', function ()
	local seconds = net.ReadUInt(32)


	-- Show the html after the time specified
	timer.Simple(seconds, function ()
		local html = vgui.Create('HTML')
		html:SetSize(ScrW() - 100, ScrH() - 100)
		html:OpenURL('http://garrysmod.com/')
		html:MakePopup()
		html:Center()
	end)
end )

end[/lua]

This was close but it doesnt seem to have worked. Nice try though :slight_smile:

[editline]7th June 2014[/editline]

So far I have managed to fix it not showing up in the categories section.
[lua]AddCSLuaFile()

CATEGORY_NAME = ‘Site Links’

if SERVER then

util.AddNetworkString('OpenSiteLink')


function ulx.d4nny(ply, seconds)
	net.Start('OpenSiteLink')
		net.WriteUInt(seconds, 32)
	net.Send(ply)
end

else – CLIENT

net.Receive('OpenSiteLink', function ()
	local seconds = net.ReadUInt(32)


	-- Show the html after the time specified
	timer.Simple(seconds, function ()
		local html = vgui.Create('HTML')
		html:SetSize(ScrW() - 100, ScrH() - 100)
		html:OpenURL('http://garrysmod.com/')
		html:MakePopup()
		html:Center()
	end)
end )

end

local d4nny = ulx.command( CATEGORY_NAME, "ulx d4nny", ulx.d4nny, "!d4nny" )
d4nny:defaultAccess( ULib.ACCESS_SUPERADMIN )
d4nny:help( "Torture an innocent soul!" )[/lua]

The remaining issues are that it doesnt let you select an amount of time to keep the HTML up for and the HTML isn’t coming up at all. There are not lua errors showing up.

Bump for help <3