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

GlobalEvent Automagically clean unused houses, multi-world support!

Thanks for comments.

@Snow, try replacing UNIX_TIMESTAMP() with date('now') for sqlite.
:eek: cool, if that script works for sqlite too
i'll merge it with my globalevent players autodelete ^^
 
[29/03/2010 13:59:24] [Error - GlobalEvent Interface]
[29/03/2010 13:59:24] data/globalevents/scripts/cleanhouses.lua
[29/03/2010 13:59:24] Description:
[29/03/2010 13:59:24] data/globalevents/scripts/cleanhouses.lua:10: attempt to concatenate a nil value
[29/03/2010 13:59:24] [Warning - Event::loadScript] Cannot load script (data/globalevents/scripts/cleanhouses.lua)


Please fix it, im using Cying Damson 0.3.6 pl1
 
It looks like you're missing
Code:
worldId = 0
in your config.lua
 
versions

Code:
 1.0 - initial release (17.02.2010)
  1.01 - added multiworld support, optimized query. (17.03.2010)
  1.02 - now uses only one sql query, removed multiworld configurable since it's not needed anymore (18.03.2010)
This mod will clean houses of inactive players every time your server starts and move their items to their depots.

Mind it may freeze for a long time if it was to clean many heavily stuffed houses. Moving items to depots is kinda slow. However running this mod every day will lessen the load and keep the houses free for active players.

Tested on TFS 0.4 DEV, although it should work flawlessly with 0.3.6 and possibly with 0.3.5 as well.

MOD VERSION

Code:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Cleanhouses" version="1.02" author="nsanee" contact="otland.net" enabled="yes">
    <description>
        v.1.01 - small fixes, optimized query + multiworld support.
        v 1.02 - now uses only one sql query, removed multiworld configurable  since it's not needed anymore

        This mod will clean houses of inactive players and move their items to the depot.
        
        config explained:
            
            days - If the player hasn't logged in for this number of days his house will be freed.
            log - true/false, whether to enable logging of which houses have been cleaned.
            file - path to the log file, where logs will be stored. Ignored if 'log' set to false
        
            DO NOT remove doSaveServer() at the end, otherwise if your server happens to crash before the nearest server save you will regret it =)
    </description>

    <config name="cleanhouses_conf"><![CDATA[
    
        config = { 
            days = 14,
            log = true,
            file = getDataDir() .. "/logs/cleanhouses.txt"
        }
        ns_query =[[SELECT houses.owner,houses.id,players.name FROM houses
                LEFT JOIN players ON players.id=houses.owner
                WHERE players.lastlogin < (UNIX_TIMESTAMP() - ]] ..config.days.. [[*24*60*60)
                AND
                players.world_id =]] .. getConfigValue("worldId")
  
    ]]></config>
    <globalevent name="cleanhouses" type="start" event="buffer"><![CDATA[
        domodlib('cleanhouses_conf')
        local house = db.getResult(ns_query)
        local logs = " :: Houses cleaned:\n\n"
        if house:getID() ~= -1 then
            repeat
                logs = logs .. getHouseInfo(house:getDataInt('id')).name ..", owned by " .. house:getDataString('name') .. "\n"
                setHouseOwner(house:getDataInt('id'), 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(doSaveServer, 1000)
    ]]></globalevent>
</mod>
Just save it as cleanhouses.xml in your TFS/mods directory.

NON-MOD VERSION

globalevents/globalevents.xml

Code:
<globalevent name="cleanhouses" type="start" event="script" value="cleanhouses.lua"/>
globalevents/scripts/cleanhouses.lua

Code:
local config = { 
    days = 14,
    log = true,
    file = getDataDir() .. "/logs/cleanhouses.txt"
}    
local ns_query =[[ SELECT houses.owner,houses.id,players.name FROM houses
                LEFT JOIN players ON players.id=houses.owner
                WHERE players.lastlogin < (UNIX_TIMESTAMP() - ]] ..config.days.. [[*24*60*60)
                AND
                players.world_id =]] .. getConfigValue("worldId")

function onStartup(_time)

    local house = db.getResult(ns_query)
    local logs = " :: Houses cleaned:\n\n"
    if house:getID() ~= -1 then
        repeat
            logs = logs .. getHouseInfo(house:getDataInt('id')).name ..", owned by " .. house:getDataString('name') .. "\n"
            setHouseOwner(house:getDataInt('id'), 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(doSaveServer, 1000)
end

I used Mod Version and i got this error:
 
Hmm I'm not sure what is it. Whch TFS version do you use?
Does this happen when using a non-mod version as well?

Also try cutting
Code:
        ns_query =[[SELECT houses.owner,houses.id,players.name FROM houses
                LEFT JOIN players ON players.id=houses.owner
                WHERE players.lastlogin < (UNIX_TIMESTAMP() - ]] ..config.days.. [[*24*60*60)
                AND
                players.world_id =]] .. getConfigValue("worldId")
and paste it after
Code:
 domodlib('cleanhouses_conf')
 
I only tried with the mods version, i use 0.4_DEV the newest. klet my try again.
 
I used Mod Version and i got this error:
try like "return 1" or "_result = 1" or w/e it gives 'boolean'
maybe after "addEvent(...)" put "return true" or "return addEvent(...)" i dont think its gonna work with return addEvent tho
not sure, but give it a try
 
Last edited:
didnt work :( no-mod an mod are not working i really wants this script is great
 
Can you please paste errors from non-mod version? Will be easier to pinpoint the problem.
 
Ok i will repost in 44 minutes the players are starting to get angry jeje :)
 
I think I got it,

replace:
Code:
getHouseInfo(house:getDataInt('id')).name
with
Code:
(getHouseInfo(house:getDataInt('id')).name or 'Unnamed House')

Not sure, but seems like you have a house without the name.


edit: or actually not. Wait a while, I'll try to fix it.
 
Last edited:
i have houses without names and some ghost houses that are not in game but in web are displayed, please can u tell me how to fix that? enter coatzaot.no-ip.org if u want to see it
 
Well a quick fix is to remove this line:
Code:
 logs = logs .. getHouseInfo(house:getDataInt('id')).name ..", owned by " .. house:getDataString('name') .. "\n"
It will still clean the houses but you won't have them logged, or replace the line to
Code:
logs = logs .. "House owned by " .. house:getDataString('name') .. "\n"
So you will at least see who lost the house.
 
Back
Top