Modifying the ULX MOTD to have accept and decline buttons.

I am trying to modify the MOTD script for my server to give players an option to accept and decline to follow the rules, but I am having some problems.

[lua]
ulx.motdmenu_exists = true

local isUrl
local url

function ulx.showMotdMenu()
local window = vgui.Create( “DFrame” )
if ScrW() > 640 then – Make it larger if we can.
window:SetSize( ScrW()*0.9, ScrH()*0.9 )
else
window:SetSize( 640, 480 )
end
window:Center()
window:SetTitle( “ULX MOTD” )
window:SetVisible( true )
window:MakePopup()

local html = vgui.Create( "HTML", window )

local button = vgui.Create( "DButton", window )
button:SetText( "I agree." )
button.DoClick = function() 
end
button:SetSize( 200, 40 )
button:SetPos( (window:GetWide() - button:GetWide()) / 3, window:GetTall() - button:GetTall() - 10 )    

local button2 = vgui.Create( "DButton", window )
button2:SetText( "I do not agree." )
button2.DoClick = function() 
ulx.jail( "(Console)", ply:Name, 120 );
window:Close();
ply:ChatPrint("You must agree to follow our rules!");
timer.Create("timer1", 120, 1, "ulx motd")
end
button2:SetSize( 200, 40 )
button2:SetPos( (window:GetWide() - button2:GetWide()) / 1.5, window:GetTall() - button2:GetTall() - 10 )    

html:SetSize( window:GetWide() - 20, window:GetTall() - button2:GetTall() - 50 )
html:SetPos( 10, 30 )
if not isUrl then
    html:SetHTML( file.Read( "ulx/motd.txt" ) )
else
    html:OpenURL( url )
end

end

function ulx.rcvMotd( isUrl_, text )
isUrl = isUrl_
if not isUrl then
file.Write( “ulx/motd.txt”, text )
else
url = “http://” … text
end
end
[/lua]

I don’t know if I am doing it even close to how it works, but could someone help me out please :ohdear:

Here is the errors which are displayed ingame:
[lua]
ULib/client/cl_util.lua:21: Received bad RPC, invalid function (ulx.rcvMotd)!
ULib/client/cl_util.lua:21: Received bad RPC, invalid function (ulx.showMotdMenu)!
[/lua]
Also the motd menu does not show unless I remove:
[lua]
ulx.jail( “(Console)”, ply:Name, 120 ); ply:ChatPrint(“You must agree to follow our rules!”);
timer.Create(“timer1”, 120, 1, “ulx motd”)
[/lua]

$5 plz

Why?

It doesn’t seem so hard to do in concept as it is just on button press, put the player into jail for 120 seconds and then after 120 seconds display the MOTD again.

Anyone have any ideas?

That’s retarded, just use your admin for a person that is not abiding by the rules, or just make it so the MOTD won’t close for 60 seconds so they are forced to at least look over it.

Anyone who has anything relating to helping me with the problem?

The MOTD is being run clientside from what I can see and you are trying to run a serverside command called ulx.jail and your not using the timer correctly.

One way could be creating another ulx jail command except it only jails yourself. So you would have something like RunConsoleCommand(“ulx”, “jailme”, “120”).

[lua]
ulx.motdmenu_exists = true

local isUrl
local url

function ulx.showMotdMenu()
local window = vgui.Create( “DFrame” )
if ScrW() > 640 then – Make it larger if we can.
window:SetSize( ScrW()*0.9, ScrH()*0.9 )
else
window:SetSize( 640, 480 )
end
window:Center()
window:SetTitle( “ULX MOTD” )
window:SetVisible( true )
window:MakePopup()

local html = vgui.Create( "HTML", window )

local button = vgui.Create( "DButton", window )
button:SetText( "I agree." )
button.DoClick = function() 
window:Close()
end
button:SetSize( 200, 40 )
button:SetPos( (window:GetWide() - button:GetWide()) / 3, window:GetTall() - button:GetTall() - 10 )    

