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

C++ [TFS 0.4] - Remove Backpack on death

marcos16

Falkhonn
Joined
May 4, 2012
Messages
224
Reaction score
1
Hello. I'm needing a script or some source code change so I will not remove the backpack when it dies [except when it's redskull clear]. I have seen some scripts but they are level protection, do not lose loot up to a certain level, but it is not what I need ... Anyone available to help? :|

Edit-
TFS 0.4_svn
 
Last edited:
player.cpp line 866
C++:
void Player::dropLoot(Container* corpse)
{
    if(corpse && lootDrop && vocationId != VOCATION_NONE)
    {
        if(inventory[SLOT_NECKLACE] && inventory[SLOT_NECKLACE]->getID() == ITEM_AMULETOFLOSS &&
            getSkull() != SKULL_RED && getSkull() != SKULL_BLACK && g_game.getWorldType() != WORLD_TYPE_PVP_ENFORCED)
        {
            g_game.internalRemoveItem(inventory[SLOT_NECKLACE], 1);
        }
        else
        {
            for(int32_t i = SLOT_FIRST; i < SLOT_LAST; ++i)
            {
                Item* item = inventory[i];
                if(item)
                {
                    if(getSkull() == SKULL_RED || getSkull() == SKULL_BLACK || i != SLOT_BACKPACK && random_range(1, (item->getContainer() ? 100 : 1000)) <= getDropPercent())
                    {
                        g_game.internalMoveItem(this, corpse, INDEX_WHEREEVER, item, item->getItemCount(), 0);
                        sendInventoryItem((slots_t)i, NULL);
                    }
                }
            }
        }
    }

    if(!inventory[SLOT_BACKPACK])
        __internalAddThing(SLOT_BACKPACK, Item::CreateItem(ITEM_BAG));
}
should just skip the item movement if the player isn't rs/bs & if i isnt SLOT_BACKPACK
 
player.cpp line 866
C++:
void Player::dropLoot(Container* corpse)
{
    if(corpse && lootDrop && vocationId != VOCATION_NONE)
    {
        if(inventory[SLOT_NECKLACE] && inventory[SLOT_NECKLACE]->getID() == ITEM_AMULETOFLOSS &&
            getSkull() != SKULL_RED && getSkull() != SKULL_BLACK && g_game.getWorldType() != WORLD_TYPE_PVP_ENFORCED)
        {
            g_game.internalRemoveItem(inventory[SLOT_NECKLACE], 1);
        }
        else
        {
            for(int32_t i = SLOT_FIRST; i < SLOT_LAST; ++i)
            {
                Item* item = inventory[i];
                if(item)
                {
                    if(getSkull() == SKULL_RED || getSkull() == SKULL_BLACK || i != SLOT_BACKPACK && random_range(1, (item->getContainer() ? 100 : 1000)) <= getDropPercent())
                    {
                        g_game.internalMoveItem(this, corpse, INDEX_WHEREEVER, item, item->getItemCount(), 0);
                        sendInventoryItem((slots_t)i, NULL);
                    }
                }
            }
        }
    }

    if(!inventory[SLOT_BACKPACK])
        __internalAddThing(SLOT_BACKPACK, Item::CreateItem(ITEM_BAG));
}
should just skip the item movement if the player isn't rs/bs & if i isnt SLOT_BACKPACK

Is there any such lines in player.cpp? Or is it to add? If you already have not found it. I'm using tfs 0.4_svn
 
yes there should be.
In line 866 have this:

Code:
bool Player::canSeeCreature(const Creature* creature) const
{
    if(creature == this)
        return true;

    if(const Player* player = creature->getPlayer())
        return !player->isGhost() || getGhostAccess() >= player->getGhostAccess();

    return !creature->isInvisible() || canSeeInvisibility();
}

I looked for what you quoted and did not find
 
