HTML Interacting With Lua

My question is if it’s possible for HTML to send commands to lua code running on a garrysmod server in a fast and efficient manner.

So one example of this would be if you had an MOTD with no buttons. And inside of it was displayed a webpage. On the webpage you would click a button that would send a message to the Derma built MOTD to close. Basically I’m looking for a way to force players to read the rules. And I think it would be cool to have a hidden button in the rules that they had to click to close the MOTD.

If you think it’s possible, or you have some wiki links or knowledge that could help it would be much appreciated if you responded.

You’re probably looking for DHtml.AddFunction.
Honestly, though, I find forcing people to read the rules counter-productive. They want to play, and if you don’t let them (i.e. if you plan to make the button hidden in text), they’ll just connect to another server.
I believe there’s also some console command to close all active panels.

On your HTML panel, call SetAllowLua( true ).

In your code, put

console.log( "RUNLUA:" + command )

Where command is the code you desire to run.


console.log( "RUNLUA:CloseMOTD( )" );

Where CloseMOTD is a global function in your client code.

Thanks for reply. It’s less about how practical that particular example is, and more about the idea behind the project. I think it would be cool to get HTML and LUA working together. It is a fun personal project for me.

That function sounds very useful thank you.