Jump to content

Quick help here


mgdmgd

Recommended Posts

Posted

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.

Posted

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

  • Moderators
Posted

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 
-- 

Posted

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 

  • Moderators
Posted

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 

Posted

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?

Posted
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) 

  • Moderators
Posted

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.

  • Moderators
Posted

@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. :-D

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...