• 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!

Commands logs

Metal Mouth

Developer
Joined
Oct 7, 2015
Messages
55
Reaction score
7
Hello, I want to control my staff on OTS so I'm looking for a way to save in logs or something every command that was used by players with it 2/3/4/5. Does someone know the way to do it?
 
Solution
Lua:
function logCommand(player, words, param)
    local file = io.open("data/logs/"..player:getName()..".log", "a+")
    file:write(("[ %s ] %s%s\n"):format(os.date(), words, (param ~= "" and " " or "") .. param))
    file:close()
    return true
end

Lua:
function onSay(player, words, param)
    if not player:getGroup():getAccess() then
        return true
    end

    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end

    local split = param:split(",")

    local itemType = ItemType(split[1])
    if itemType:getId() == 0 then
        itemType = ItemType(tonumber(split[1]))
        if itemType:getId() == 0 then
            player:sendCancelMessage("There is no item with that id or name.")...
hmm i can use it? @Colandus

Code:
function onSay(player, words, param)
logCommand(player, words, param)
    if not player:getGroup():getAccess() then
        return true
    end

    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end

    local split = param:split(",")

    local itemType = ItemType(split[1])
    if itemType:getId() == 0 then
        itemType = ItemType(tonumber(split[1]))
        if itemType:getId() == 0 then
            player:sendCancelMessage("There is no item with that id or name.")
            return false
        end
    end

    local count = tonumber(split[2])
    if count ~= nil then
        if itemType:isStackable() then
            count = math.min(10000, math.max(1, count))
        elseif not itemType:isFluidContainer()  then
            count = math.min(100, math.max(1, count))
        else
            count = math.max(0, count)
        end
    else
        count = itemType:isFluidContainer() and 0 or 1
    end

    local result = player:addItem(itemType:getId(), count)
    if result ~= nil then
        if not itemType:isStackable() then
            if type(result) == "table" then
                for i = 1, #result do
                    result[i]:decay()
                end
            else
                result:decay()
            end
        end
        player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
    end
    return false
end

Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/create_item.lua:eek:nSay
data/global.lua:88: attempt to call a string value
stack traceback:
[C]: in ?
data/global.lua:88: in function 'logCommand'
data/talkactions/scripts/create_item.lua:2: in function
 
you can log talkactions in lua
put this somewhere in your lib
Code:
function logCommand(player, words, param)
    local file = io.open("data/logs/"..player:getName()".log", "a+")
    file:write(("[ %s ] %s%s\n"):format(os.date(), words, (param ~= "" and " " or "") .. param))
    file:flush()
    file:close()
    return true
end
then call it in your talkaction scripts with:
logCommand(player, words, param)

it should automatically write to the log for ou
i think
Code:
io.open("data/logs/"..player:getName()".log", "a+")
should be
Code:
io.open("data/logs/"..player:getName()..".log", "a+")
 
Last edited:
i guess i fugged it up
ty for noticing lel
wrote it in 1min
o_O

@OT
In all, this would lead to bad code in general since it is not very maintainable. You are reducing some code reuse by putting the function in global.lua, however, I'd find it more suitable and more convenient if you had the right things at the right place. If you could find me a link where I can find the sources you use, I can write you a possible solution that is adapted to your sources.
 
o_O

@OT
In all, this would lead to bad code in general since it is not very maintainable. You are reducing some code reuse by putting the function in global.lua, however, I'd find it more suitable and more convenient if you had the right things at the right place. If you could find me a link where I can find the sources you use, I can write you a possible solution that is adapted to your sources.
i'd rather give him bad code than confuse him even more by giving him source code
unless you're willing to compile for him, he'll just be even more confused where to put things and how to use it.
 
are you sure you put logcommand in global.lua correctly? can you send it on pastebin.com
Here are my paste bin - global.ua
http://pastebin.com/vvXbk9Ld

and i need add log to this command.

/i
Code:
function onSay(player, words, param)
    if not player:getGroup():getAccess() then
        return true
    end

    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end

    local split = param:split(",")

    local itemType = ItemType(split[1])
    if itemType:getId() == 0 then
        itemType = ItemType(tonumber(split[1]))
        if itemType:getId() == 0 then
            player:sendCancelMessage("There is no item with that id or name.")
            return false
        end
    end

    local count = tonumber(split[2])
    if count ~= nil then
        if itemType:isStackable() then
            count = math.min(10000, math.max(1, count))
        elseif not itemType:isFluidContainer()  then
            count = math.min(100, math.max(1, count))
        else
            count = math.max(0, count)
        end
    else
        count = itemType:isFluidContainer() and 0 or 1
    end

    local result = player:addItem(itemType:getId(), count)
    if result ~= nil then
        if not itemType:isStackable() then
            if type(result) == "table" then
                for i = 1, #result do
                    result[i]:decay()
                end
            else
                result:decay()
            end
        end
        player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
    end
    return false
end
 
Lua:
function logCommand(player, words, param)
    local file = io.open("data/logs/"..player:getName()..".log", "a+")
    file:write(("[ %s ] %s%s\n"):format(os.date(), words, (param ~= "" and " " or "") .. param))
    file:close()
    return true
end

Lua:
function onSay(player, words, param)
    if not player:getGroup():getAccess() then
        return true
    end

    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end

    local split = param:split(",")

    local itemType = ItemType(split[1])
    if itemType:getId() == 0 then
        itemType = ItemType(tonumber(split[1]))
        if itemType:getId() == 0 then
            player:sendCancelMessage("There is no item with that id or name.")
            return false
        end
    end

    local count = tonumber(split[2])
    if count ~= nil then
        if itemType:isStackable() then
            count = math.min(10000, math.max(1, count))
        elseif not itemType:isFluidContainer()  then
            count = math.min(100, math.max(1, count))
        else
            count = math.max(0, count)
        end
    else
        count = itemType:isFluidContainer() and 0 or 1
    end

    local result = player:addItem(itemType:getId(), count)
    if result ~= nil then
        if not itemType:isStackable() then
            if type(result) == "table" then
                for i = 1, #result do
                    result[i]:decay()
                end
            else
                result:decay()
            end
        end
        player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
    end
    logCommand(player, words, param)
    return false
end
 
Solution
Back
Top