• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

TFS 1.X+ Log onUse

peteralto

Active Member
Joined
Nov 1, 2020
Messages
131
Solutions
1
Reaction score
33
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