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:
info.lua code:
rules.lua code:
core.deproj code:
1 2 3 | <file> <filename>rules.lua</filename> </file> |
1 2 3 4 5 6 | [ "/rules" ] = { Permission = "core.rules" , Handler = HandleRulesCommand, HelpString = " - Show rules" , }, |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | 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 |