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

Lua Bug Report TFS 1.2

_M4G0_

Well-Known Member
Joined
Feb 6, 2016
Messages
504
Solutions
16
Reaction score
98
original post https://otland.net/threads/a-better-way-to-report-bugs.147048/#post-2378435

Credits @president vankk

i made some changes to work "perfectly"
but when reporting does not update the log, i need to do a new report and /reload talkaction
is there any solution?


Code:
local config = {
    storage = 6707,
    cooldown = 120,
    file = "data/logs/bugs.txt"
}

function onSay(player, words, param)
    local file = io.open(config.file, "a")
    if not file then
        print(string.format("Warning: Could not open %s", config.file))
        return true
    end

    local split = param:split(",")
    local action = split[1]
 
    if (action == nil) then
        return true
    end
 
    if player:getStorageValue(config.storage) >= os.time() then
        player:sendTextMessage(MESSAGE_EVENT_DEFAULT, string.format('You must wait %d seconds to use this command again', config.cooldown))
        return false
    end
 
    local position = player:getPosition()
    io.output(file)
    io.write(os.date(), " Player:" .. player:getName() .. " reported a bug at " .. position.x .. " ,".. position.y .. " ,".. position.z .. " with description: " .. param .. "\n\n----------------------------------------------------------\n")
    player:sendTextMessage(MESSAGE_EVENT_DEFAULT, "Your report has been sent to " .. configManager.getString(configKeys.SERVER_NAME) .. '!')
    player:setStorageValue(config.storage, os.time() + config.cooldown)
    player:sendCancelMessage("Your report has been received successfully!")
    return false
end
 
try this
Code:
local config = {
    sep = '\n\n----------------------------------------------------------\n',
    storage = 6707,
    cooldown = 120,
    file = "data/logs/bugs.txt"
}

function onSay(player, words, param)
    local file = io.open(config.file, "a+")
    if not file then
        return print("Warning: Could not open ".. config.file)
    end

    if param == '' then
        return true
    end

    if player:getStorageValue(config.storage) >= os.time() then
        player:sendTextMessage(MESSAGE_EVENT_DEFAULT, 'You must wait '.. config.cooldown ..' seconds to use this command again')
        return false
    end

    local pos = player:getPosition()
    file:write(string.format("Date [%d] | Player: %s reported a bug at (X: %d, Y: %d, Z: %d) with description: %s%s", os.date(), player:getName(), pos.x, pos.y, pos.z, param, config.sep))
    file:close()
    player:sendTextMessage(MESSAGE_EVENT_DEFAULT, "Your report has been sent to " .. configManager.getString(configKeys.SERVER_NAME) .. '!')
    player:setStorageValue(config.storage, os.time() + config.cooldown)
    player:sendCancelMessage("Your report has been received successfully!")
    return false
end
 
At the risk of getting flamed.. Why not just use the inbuilt bug feature? (ctrl+z)
 

have this error

Code:
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/bug.lua:onSay
data/talkactions/scripts/bug.lua:24: bad argument #2 to 'format' (number expected, got string)
stack traceback:
        [C]: in ?
        [C]: in function 'format'
        data/talkactions/scripts/bug.lua:24: in function <data/talkactions/scripts/bug.lua:8>
 
Back
Top