Not sure if this goes here but I thought I would create a function to display server rules and decided to use the motd function from core as a template for it since it basically does the same thing. Now I've added it to the core.deproj file, info.lua file, and created a rules.lua file with some modifications. Everything works except one thing, it reads from the motd.txt and doesn't create rules.txt like I wanted it to. Is there something I'm missing like a variable defined elsewhere? I would also like to add I'm completely new here and just started using this today because I despise java and am so happy I found a C++ alternative. I'm also completely new to LUA but I do have a little knowledge in C++, PHP, and JS/jQuery so I'm not completely dumb.
core.deproj code:
core.deproj code:
<file> <filename>rules.lua</filename> </file>info.lua code:
["/rules"] = { Permission = "core.rules", Handler = HandleRulesCommand, HelpString = " - Show rules", },rules.lua code:
function HandleRulesCommand( Split, Player ) ShowRulesTo( Player ) return true end function LoadRules() local File = io.open( "rules.txt", "r" ) -- Check if the file 'rules.txt' exists, else create it. if not File then CreateFile = io.open( "rules.txt", "w" ) CreateFile:write("@6Server Rules") CreateFile:close() else File:close() end for line in io.lines( "rules.txt" ) do local TempMessage = line -- Do a for loop that goes to each char in the line. 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 local Char = string.sub( TempMessage, I + 1, I + 1 ) 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 ) end end end -- Add the message to the list of messages. Messages[#Messages + 1] = TempMessage end end function ShowRulesTo( Player ) for I=1, #Messages do Player:SendMessage(Messages[I]) end end