local button2 = vgui.Create( "DButton", window )
button2:SetText( "I do not agree." )
button2.DoClick = function() 
//ulx.jail( "(Console)", ply:Name, 120 ); -- You need to use something available on the client.
window:Close();
ply:ChatPrint("You must agree to follow our rules!");
timer.Create("OpenMOTD", 120, 1, function() RunConsoleCommand("ulx", "motd") end)
end
button2:SetSize( 200, 40 )
button2:SetPos( (window:GetWide() - button2:GetWide()) / 1.5, window:GetTall() - button2:GetTall() - 10 )    

html:SetSize( window:GetWide() - 20, window:GetTall() - button2:GetTall() - 50 )
html:SetPos( 10, 30 )
if not isUrl then
    html:SetHTML( file.Read( "ulx/motd.txt" ) )
else
    html:OpenURL( url )
end

end

function ulx.rcvMotd( isUrl_, text )
isUrl = isUrl_
if not isUrl then
file.Write( “ulx/motd.txt”, text )
else
url = “http://” … text
end
end
[/lua]

Okay thanks so much for the help, I’ll have a go at it.

You could use datastream to send a message to the server to run the command.

Thanks I will look into them :smile:

Dumb suggestion, when you can use a concommand to send it. Since the datastream (to the server) uses concommands anyway.

I am confused now :s

Basically, don’t use datastream, it is just a wrapper that uses console commands anyway. You are better off using console commands in this situation.

Okay I decided to do this instead:

[lua]
ulx.motdmenu_exists = true

local isUrl
local url

function ulx.showMotdMenu()
local window = vgui.Create( “DFrame” )
if ScrW() > 640 then – Make it larger if we can.
window:SetSize( ScrW()*0.9, ScrH()*0.9 )
else
window:SetSize( 640, 480 )
end
window:Center()
window:SetTitle( “ULX MOTD” )
window:SetVisible( true )
window:MakePopup()

local html = vgui.Create( "HTML", window )

local button = vgui.Create( "DButton", window )
button:SetText( "I agree." )
button.DoClick = function() 
window:Close()
end
button:SetSize( 200, 40 )
button:SetPos( (window:GetWide() - button:GetWide()) / 3, window:GetTall() - button:GetTall() - 10 )    

local button2 = vgui.Create( "DButton", window )
button2:SetText( "I do not agree." )
button2.DoClick = function() 
window:Close();
    timer.Create("sound2", 50, 1, function() RunConsoleCommand("play", "npc/overwatch/radiovoice/attentionyouhavebeenchargedwith.wav") end)
        timer.Create("sound3", 52, 1, function() RunConsoleCommand("play", "npc/overwatch/radiovoice/violationofcivictrust.wav") end)
            timer.Create("sound4", 54, 1, function() RunConsoleCommand("play", "npc/overwatch/radiovoice/youarejudgedguilty.wav") end)
                timer.Create("sound5", 58, 1, function() RunConsoleCommand("play", "HL1/fvox/near_death.wav") end)
                    timer.Create("sound6", 62, 1, function() RunConsoleCommand("play", "HL1/fvox/voice_off.wav") end)
                        timer.Create("sound1", 70, 1, function() RunConsoleCommand("play", "npc/stalker/go_alert2a.wav") end)
                            timer.Create("kill", 70, 1, function() RunConsoleCommand("kill") end)
timer.Create("OpenMOTD", 71, 1, function() RunConsoleCommand("ulx", "motd") end)
end
button2:SetSize( 200, 40 )
button2:SetPos( (window:GetWide() - button2:GetWide()) / 1.5, window:GetTall() - button2:GetTall() - 10 )    

html:SetSize( window:GetWide() - 20, window:GetTall() - button2:GetTall() - 50 )
html:SetPos( 10, 30 )
if not isUrl then
    html:SetHTML( file.Read( "ulx/motd.txt" ) )
else
    html:OpenURL( url )
end

end

function ulx.rcvMotd( isUrl_, text )
isUrl = isUrl_
if not isUrl then
file.Write( “ulx/motd.txt”, text )
else
url = “http://” … text
end
end
[/lua]

Thanks for everyone’s help!

Cookies?