• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

TFS 1.X+ Log onUse

peteralto

Member
Joined
Nov 1, 2020
Messages
93
Solutions
1
Reaction score
19
Is it possible to generate a log with the time and name of the player that executes an action script? For example, opening a quest chest.
 
Lua:
local generateLog = Action()
function generateLog.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local file = io.open("data/logs/actions.log", "a")
    if file then
        file:write(("[%s] Player \"%s\" opened a chest."):format(os.date("%c", os.time()), player:getName()), "\n")
        file:close()
    end
    return true
end

generateLog:aid(1000)
generateLog:register()

Edit: Or better yet, since you probably want to log multiple actions
Lua:
generateLog = function(s, path)
    local file = io.open(path, "a")
    if file then
        file:write("["..os.date("%c", os.time()).."] "..s, "\n")
        file:close()
    end
end

local name = "Roddet"
local rupees = 50

generateLog(string.format("Player \"%s\" opened a chest with %d rupees", name, rupees), "actions.log")

%s expects a "string" and %d expects a number
 
Last edited:
Back
Top