test
C++:
void Player::dropLoot(Container* corpse)
{
    if(corpse && lootDrop && vocationId != VOCATION_NONE)
    {
        if(inventory[SLOT_NECKLACE] && inventory[SLOT_NECKLACE]->getID() == ITEM_AMULETOFLOSS &&
            getSkull() != SKULL_RED && getSkull() != SKULL_BLACK && g_game.getWorldType() != WORLD_TYPE_PVP_ENFORCED)
        {
            g_game.internalRemoveItem(inventory[SLOT_NECKLACE], 1);
        }
        else
        {
            for(int32_t i = SLOT_FIRST; i < SLOT_LAST; ++i)
            {
                if (getSkull() < SKULL_RED && i == SLOT_BACKPACK)
                    continue;
               
                Item* item = inventory[i];
                if(item)
                {
                    if(getSkull() == SKULL_RED || getSkull() == SKULL_BLACK || i != SLOT_BACKPACK && random_range(1, (item->getContainer() ? 100 : 1000)) <= getDropPercent())
                    {
                        g_game.internalMoveItem(this, corpse, INDEX_WHEREEVER, item, item->getItemCount(), 0);
                        sendInventoryItem((slots_t)i, NULL);
                    }
                }
            }
        }
    }
    if(!inventory[SLOT_BACKPACK])
        __internalAddThing(SLOT_BACKPACK, Item::CreateItem(ITEM_BAG));
}
 
test
C++:
void Player::dropLoot(Container* corpse)
{
    if(corpse && lootDrop && vocationId != VOCATION_NONE)
    {
        if(inventory[SLOT_NECKLACE] && inventory[SLOT_NECKLACE]->getID() == ITEM_AMULETOFLOSS &&
            getSkull() != SKULL_RED && getSkull() != SKULL_BLACK && g_game.getWorldType() != WORLD_TYPE_PVP_ENFORCED)
        {
            g_game.internalRemoveItem(inventory[SLOT_NECKLACE], 1);
        }
        else
        {
            for(int32_t i = SLOT_FIRST; i < SLOT_LAST; ++i)
            {
                if (getSkull() < SKULL_RED && i == SLOT_BACKPACK)
                    continue;
              
                Item* item = inventory[i];
                if(item)
                {
                    if(getSkull() == SKULL_RED || getSkull() == SKULL_BLACK || i != SLOT_BACKPACK && random_range(1, (item->getContainer() ? 100 : 1000)) <= getDropPercent())
                    {
                        g_game.internalMoveItem(this, corpse, INDEX_WHEREEVER, item, item->getItemCount(), 0);
                        sendInventoryItem((slots_t)i, NULL);
                    }
                }
            }
        }
    }
    if(!inventory[SLOT_BACKPACK])
        __internalAddThing(SLOT_BACKPACK, Item::CreateItem(ITEM_BAG));
}
if you're going to use a continue remove the code i added to the if statement since it becomes useless
C++:
void Player::dropLoot(Container* corpse)
{
    if(corpse && lootDrop && vocationId != VOCATION_NONE)
    {
        if(inventory[SLOT_NECKLACE] && inventory[SLOT_NECKLACE]->getID() == ITEM_AMULETOFLOSS &&
            getSkull() != SKULL_RED && getSkull() != SKULL_BLACK && g_game.getWorldType() != WORLD_TYPE_PVP_ENFORCED)
        {
            g_game.internalRemoveItem(inventory[SLOT_NECKLACE], 1);
        }
        else
        {
            for(int32_t i = SLOT_FIRST; i < SLOT_LAST; ++i)
            {
                if (getSkull() < SKULL_RED && i == SLOT_BACKPACK)
                    continue;
               
                Item* item = inventory[i];
                if(item)
                {
                    if(getSkull() == SKULL_RED || getSkull() == SKULL_BLACK || random_range(1, (item->getContainer() ? 100 : 1000)) <= getDropPercent())
                    {
                        g_game.internalMoveItem(this, corpse, INDEX_WHEREEVER, item, item->getItemCount(), 0);
                        sendInventoryItem((slots_t)i, NULL);
                    }
                }
            }
        }
    }
    if(!inventory[SLOT_BACKPACK])
        __internalAddThing(SLOT_BACKPACK, Item::CreateItem(ITEM_BAG));
}

