-- Synchronised I/O example by LJ Sonic -- The "w" command will write the command arguments to luafiles/iotest.txt -- The "r" command will write the content of luafiles/iotest.txt in the console COM_AddCommand("w", function(player, ...) local args = {...} io.open("iotest.txt", "w", player, function(file, filename) if not file CONS_Printf(player, filename.." cannot be opened.") return end file:write("This is a test file.\n") file:write("It contains the following data:\n") for _, line in ipairs(args) file:write(line, "\n") end end) end, true) local function functionToExecuteOnceEveryoneHasReceivedTheFile(file, filename) if not file print(filename.." cannot be opened.") return end -- We could also use file:lines for the record local line = file:read() while line print(line) line = file:read() end end COM_AddCommand("r", do -- "iotest.txt" is the file name -- "r" means we are reading -- nil means the server will send the file to everyone before using it -- functionToExecuteOnceEveryoneHasReceivedTheFile is... exactly what it says io.open("iotest.txt", "r", nil, functionToExecuteOnceEveryoneHasReceivedTheFile) end)