Jump to content

commands reader


viktorX

Recommended Posts

Posted

hello 

i need someone to tell me how to make a script like that:

log for players cmds i mean when someone type any cmd it's saves to file in ftp 

I also want to make a script to watch the  cmds of a particular player inside the server

how to make that?

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

turkey_1274.jpg İstikbal göklerdedir.

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

 

 

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

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

 

 

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