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

Solved TFS 1.2 clean houses of inactive players

Shadow Dan

Sh4dowDan
Joined
Jun 5, 2010
Messages
344
Reaction score
88
Location
Poland
Script now working, big thanks to Ninja who made this script!
Tested on TFS 1.2 (100% working)
Code:
local config = {
    days = 30, --- 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
Code:
[14/07/2015 17:11:15] Houses cleaned:
There were no houses to clean.

[14/07/2015 17:11:17] Houses cleaned:
There were no houses to clean.

[14/07/2015 17:11:20] Houses cleaned:
There were no houses to clean.
#GLOBALEVENT ======================================
data/globalevents/globalevents.xml
Code:
<globalevent type="startup" name="CleanHouses" script="cleanhouses.lua" />
data/globalevents/scripts/cleanhouses.lua
Code:
local config = {
    days = 30, --- 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 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

#OLD ======================================
I can't make this script working for TFS 1.2
Any help would be really appreciated.
Code:
local config = {
    days = 30, --- days to clean houses ---
    log = true,
    file = "data/logs/cleanhouses.txt"
}

function onSay(player, words, param)
    local house = db.storeQuery("SELECT `owner` ,`id` FROM `houses` WHERE `owner` IN (SELECT `id` FROM `players` WHERE `lastlogin` < UNIX_TIMESTAMP() - "..config.days.. "*24*60*60)")
    local logs = " :: Houses cleaned:\n\n"
    if house:getID() ~= -1 then
        repeat
            logs = logs .. getHouseInfo(house:getDataInt('id')).name ..", owned by " .. getPlayerNameByGUID(house:getDataInt('owner')) .. "\n"
            setHouseOwner(house:getDataInt('id'), 0)
        until not house:next()
    else
        logs = logs .. "There were no houses to clean."
    end
    if config.log then
        doWriteLogFile(config.file, logs)
    end
    saveServer()
    return true
end
Code:
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/houses.lua:onSay
data/talkactions/scripts/houses.lua:10: attempt to index local 'house' (a number value)
stack traceback:
        [C]: in function '__index'
        data/talkactions/scripts/houses.lua:10: in function <data/talkactions/scripts/houses.lua:7>
 
Last edited:
your variable house is already a number value, i assume its the id of house.

change line 10 to this.
if house ~= -1 then
 
Code:
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/houses.lua:onSay
data/talkactions/scripts/houses.lua:12: attempt to index local 'house' (a boolean value)
stack traceback:
        [C]: in function '__index'
        data/talkactions/scripts/houses.lua:12: in function <data/talkactions/scripts/houses.lua:7>
 
Last edited:
change line 10 to this.
if house ~= -1 then
I did it and posted new error, what else you except me to write? is it really that hard to guess?
For me connections to database and getting info from there is too hard atm and i need some help to understand it.

Code:
local config = {
    days = 30, --- days to clean houses ---
    log = true,
    file = "data/logs/cleanhouses.txt"
}

function onSay(player, words, param)
    local house = db.storeQuery("SELECT `owner` ,`id` FROM `houses` WHERE `owner` IN (SELECT `id` FROM `players` WHERE `lastlogin` < UNIX_TIMESTAMP() - "..config.days.. "*24*60*60)")
    local logs = " :: Houses cleaned:\n\n"
    if house ~= -1 then
        repeat
            logs = logs .. getHouseInfo(house:getDataInt('id')).name ..", owned by " .. getPlayerNameByGUID(house:getDataInt('owner')) .. "\n"
            setHouseOwner(house:getDataInt('id'), 0)
        until not house:next()
    else
        logs = logs .. "There were no houses to clean."
    end
    if config.log then
        doWriteLogFile(config.file, logs)
    end
    saveServer()
    return true
end

Code:
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/houses.lua:onSay
data/talkactions/scripts/houses.lua:12: attempt to index local 'house' (a boolean value)
stack traceback:
        [C]: in function '__index'
        data/talkactions/scripts/houses.lua:12: in function <data/talkactions/scripts/houses.lua:7>
Sadly i can't delete my own posts.
I was searching whole forum and didnt found a single thread with updated script to clean houses for TFS 1.0+

line:12
Code:
logs = logs .. getHouseInfo(house:getDataInt('id')).name ..", owned by " .. getPlayerNameByGUID(house:getDataInt('owner')) .. "\n"
 
Last edited:
You are using the house id to get the data information. Im not sure all your getDataInt are corrects.
 
Maybe someone who understands this script will reply.

I was trying also this way:
Code:
local config = {
    days = 30, --- days to clean houses ---
    log = true,
    file = "data/logs/cleanhouses.txt"
}

function onSay(player, words, param)
    local ns_query = db.storeQuery("SELECT houses.owner, houses.id as hid, houses.name as house_name ,players.name FROM houses LEFT JOIN players ON players.id=houses.owner LEFT JOIN accounts ON players.account_id=accounts.id WHERE players.lastlogin < (UNIX_TIMESTAMP() - "..config.days.." *24*60*60)")

    local house = db.storeQuery(ns_query)
    local logs = " :: Houses cleaned:\n\n"
    if house ~= -1 then
        repeat
            logs = logs .. house:getDataString('house_name') ..", owned by " .. house:getDataString('name') .. "\n"
            setHouseOwner(house:getDataInt('hid'), 0)
        until not house:next()
        house:free()
    else
        logs = logs .. "There were no houses to clean."
    end
    if config.log then
        doWriteLogFile(config.file, logs)
    end
    addEvent(SaveServer, 1000)
    return true
end
Code:
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/houses.lua:onSay
data/talkactions/scripts/houses.lua:14: attempt to index local 'house' (a boolean value)
stack traceback:
        [C]: in function '__index'
        data/talkactions/scripts/houses.lua:14: in function <data/talkactions/scripts/houses.lua:7>
line:14
Code:
logs = logs .. house:getDataString('house_name') ..", owned by " .. house:getDataString('name') .. "\n"
 
after you create variable house do this:
print("house = "..tostring(house))
return false

and tell me what text you get..
and why you even trying to get dataint from number values??
 
Try with this:
Code:
local config = {
    days = 30, --- 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\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.", 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
 
Last edited:
edit soon ~~ testing top script
Code:
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/houses.lua:onSay
data/talkactions/scripts/houses.lua:27: attempt to call global 'doWriteLogFile' (a nil value)
stack traceback:
        [C]: in function 'doWriteLogFile'
        data/talkactions/scripts/houses.lua:27: in function <data/talkactions/scripts/houses.lua:7>
 
You can remove it, you just dont need that function. Its just to save info about all the cleaning process

Edit: The function is on the same file :)
 
#edit up
Edit: The function is on the same file :)
Yeah i saw it too, he edited script ^^
-----------------------
Ok last thing was easy to fix.
Thank YOU very much for your help!
At the end file looks like this:
Code:
local config = {
    days = 15, --- days to clean houses ---
    log = true,
}

function onSay(player, words, param)
    local a = "data/logs/houses.txt"
    local f = io.open(a, "a+")
    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("data " .. os.date("%d %B %Y - %X.", os.time()) .." %sThere were no houses to clean.\n\n", logs)
    else

        repeat
            local house = House(result.getNumber(resultId, "id"))
            local playerName = result.getString(resultId, "playerName")
            if house 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
        f:write(""..logs.."")
        f:close()
    end

    saveServer()
    return true
end
TESTED on TFS 1.2 WORKS FINE!
Code:
Houses cleaned:

There were no houses to clean.Houses cleaned:

House: Harbour Place 2 (Shop), Owner: Morfina
House: Warriors Guildhall, Owner: De Denkan

#Edit
added date and better readable log
Code:
data 14 July 2015 - 16:50:49. Houses cleaned:
There were no houses to clean.

data 14 July 2015 - 16:50:52. Houses cleaned:
There were no houses to clean.

data 14 July 2015 - 16:51:10. Houses cleaned:
There were no houses to clean.

#Edit2
See first post for lastest version of this script.
 
Last edited:
Script now working, big thanks to Ninja who made this script!
Tested on TFS 1.2 (100% working)
Code:
local config = {
    days = 30, --- 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
Code:
[14/07/2015 17:11:15] Houses cleaned:
There were no houses to clean.

[14/07/2015 17:11:17] Houses cleaned:
There were no houses to clean.

[14/07/2015 17:11:20] Houses cleaned:
There were no houses to clean.
#GLOBALEVENT ======================================
data/globalevents/globalevents.xml
Code:
<globalevent type="startup" name="CleanHouses" script="cleanhouses.lua" />
data/globalevents/scripts/cleanhouses.lua
Code:
local config = {
    days = 30, --- 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 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

#OLD ======================================
I can't make this script working for TFS 1.2
Any help would be really appreciated.
Code:
local config = {
    days = 30, --- days to clean houses ---
    log = true,
    file = "data/logs/cleanhouses.txt"
}

function onSay(player, words, param)
    local house = db.storeQuery("SELECT `owner` ,`id` FROM `houses` WHERE `owner` IN (SELECT `id` FROM `players` WHERE `lastlogin` < UNIX_TIMESTAMP() - "..config.days.. "*24*60*60)")
    local logs = " :: Houses cleaned:\n\n"
    if house:getID() ~= -1 then
        repeat
            logs = logs .. getHouseInfo(house:getDataInt('id')).name ..", owned by " .. getPlayerNameByGUID(house:getDataInt('owner')) .. "\n"
            setHouseOwner(house:getDataInt('id'), 0)
        until not house:next()
    else
        logs = logs .. "There were no houses to clean."
    end
    if config.log then
        doWriteLogFile(config.file, logs)
    end
    saveServer()
    return true
end
Code:
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/houses.lua:onSay
data/talkactions/scripts/houses.lua:10: attempt to index local 'house' (a number value)
stack traceback:
        [C]: in function '__index'
        data/talkactions/scripts/houses.lua:10: in function <data/talkactions/scripts/houses.lua:7>

Hello! otlanders :D I want this script but only for free accounts, its possible? What premium players don't affect this script. @MartyX
 
Back
Top