Hugos Posted December 29, 2019 Share Posted December 29, 2019 Hi everyone! Please tell me how to save time to log file when the server is shut down? (It is necessary that at shutdown) PS: fileWrite(create, ...) Link to comment
Moderators Patrick Posted December 29, 2019 Moderators Share Posted December 29, 2019 (edited) https://wiki.multitheftauto.com/wiki/OnResourceStop Its log when the resource stops, make a new resource only for this code. local filePath = "shutdown.log" -- log file path addEventHandler("onResourceStop", resourceRoot, function() -- call this function at resource stop -- logfile not found, create it first. if not fileExists(filePath) then fileCreate(filePath) end -- get the current datetime and make the new line what we want to insert end of the file local DateTime = getRealTime() DateTime.year = DateTime.year + 1900 DateTime.month = DateTime.month + 1 local timeString = ("%d-%02d-%02d %02d:%02d:%02d"):format(DateTime.year, DateTime.month, DateTime.monthday, DateTime.hour, DateTime.minute, DateTime.second) local newLine = "["..timeString.."] Server shutdown!" -- open file local file = fileOpen(filePath) local fileSize = fileGetSize(file) -- length of text in file fileSetPos(file, fileSize) -- move cursor the end of the file (because we want to write to the end of the file) fileWrite(file, newLine.."\n") -- add the new line with linebreak on the end fileClose(file) -- close the file (save) end) Edited December 29, 2019 by stPatrick Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now