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

Not to throw items through the teleporters C++

alexxxxxxx

Member
Joined
Aug 16, 2015
Messages
10
Reaction score
15
Location
Brasil
GitHub
l3k0t
YouTube
UCMP25Br519j7dD1FF
The name already says it all: anyone who throws items into the teleporter of your OTServ, it will be removed, like those trash cans, however, this system is implemented in the source code, excluding .LUA scripts. TFS 0.4


In teleport.cpp, find

Lua:
void Teleport::__addThing(Creature* actor, int32_t, Thing* thing)
{
    if(!thing || thing->isRemoved())
        return;

    Tile* destTile = g_game.getTile(destination);
    if(!destTile)
        return;

    if(Creature* creature = thing->getCreature())
    {
        g_game.addMagicEffect(creature->getPosition(), MAGIC_EFFECT_TELEPORT, creature->isGhost());
        creature->getTile()->moveCreature(actor, creature, destTile);
        g_game.addMagicEffect(destTile->getPosition(), MAGIC_EFFECT_TELEPORT, creature->isGhost());
    }
    else if(Item* item = thing->getItem())
    {
        g_game.addMagicEffect(item->getPosition(), MAGIC_EFFECT_TELEPORT);
        g_game.internalMoveItem(actor, item->getTile(), destTile, INDEX_WHEREEVER, item, item->getItemCount(), NULL);
        g_game.addMagicEffect(destTile->getPosition(), MAGIC_EFFECT_TELEPORT);
    }
}

Change it all to:

Lua:
void Teleport::__addThing(Creature* actor, int32_t, Thing* thing)
{
    if (!thing || thing->isRemoved())
        return;

    Tile* destTile = g_game.getTile(destination);
    if (!destTile)
        return;

    if (Creature* creature = thing->getCreature())
    {
        g_game.addMagicEffect(creature->getPosition(), MAGIC_EFFECT_TELEPORT, creature->isGhost());
        creature->getTile()->moveCreature(actor, creature, destTile);
        g_game.addMagicEffect(destTile->getPosition(), MAGIC_EFFECT_TELEPORT, creature->isGhost());
    }
    else
    {
        Player* player = dynamic_cast<Player*>(actor);
        if (player)
        {
            player->sendTextMessage(MSG_STATUS_SMALL, "You cannot teleport items.");
            
            // Remover o item
            Item* item = dynamic_cast<Item*>(thing);
            if (item) {
                g_game.internalRemoveItem(actor, item);
            }
        }
        return;
    }
}

Now just compile in rebuild mode and start the server, credits to me, alexxxxxxx ~ L3K0T, for the changes.
 
Does old tfs not have onMoveItem function?
 
Last edited:
Nah, I would prefer this too, but for the sake of taking everyone's opinion into consideration, we could modify to only apply the new logic if in config.lua its enabled! Boom! Much better than onMove!
 
Back
Top