1
0

Added missing "Colors", Documented the code + Cleanup.

git-svn-id: http://mc-server.googlecode.com/svn/trunk@1654 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
nielsbreu@gmail.com 2013-07-06 18:24:33 +00:00
parent daff3ca687
commit 4b18fd2eb1

View File

@ -3,8 +3,12 @@ function HandleMOTDCommand( Split, Player )
return true return true
end end
function LoadMotd() function LoadMotd()
local File = io.open("motd.txt", "r") local File = io.open("motd.txt", "r")
-- Check if the file 'motd.txt' exists, else create it.
if not File then if not File then
CreateFile = io.open("motd.txt", "w") CreateFile = io.open("motd.txt", "w")
CreateFile:write("@6Welcome to the MCServer test server!\n@6http://www.mc-server.org/\n@6Type /help for all commands") CreateFile:write("@6Welcome to the MCServer test server!\n@6http://www.mc-server.org/\n@6Type /help for all commands")
@ -14,58 +18,80 @@ function LoadMotd()
end end
for line in io.lines("motd.txt") do for line in io.lines("motd.txt") do
local TempMessage = line local TempMessage = line
-- Do a for loop that goes to each char in the line.
for I=1, string.len(TempMessage) do for I=1, string.len(TempMessage) do
-- If the char is a '@' then check if the next char represents a color.
if string.sub(TempMessage, I, I) == "@" then if string.sub(TempMessage, I, I) == "@" then
local Color, Char = ReturnColor(TempMessage, string.sub( TempMessage, I + 1, I + 1 )) local Char = string.sub(TempMessage, I + 1, I + 1)
if (Color ~= "") then local Color = ReturnColorFromChar(TempMessage, Char)
-- If the next char represented a color then put the color in the string.
if (Color ~= nil) then
TempMessage = string.gsub(TempMessage, "@" .. Char, Color) TempMessage = string.gsub(TempMessage, "@" .. Char, Color)
end end
end end
end end
-- Add the message to the list of messages.
Messages[#Messages + 1] = TempMessage Messages[#Messages + 1] = TempMessage
end end
end end
function ShowMOTDTo( Player ) function ShowMOTDTo( Player )
for I=1, #Messages do for I=1, #Messages do
Player:SendMessage(Messages[I]) Player:SendMessage(Messages[I])
end end
end end
function ReturnColor( Split, char )
function ReturnColorFromChar( Split, char )
-- Check if the char represents a color. Else return nil.
if char == "0" then if char == "0" then
return cChatColor.Black, 0 return cChatColor.Black
elseif char == "1" then elseif char == "1" then
return cChatColor.Navy, 1 return cChatColor.Navy
elseif char == "2" then elseif char == "2" then
return cChatColor.Green, 2 return cChatColor.Green
elseif char == "3" then elseif char == "3" then
return cChatColor.Blue, 3 return cChatColor.Blue
elseif char == "4" then elseif char == "4" then
return cChatColor.Red, 4 return cChatColor.Red
elseif char == "5" then elseif char == "5" then
return cChatColor.Purple, 5 return cChatColor.Purple
elseif char == "6" then elseif char == "6" then
return cChatColor.Gold, 6 return cChatColor.Gold
elseif char == "7" then elseif char == "7" then
return cChatColor.LightGray, 7 return cChatColor.LightGray
elseif char == "8" then elseif char == "8" then
return cChatColor.Gray, 8 return cChatColor.Gray
elseif char == "9" then elseif char == "9" then
return cChatColor.DarkPurple, 9 return cChatColor.DarkPurple
elseif char == "a" then elseif char == "a" then
return cChatColor.LightGreen, "a" return cChatColor.LightGreen
elseif char == "b" then elseif char == "b" then
return cChatColor.LightBlue, "b" return cChatColor.LightBlue
elseif char == "c" then elseif char == "c" then
return cChatColor.Rose, "c" return cChatColor.Rose
elseif char == "d" then elseif char == "d" then
return cChatColor.LightPurple, "d" return cChatColor.LightPurple
elseif char == "e" then elseif char == "e" then
return cChatColor.Yellow, "e" return cChatColor.Yellow
elseif char == "f" then elseif char == "f" then
return cChatColor.White, "f" return cChatColor.White
else elseif char == "k" then
return "" return cChatColor.Random
elseif char == "l" then
return cChatColor.Bold
elseif char == "m" then
return cChatColor.Strikethrough
elseif char == "n" then
return cChatColor.Underlined
elseif char == "o" then
return cChatColor.Italic
elseif char == "r" then
return cChatColor.Plain
end end
end end