mgdmgd Posted May 24, 2016 Share Posted May 24, 2016 Anybody can give me a resource that logs all commands when a player write a command for example Mgdmgd :- /help and it gets logged into .txt file so i can check them, please can somebody help me? i really need it. Link to comment
ViRuZGamiing Posted May 24, 2016 Share Posted May 24, 2016 OutputServerLog take a look into this event 'OnPlayerCommand' Link to comment
mgdmgd Posted May 24, 2016 Author Share Posted May 24, 2016 And for example where to log the files? it doesn't show any function to create the .txt file and can you please help me to explain better cause i am not that good with lua Link to comment
Moderators IIYAMA Posted May 24, 2016 Moderators Share Posted May 24, 2016 It does, you just have to search better. https://wiki.multitheftauto.com/wiki/FileCreate In the Netherlands we would call a you a 'blind chicken', although it is just a way of announcing somebody who doesn't search very well. (don't take this personal) -- on the top of your script local newFile = fileCreate("command.log") fileFlush ( newFile ) -- log files require buffers to reduce hard-drive writing. (more performance) -- -- when a player writes a command if (newFile) then fileWrite(newFile, "Log the blind chicken!") end -- -- on resource stop > if (newFile) then fileClose(newFile) end -- Link to comment
mgdmgd Posted May 24, 2016 Author Share Posted May 24, 2016 Ammm can guys somebody give me a full code please? i am really noob at it Link to comment
ViRuZGamiing Posted May 24, 2016 Share Posted May 24, 2016 I wrote you a little script. local filepath = "command-log.txt" local file addEventHandler("onPlayerCommand", root, function (cmdname) if (not fileExists(filepath)) then fileCreate(filepath) end file = fileOpen(filepath) fileSetPos(file, fileGetSize(file)) fileWrite(file, getPlayerName(source).." typed command "..cmdname.."\n") fileFlush(file) fileClose(file) end) Just because I was interested in testing this out. Text document looks sorta like this: Viruz typed command stop Viruz typed command start Viruz typed command debugscript or this format I've just made; local filepath = "command-log.txt" local file local months = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", } addEventHandler("onPlayerCommand", root, function (cmdname) if (not fileExists(filepath)) then fileCreate(filepath) end file = fileOpen(filepath) fileSetPos(file, fileGetSize(file)) if (cmdname ~= "stopanim") then local time = getRealTime() fileWrite(file,"["..time.monthday.." "..months[time.month].." "..(time.year+1900).." | "..time.hour..":"..time.minute..":"..time.second.."] "..getPlayerName(source)..": "..cmdname.."\n") fileFlush(file) fileClose(file) end end) looks like this: [24 April 2016 | 11:27:35] Viruz: debugscript Link to comment
Moderators IIYAMA Posted May 24, 2016 Moderators Share Posted May 24, 2016 Opening and closing a file for every command isn't a good idea. (when the file gets larger you might experience lagg) That's why the fileFlush function is so important. fileFlush Link to comment
mgdmgd Posted May 24, 2016 Author Share Posted May 24, 2016 Thank you ViRuZGamiing!!!! <3 and i got one more question is it possible to write down where is that command located at? like which resource? whenever he writes it too? Link to comment
ViRuZGamiing Posted May 24, 2016 Share Posted May 24, 2016 Opening and closing a file for every command isn't a good idea. (when the file gets larger you might experience lagg)That's why the fileFlush function is so important. fileFlush So I'd would be like this right; local filepath = "command-log.txt" local file local months = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", } addEventHandler( "onResourceStart", getResourceRootElement(getThisResource()), function () if (not fileExists(filepath)) then fileCreate(filepath) else file = fileOpen(filepath) end end) addEventHandler("onPlayerCommand", root, function (cmdname) fileSetPos(file, fileGetSize(file)) if (cmdname ~= "stopanim") then local time = getRealTime() fileWrite(file,"["..time.monthday.." "..months[time.month].." "..(time.year+1900).." | "..time.hour..":"..time.minute..":"..time.second.."] "..getPlayerName(source)..": "..cmdname.."\n") fileFlush(file) end end) addEventHandler("addEventHandler", getResourceRootElement(getThisResource()), function () fileClose(file) end) Link to comment
Moderators IIYAMA Posted May 24, 2016 Moderators Share Posted May 24, 2016 Jup, yup, yep, (Except for the typo of the event on line 35 > onResourceStop) And this line: fileSetPos(file, fileGetSize(file)) It only has to be called ones, when the file already exist. But is not a critical thing. After writing lines, the position will also change, so no need to call it every time you add content. Link to comment
ViRuZGamiing Posted May 24, 2016 Share Posted May 24, 2016 oh yeah lol sublime text derped Link to comment
Moderators IIYAMA Posted May 24, 2016 Moderators Share Posted May 24, 2016 @mgdmgd Commands are not bound on resources. @ViRuZGamiing Anyway, you are getting pretty good at lua. A total different level as when we last met. 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