motd that only pops up once, until updated?

how would i go about having a menu that pops up once, and then doesn’t popup again until the menu is updated?

E.I i have a MOTD that you only have to look at once, and it wouldn’t pop up again, but if it is updated, it would appear again.

What do you mean updated? Like part of the code changed?

I would have the version number of the MOTD sent with the net message that opens it, and compare it with a cookie stored on the client. If they aren’t equal, then open the MOTD and set the cookie.

ah, thanks, i should have thought of that lol.

Ninja’d because I was making an example :frowning:

If you are using DHTML to display your motd, you might be able to do this:

function motdbody:ConsoleMessage( txt )
  local b = txt:match( "^VER:(.-)" )

  if b then
    if cookie.GetString( "motd.lastreadversion" ) ~= b then
      self:GetParent( ):MakePopup( )
      self:GetParent( ).ResponseReceived = true
      cookie.Set( "motd.lastreadversion", b )
      self:GetParent( ):Remove( )

And then in your webpage, just put this in the javascript:

console.log( "VER:whatever" );

The important part is that you don’t show the MOTD on its own so it only pops up if they haven’t read it before on their install ( cookies are stored in the sqlite db ), or if your motd page has a new version number.

You’d also want to remove the motd after a couple of seconds if ResponseReceived never becomes true, since that could indicate the MOTD not loading correctly and you don’t want your panel becoming a memory leak.

If you aren’t using a webpage, you can do something similar - store the version number in your code and compare against the cookie value, display if it doesn’t match.

currently my motd is made of just a frame, panel, and a bunch of dlabels. The code is actually pretty messy, and I should probably clean it up a little while I’m doing the cookie thing.

[editline]9th August 2015[/editline]

nvm, i got it working, thanks guys!

i feel pretty stupid for not knowing this, and for some reason I can’t figure it out.

The cookie saves to the server instead of the client for some reason.

Here is the code:

Server Side File:

------------------Open Menu On Join---------------
function TobMOTDMenuPopup(ply)
	if ( IsValid( ply ) and ply:IsPlayer() ) then
		if cookie.GetString( "tobiasxmotdversion.lastreadversion" ) != SERVER_MOTD_VERSION_COOKIE then	
hook.Add("PlayerInitialSpawn", "TobMOTDMenuPopup", TobMOTDMenuPopup)

util.AddNetworkString ( "setMOTDCookie" )
net.Receive ( "setMOTDCookie", function ( messageLength, pl )
	if ( IsValid( pl ) and pl:IsPlayer() ) then
		cookie.Set( "tobiasxmotdversion.lastreadversion", SERVER_MOTD_VERSION_COOKIE )
end )

Client Side:

		Button1.DoClick = function()
			net.Start ("setMOTDCookie")


You have to do cookie.set clientside, if I am right, lol.

I tried that, and it didn’t work :frowning:

Network the cookie version to player on PlayerInitialSpawn, and then Use cookie.Get clientside to check if it matches. If it doesn’t match, open motd and use cookie.Set.

What do you mean by network the cookie version to the player?

AddCSLuaFile( )


if SERVER then
  util.AddNetworkString( "MOTD DISPLAY" )

  local function PlayerInitialSpawn( pl )
    net.Start( "MOTD DISPLAY" )
    net.Send( pl )
  hook.Add( "PlayerInitialSpawn", "MOTD.PlayerInitialSpawn", PlayerInitialSpawn )
  net.Receive( "MOTD DISPLAY", function( )
    if cookie.GetString( "motd.version" ) ~= MOTD_VERSION then
      cookie.SetString( "motd.version", MOTD_VERSION )
      --Display MOTD here
  end )

Would go in lua/autorun