Using Two Commands For One Function

Well I’m making a motd and I’m trying to make it so that when you click one button it’ll close the motd
and make the player send a message whereas if you click the other it’ll simply disconnect you from the
server. I’m having trouble getting a function to run two commands so if anyone can help I’d be grateful.



function webmotdButton2:DoClick( )
   RunConsoleCommand( "say", sButtonDecline);
   RunConsoleCommand( "disconnect" )
end


Note: I didn’t make the MOTD I’m using, I’m editing it with a few more things.

That should work, perhaps the DoClick method is being overwritten somewhere later in the code?

[editline]meh[/editline]
Just created a DButton and tried the code ingame, works fine. Have a close look, you may spot something. If you can’t, post the entire code and I’ll have a look.

There’s 2 buttons, one for agreeing and one for disagreeing, I’ll list them all out:



sButtonAccept = "// I accept and agree to the rules."




function webmotdButton1:DoClick( )
   webframe:Remove( )
   RunConsoleCommand( "say", sButtonAccept);
end




sButtonDecline = "// I decline and disagree to the rules."




function webmotdButton2:DoClick( )
   RunConsoleCommand( "say", sButtonDecline);
   RunConsoleCommand( "disconnect" )
end


Read my edit ^^

Crap I’m completely lost, I’ll paste the code :stuck_out_tongue:



/* Simple WebMOTD v1.10
-- Created by Xenoyia
-- Do NOT re-upload! */

sTitle = "New Life Gaming" //Title of the WebMOTD here. This will show at the top left of the MOTD.
sURL = "http://urgaming.heliohost.org/server-files/JoinMenu/Menu-StartupPage.html" //The URL the WebMOTD shows.
sButtonText1 = "-[By clicking here you Accept and Agree to the Rules]-" //Text to show on the accept button.
sButtonText2 = "-[By clicking here you Decline and Disagree to the Rules]-" //Text to show on the decline button.
sButtonAccept = "// I accept and agree to the rules."
sButtonDecline = "// I decline and disagree to the rules."


function webmotd( ) // DO NOT TOUCH
    local webframe = vgui.Create( "DFrame" ); // DO NOT TOUCH
    webframe:SetTitle( sTitle ) // Edit at the top.
    webframe:SetSize( ScrW() - 57.5, ScrH() - 57.5 )
	webframe:Center() // DO NOT TOUCH UNLESS YOU KNOW WHAT YOU'RE DOING
	webframe:SetDraggable( false )
	webframe:ShowCloseButton( false )
	webframe:SetBackgroundBlur( true )
	webframe:SetVisible( true )
    webframe:MakePopup( ) // DO NOT TOUCH

local webmotdurl = vgui.Create( "HTML", webframe ) // DO NOT TOUCH
webmotdurl:SetPos( 24, 50 )
webmotdurl:SetSize( webframe:GetWide() - 50, webframe:GetTall() - 150 )
webmotdurl:OpenURL( sURL ) // Edit at the top.

local webmotdButton1 = vgui.Create( "DButton", webframe ) // DO NOT TOUCH
webmotdButton1:SetText( sButtonText1 ); // Edit at the top.
webmotdButton1:SetPos( ( webframe:GetWide() / 14 ) - ( webmotdButton1:GetWide() / 2 ), webframe:GetTall() - 92 )
webmotdButton1:SetWide( 280 );
webmotdButton1:SetHeight( 40 );
webmotdButton1:SetCursor("hand");
function webmotdButton1:DoClick( ) // DO NOT TOUCH
   webframe:Remove( )
   RunConsoleCommand( "say", sButtonAccept);
   end

local webmotdButton2 = vgui.Create( "DButton", webframe ) // DO NOT TOUCH
webmotdButton2:SetText( sButtonText2 ); // Edit at the top.
webmotdButton2:SetPos( ( webframe:GetWide() / 14 ) - ( webmotdButton2:GetWide() / 2 ), webframe:GetTall() - 53 )
webmotdButton2:SetWide( 280 );
webmotdButton2:SetHeight( 40 );
webmotdButton2:SetCursor("hand");
function webmotdButton2:DoClick( ) // DO NOT TOUCH
   RunConsoleCommand( "say", sButtonDecline);
   RunConsoleCommand( "disconnect" )
   end
end
concommand.Add( "smotd", webmotd ); // Do NOT edit unless you want a broken WebMOTD.


If you’re saying the problem is that the sButtonDecline text doesn’t show then it’s probably because you’re running disconnect at the same time. Other than that, it seems to work fine for me.

Please explain in detail what the problem you’re experiencing is, if it’s as mentioned above, put a small delay in for the disconnect command.

isn’t it whateverbutton**.DoClick? and not whateverbutton:**DoClick

button.DoClick = function() //stuff end
function button:DoClick() //stuff end

Same thing.

Does “disconnect” work with RunConsoleCommand though? I thought it was one of the blacklisted commands? You may need to use LocalPlayer():ConCommand(“disconnect”)

oh

disconnect works with RunConsoleCommand last I knew

Okay, sorry for taking so long for the reply but here’s some more details:

For the accept button it’s supposed to close the box and then send an OOC message, the box closing works but the message isn’t sent.
For the decline button it’s supposed to send a message then disconnect, the disconnect works but not the OOC message.

I hope this clears things up, and how would I add a delay between the message and disconnect?

[lua]timer.Simple( .3, RunConsoleCommand, “disconnect” )[/lua]

Does anyone have a solution to the chat command on button press? I can’t seem to get it to work.

Just tried the entire code ingame, works fine in sandbox. Try changing your speech strings to something else, or perhaps test it with a completely different console command.