In line 866 have this:

Code:
bool Player::canSeeCreature(const Creature* creature) const
{
    if(creature == this)
        return true;

    if(const Player* player = creature->getPlayer())
        return !player->isGhost() || getGhostAccess() >= player->getGhostAccess();

    return !creature->isInvisible() || canSeeInvisibility();
}

I looked for what you quoted and did not find
did you use ctrl+f
it should be somewhere in player.cpp, if not then good luck cause i took it from vanilla 0.4 source code
 
if you're going to use a continue remove the code i added to the if statement since it becomes useless
C++:
void Player::dropLoot(Container* corpse)
{
    if(corpse && lootDrop && vocationId != VOCATION_NONE)
    {
        if(inventory[SLOT_NECKLACE] && inventory[SLOT_NECKLACE]->getID() == ITEM_AMULETOFLOSS &&
            getSkull() != SKULL_RED && getSkull() != SKULL_BLACK && g_game.getWorldType() != WORLD_TYPE_PVP_ENFORCED)
        {
            g_game.internalRemoveItem(inventory[SLOT_NECKLACE], 1);
        }
        else
        {
            for(int32_t i = SLOT_FIRST; i < SLOT_LAST; ++i)
            {
                if (getSkull() < SKULL_RED && i == SLOT_BACKPACK)
                    continue;
              
                Item* item = inventory[i];
                if(item)
                {
                    if(getSkull() == SKULL_RED || getSkull() == SKULL_BLACK || random_range(1, (item->getContainer() ? 100 : 1000)) <= getDropPercent())
                    {
                        g_game.internalMoveItem(this, corpse, INDEX_WHEREEVER, item, item->getItemCount(), 0);
                        sendInventoryItem((slots_t)i, NULL);
                    }
                }
            }
        }
    }
    if(!inventory[SLOT_BACKPACK])
        __internalAddThing(SLOT_BACKPACK, Item::CreateItem(ITEM_BAG));
}


did you use ctrl+f
it should be somewhere in player.cpp, if not then good luck cause i took it from vanilla 0.4 source code

Found it. I just do not understand what I should do.

Code:
void Player::dropLoot(Container* corpse)
{
    if(!corpse || lootDrop != LOOT_DROP_FULL)
        return;

    uint32_t loss = lossPercent[LOSS_CONTAINERS];
    if(g_config.getBool(ConfigManager::BLESSINGS))
    {
        uint32_t start = g_config.getNumber(ConfigManager::BLESS_REDUCTION_BASE), bless = getBlessings();
        while(bless > 0 && loss > 0)
        {
            loss -= start;
            start -= g_config.getNumber(ConfigManager::BLESS_REDUCTION_DECREMENT);
            bless--;
        }
    }

    uint32_t itemLoss = (uint32_t)std::floor((5. + loss) * lossPercent[LOSS_ITEMS] / 1000.);
    for(int32_t i = SLOT_FIRST; i < SLOT_LAST; ++i)
    {
        Item* item = inventory[i];
        if(!item)
            continue;

        uint32_t tmp = random_range(1, 100);
        if(skull > SKULL_WHITE || (item->getContainer() && tmp < loss) || (!item->getContainer() && tmp < itemLoss))
        {
            g_game.internalMoveItem(NULL, this, corpse, INDEX_WHEREEVER, item, item->getItemCount(), 0);
            sendRemoveInventoryItem((slots_t)i, inventory[(slots_t)i]);
        }
    }
}
 
i also had error with people losing to lvl 1 on tfs 0.4 so basically there is thing in vocations lessloss=30 need to delete that score. after that everyting worked (leaving it here for other generations of ppl)
 
Back
Top