• 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.3 clean houses of inactive players

adrianootavares

New Member
Joined
Jul 23, 2012
Messages
112
Reaction score
4
Location
Salvador - Bahia - Brasil
Lua:
local config = {

    days = 7, --- days to clean houses ---

    log = true,

    file = "data/logs/cleanhouses.txt"

}



local function doWriteLogFile(file, text)

    local f = io.open(file, "a+")

    if not f then

        return false

    end



    f:write("[" .. os.date("%d/%m/%Y %H:%M:%S") .. "] " .. text .. "\n")

    f:close()

    return true

end



function onSay(player, words, param)

    local logs = "Houses cleaned:\n"

    local resultId = db.storeQuery("SELECT `h`.`id` AS `id`, `p`.`name` AS `playerName` FROM `houses` AS `h` LEFT JOIN `players` AS `p` ON `p`.`id` = `h`.`owner` WHERE `p`.`lastlogin` < UNIX_TIMESTAMP() - " .. config.days .. " * 24 * 60 * 60")

    if resultId == false then

        logs = string.format("%sThere were no houses to clean.\n", logs)

    else



        repeat

            local house = House(result.getNumber(resultId, "id"))

            local playerName = result.getString(resultId, "playerName")

            if house ~= nil then

                logs = string.format("%sHouse: %s, Owner: %s\n", logs, house:getName(), playerName)

                house:setOwnerGuid(0)

            end



        until not result.next(resultId)

        result.free(resultId)

    end



    if config.log then

        doWriteLogFile(config.file, logs)

    end



    return true

end


<globalevent name="CleanHouses" type="Startup" script="otfacil/cleanhouses.lua" />

BUG!

 
how can i change this to 1.3 as a action
TFS 1.3 version

data/scripts/cleanhouses.lua
Lua:
local config = {
    days = 7, --- days to clean houses ---
    log = true,
    file = "data/logs/cleanhouses.txt"
}

local function doWriteLogFile(file, text)
    local f = io.open(file, "a+")
    if not f then
        return
    end

    f:write("[" .. os.date("%d/%m/%Y %H:%M:%S") .. "] " .. text .. "\n")
    f:close()
end

local event = GlobalEvent("CleanHouses")

function event.onStartup()
    local logs = "Houses cleaned:\n"
    local resultId = db.storeQuery("SELECT `h`.`id` AS `id`, `p`.`name` AS `playerName` FROM `houses` AS `h` LEFT JOIN `players` AS `p` ON `p`.`id` = `h`.`owner` WHERE `p`.`lastlogin` < UNIX_TIMESTAMP() - " .. config.days .. " * 24 * 60 * 60")
    if resultId == false then
        logs = string.format("%sThere were no houses to clean.\n", logs)
    else
        repeat
            local house = House(result.getNumber(resultId, "id"))
            local playerName = result.getString(resultId, "playerName")
            if house ~= nil then
                logs = string.format("%sHouse: %s, Owner: %s\n", logs, house:getName(), playerName)
                house:setOwnerGuid(0)
            end
        until not result.next(resultId)
        result.free(resultId)
    end

    if config.log then
        doWriteLogFile(config.file, logs)
    end
    return true
end

event:register()
 
Back
Top