Jump to content

commands reader


viktorX

Recommended Posts

addEventHandler("onResourceStart",root,
    function()
		if fileExists("log.txt") then
 		   log = fileOpen("log.txt")
		else
  			 log = fileCreate("log.txt") 
		end
end)
      

addEventHandler("onPlayerCommand",root,
    function(command)
        fileWrite(file,getPlayerName(source).." used "..command.." command.".."\n" )   
end)
      

 

Edited by URBAN
Link to comment
15 hours ago, URBAN said:

addEventHandler("onResourceStart",root,
    function()
		if fileExists("log.txt") then
 		   log = fileOpen("log.txt")
		else
  			 log = fileCreate("log.txt") 
		end
end)
      

addEventHandler("onPlayerCommand",root,
    function(command)
        fileWrite(file,getPlayerName(source).." used "..command.." command.".."\n" )   
end)
      

 

You need to close the file after you finish editing.

Link to comment
3 hours ago, Gordon_G said:

So now MTA's forum directly gives scripts ?

Yeah, dunno why. Maybe road to +reps.

10 hours ago, N3xT said:

You need to close the file after you finish editing.

And use log isntead of file variable.
Btw i think this keep open the file to optimize more memory. Bcs open/close file every command not better than keep the file open (i think fileWrite don't require fileClose to work)

Link to comment
4 hours ago, sanyisasha said:

Yeah, dunno why. Maybe road to +reps.

And use log isntead of file variable.
Btw i think this keep open the file to optimize more memory. Bcs open/close file every command not better than keep the file open (i think fileWrite don't require fileClose to work)

Wiki: It is also important to remember to close a file after you've finished all your operations on it, especially if you've been writing to the file. If you don't close a file and your resource crashes, all changes to the file may be lost.

Link to comment

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