Jump to content

Problem with writing a log.


Andreas.

Recommended Posts

I want the result to be:

Position: xvalue, yvalue, zvalue

Money: lol

the current result:

  
Money: lol2381.0546875-2175.641601562522.9655265808118 

LUA code used:

function log(account, message) 
    if not (fileExists("logs/"..account)) then  
        log = fileCreate("logs/"..account) 
    else 
        log = fileOpen("logs/"..account) 
    end 
    fileWrite(log, "\n"..message) 
    fileClose(log) 
end 
addEvent("log", true) 
addEventHandler("log", root, log) 
  
function testlog(client) 
    local playerAccount = getPlayerAccount(client) 
    local accName = getAccountName ( playerAccount ) 
    local x, y, z = getElementPosition(client) 
    triggerEvent("log", client, accName, "Position: "..x..y..z) 
    triggerEvent("log", client, accName, "Money: lol") 
end 
addCommandHandler("log", testlog) 

Link to comment

Try this

function log(account, message) 
     if not (fileExists("logs/"..account)) then 
          log = fileCreate("logs/"..account) 
     else 
          log = fileOpen("logs/"..account) 
     end 
     if fileGetSize(log) == 0 then 
          fileWrite(log,message) 
     else 
          fileSetPos(log,fileGetSize(log)) 
          fileWrite(log,"\r\n",message) 
     end 
     fileClose(log) 
end 
addEvent("log", true) 
addEventHandler("log", root, log) 
  
function testlog(client) 
     local playerAccount = getPlayerAccount(client) 
     local accName = getAccountName ( playerAccount ) 
     local x, y, z = getElementPosition(client) 
     triggerEvent("log", client, accName, "Position: "..x..", "..y..", "..z) 
     triggerEvent("log", client, accName, "Money: lol") 
end 
addCommandHandler("log", testlog) 

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