• 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 Clean Globalevent problem.

Wiw3K

New Member
Joined
Apr 16, 2008
Messages
371
Reaction score
3
Sup, clean globalevent freezes server o_O no idea why there aren't much code lol
Also i have set up it for 13:00 and it cleaned at 22:00 o_O wtf?

Distro: TFS 0.4
Client: Tibia 8.60
Dedi: Debian 6 32bit

globalevents.xml
Code:
<globalevent name="clean" time="13:00" event="script" value="clean.lua"/>


clean.lua
Code:
function onTime(interval)
    doCleanMap()
    doBroadcastMessage("Game map cleaned, next clean in at 13:00.")
    return true
end


luainterface.cpp
Code:
int32_t LuaInterface::luaDoCleanMap(lua_State* L)
{
    //doCleanMap()
    uint32_t count = 0;
    g_game.cleanMapEx(count);
    lua_pushnumber(L, count);
    return 1;
}

and whole cleanMapEx function from game.cpp
Code:
void Game::cleanMapEx(uint32_t& count)
{
    uint64_t start = OTSYS_TIME();
    uint32_t tiles = 0; count = 0;

    int32_t marked = -1;
    if(gameState == GAMESTATE_NORMAL)
        setGameState(GAMESTATE_MAINTAIN);

    Tile* tile = NULL;
    ItemVector::iterator tit;
    if(g_config.getBool(ConfigManager::STORE_TRASH))
    {
        marked = trash.size();
        Trash::iterator it = trash.begin();
        if(g_config.getBool(ConfigManager::CLEAN_PROTECTED_ZONES))
        {
            for(; it != trash.end(); ++it)
            {
                if(!(tile = getTile(*it)))
                    continue;

                tile->resetFlag(TILESTATE_TRASHED);
                if(tile->hasFlag(TILESTATE_HOUSE) || !tile->getItemList())
                    continue;

                ++tiles;
                tit = tile->getItemList()->begin();
                while(tile->getItemList() && tit != tile->getItemList()->end())
                {
                    if((*tit)->isMoveable() && !(*tit)->isLoadedFromMap()
                        && !(*tit)->isScriptProtected())
                    {
                        internalRemoveItem(NULL, *tit);
                        if(tile->getItemList())
                            tit = tile->getItemList()->begin();

                        ++count;
                    }
                    else
                        ++tit;
                }
            }

            trash.clear();
        }
        else
        {
            for(; it != trash.end(); ++it)
            {
                if(!(tile = getTile(*it)))
                    continue;

                tile->resetFlag(TILESTATE_TRASHED);
                if(tile->hasFlag(TILESTATE_PROTECTIONZONE) || !tile->getItemList())
                    continue;

                ++tiles;
                tit = tile->getItemList()->begin();
                while(tile->getItemList() && tit != tile->getItemList()->end())
                {
                    if((*tit)->isMoveable() && !(*tit)->isLoadedFromMap()
                        && !(*tit)->isScriptProtected())
                    {
                        internalRemoveItem(NULL, *tit);
                        if(tile->getItemList())
                            tit = tile->getItemList()->begin();

                        ++count;
                    }
                    else
                        ++tit;
                }
            }

            trash.clear();
        }
    }
    else if(g_config.getBool(ConfigManager::CLEAN_PROTECTED_ZONES))
    {
        for(uint16_t z = 0; z < (uint16_t)MAP_MAX_LAYERS; z++)
        {
            for(uint16_t y = 1; y <= map->mapHeight; y++)
            {
                for(uint16_t x = 1; x <= map->mapWidth; x++)
                {
                    if(!(tile = getTile(x, y, z)) || tile->hasFlag(TILESTATE_HOUSE) || !tile->getItemList())
                        continue;

                    ++tiles;
                    tit = tile->getItemList()->begin();
                    while(tile->getItemList() && tit != tile->getItemList()->end())
                    {
                        if((*tit)->isMoveable() && !(*tit)->isLoadedFromMap()
                            && !(*tit)->isScriptProtected())
                        {
                            internalRemoveItem(NULL, *tit);
                            if(tile->getItemList())
                                tit = tile->getItemList()->begin();

                            ++count;
                        }
                        else
                            ++tit;
                    }
                }
            }
        }
    }
    else
    {
        for(uint16_t z = 0; z < (uint16_t)MAP_MAX_LAYERS; z++)
        {
            for(uint16_t y = 1; y <= map->mapHeight; y++)
            {
                for(uint16_t x = 1; x <= map->mapWidth; x++)
                {
                    if(!(tile = getTile(x, y, z)) || tile->hasFlag(TILESTATE_PROTECTIONZONE) || !tile->getItemList())
                        continue;

                    ++tiles;
                    tit = tile->getItemList()->begin();
                    while(tile->getItemList() && tit != tile->getItemList()->end())
                    {
                        if((*tit)->isMoveable() && !(*tit)->isLoadedFromMap()
                            && !(*tit)->isScriptProtected())
                        {
                            internalRemoveItem(NULL, *tit);
                            if(tile->getItemList())
                                tit = tile->getItemList()->begin();

                            ++count;
                        }
                        else
                            ++tit;
                    }
                }
            }
        }
    }

    if(gameState == GAMESTATE_MAINTAIN)
        setGameState(GAMESTATE_NORMAL);

    std::clog << "> CLEAN: Removed " << count << " item" << (count != 1 ? "s" : "")
        << " from " << tiles << " tile" << (tiles != 1 ? "s" : "");
    if(marked >= 0)
        std::clog << " (" << marked << " were marked)";

    std::clog << " in " << (OTSYS_TIME() - start) / (1000.) << " seconds." << std::endl;
}

i have no idea what may cause server to freeze.

ps. talkaction clean works like charm but doesn't clean whole map, it only uses cleantile in cid range function.

-EDIT-
i just noticed there is return true in clean.lua can this cause that freeze problem ? Lol...
 
Last edited:
About the time, you must remember that the dedi may be in a different time zone compared to where you are.

About the clean, how big is the map? is it an RL map?
 
About the time, you must remember that the dedi may be in a different time zone compared to where you are.

About the clean, how big is the map? is it an RL map?
Ill give a look about time on dedi, Noo its Evolution 4mb+- ^^

-edit-
yeah difference was 6hours lol.
 
Back
Top