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

Monster Drops 1 Item

Fischturd

New Member
Joined
Jan 30, 2023
Messages
26
Reaction score
3
GitHub
Fischturd
Howdy,

I am looking into some of this coding for C++, which I am not good at... however I want to add this feature that monsters only drop 1 item from the loot table.

TFS 1.3

I wanted to know if this code here
monsters.cpp
C++:
std::vector<Item*> MonsterType::createLootItem(const LootBlock& lootBlock)
{
    int32_t itemCount = 0;

    uint32_t randvalue = Monsters::getLootRandom();
    if (randvalue < lootBlock.chance) {
        if (Item::items[lootBlock.id].stackable) {
            itemCount = randvalue % lootBlock.countmax + 1;
        } else {
            itemCount = 1;
        }
    }

    std::vector<Item*> itemList;
    while (itemCount > 0) {
        uint16_t n = static_cast<uint16_t>(std::min<int32_t>(itemCount, 100));
        Item* tmpItem = Item::CreateItem(lootBlock.id, n);
        if (!tmpItem) {
            break;
        }

        itemCount -= n;

        if (lootBlock.subType != -1) {
            tmpItem->setSubType(lootBlock.subType);
        }

        if (lootBlock.actionId != -1) {
            tmpItem->setActionId(lootBlock.actionId);
        }

        if (!lootBlock.text.empty()) {
            tmpItem->setText(lootBlock.text);
        }

        itemList.push_back(tmpItem);
    }
    return itemList;
}
Is the correct spot to adjust monster loot?
I tried adjusting what I thought was the area to change this but I am apparently not correct..
I changed
C++:
uint16_t n = static_cast<uint16_t>(std::min<int32_t>(itemCount, 100));
to
C++:
uint16_t n = 1;
thinking that the next lines
C++:
Item* tmpItem = Item::CreateItem(lootBlock.id, n);
        if (!tmpItem) {
            break;
Would only generate 1 item instead of pulling from the itemList itself

I think I am close, but like I said this is kind of above me right now...It appears there could be a work around with a .lua script adding "extra loot" and having it pull from a loot list that way.. but I don't want to go in and adjust all my monsters into that 1 script and remove their drops from XML, etc etc..

Thanks for listening!
 
Last edited:
Back
Top