Display motd when player types a word

I use the motd_menu addon and recently the !motd command no longer displays the motd menu.

Here’s the code i have in sv_motd.lua:


AddCSLuaFile("autorun/client/motd.lua")

function MOTDMenuPopup(ply)
	ply:ConCommand("showmotdmenu")
end

hook.Add("PlayerInitialSpawn", "MOTDMenuPopup", MOTDMenuPopup)

function ChatMOTDMenuPopup(ply, text)
	local prefixs = {"!rules", "/rules", "!motd", "/motd"}
	local command = string.Explode(" ", text)[1]
	for _, v in pairs(prefixs) do
		if string.lower(command) == v  then
			ply:ConCommand("showmotdmenu")
		end
	end
end

hook.Add("PlayerSay", "ChatMOTD", ChatMOTDMenuPopup)

Any idea why it stopped working and how to fix it? Thanks in advance.

I’ve done a lot with chat-commands, but I’ve found the best way to deal with them is to redirect them directly to concommands.

so ! is said publicly, and / is done privately.

Ways to detect commands being entered:
[lua] local _bSlash = string.sub( text, 1, 1 ) == “/”;;
local _bExclaim = string.sub( text, 1, 1 ) == “!”;

local _bSlash = string.StartWith( text, "/" );
local _bExclaim = string.StartWith( text, "!" );[/lua]

And what I use now:
[lua] //
// Do /commands privately, !commands publicly
//
local _bSlash = string.StartWith( text, “/” );
local _bExclaim = string.StartWith( text, “!” );
if ( _bSlash || _bExclaim ) then
Player:ConCommand( string.sub( text, 2 ) );
if ( !_bExclaim ) then
return “”;
end
end[/lua]

The beauty of using ConCommand is that spaces are already interpreted as breaks, so each new word is a new argument for the function. You can add motd by simply doing:

[lua]concommand.Add( “motd”, function( ply, cmd, args )
// Open it
end );[/lua]

If you want to hide the concommands a little better, simple add salt / pepper ( a string before and/or after the string.sub( text, 2 ) in the ConCommand line, then add the same to each new concommand you add )

What about say commands though? The console command is working fine, its the say commands that broke.

I pasted the code; if you add that to GM:PlayerSay or simply hook it, it’s all that needs to be done. Remember, PlayerSay is SERVER-side.

[lua]hook.Add( “PlayerSay”, “Acecool:ChatToConCommands”, function( Player, text, private )
//
// Do /commands privately, !commands publicly
//
local _bSlash = string.StartWith( text, “/” );
local _bExclaim = string.StartWith( text, “!” );
if ( _bSlash || _bExclaim ) then
Player:ConCommand( string.sub( text, 2 ) );
if ( !_bExclaim ) then
return “”;
end
end
end );[/lua]

Just by putting that into the server autorun it’ll forward ! and / commands to concommands.

Example: if I were to type “!motd”, it would try executing that concommand and everyone would see; if I were to type “/motd” it would try executing the same concommand, but it’s suppressed; no one sees the text.

Ah cool, thanks!