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

[TFS 1.3] - Extra/Better loot based on source:getLevel

Lyky

Well-Known Member
Joined
May 27, 2014
Messages
291
Solutions
8
Reaction score
89
if you using tfs 1.3+ you can easily add some lines into the loot item creation
open container.lua file inside libs and this function with
Lua:
function Container.createLootItem(self, item, multiplier)
    if self:getEmptySlots() == 0 then
        return true
    end

    multiplier = multiplier or 1
    local itemCount = 0
    local randvalue = getLootRandom()
    if randvalue < item.chance * multiplier then
        if ItemType(item.itemId):isStackable() then
            itemCount = randvalue % item.maxCount + 1
        else
            itemCount = 1
        end
    end

    if itemCount > 0 then
        local tmpItem = self:addItem(item.itemId, math.min(itemCount, 100))
        if not tmpItem then
            return false
        end

        if tmpItem:isContainer() then
            for i = 1, #item.childLoot do
                if not tmpItem:createLootItem(item.childLoot[i]) then
                    tmpItem:remove()
                    return false
                end
            end
        end

        if item.subType ~= -1 then
            tmpItem:setAttribute(ITEM_ATTRIBUTE_CHARGES, item.subType)
        end

        if item.actionId ~= -1 then
            tmpItem:setActionId(item.actionId)
        end

        if item.text and item.text ~= "" then
            tmpItem:setText(item.text)
        end
    end
    return true
end

so then at dropLoot event edit "createLootItem" with something like
Lua:
local item = corpse:createLootItem(monsterLoot[i], multiplier)
where multiplier is the new parameter so use something like the function you said:
Lua:
local item = corpse:createLootItem(monsterLoot[i], self:getLevel())
 
Last edited:
Hi thanks for responding to this.

The engine is 1.3 indeed;
My container.lua file originally was quite empty

Lua:
function Container.isContainer(self)
    return true
end

and my droploot.lua in data\creaturescripts\scripts\droploot.lua is as follows
I don't see the corpseLootItem or in fact anything referencing to monster loot.

Lua:
function onDeath(player, corpse, killer, mostDamage, unjustified, mostDamage_unjustified)
    if player:hasFlag(PlayerFlag_NotGenerateLoot) then --or player:getVocation():getId() == VOCATION_NONE then
        return true
    end

    local amulet = player:getSlotItem(CONST_SLOT_NECKLACE)
    if amulet and amulet.itemid == ITEM_AMULETOFLOSS and not table.contains({SKULL_RED, SKULL_BLACK}, player:getSkull()) then
        local isPlayer = false
        if killer then
            if killer:isPlayer() then
                isPlayer = true
            else
                local master = killer:getMaster()
                if master and master:isPlayer() then
                    isPlayer = true
                end
            end
        end

        if not isPlayer or not player:hasBlessing(6) then
            player:removeItem(ITEM_AMULETOFLOSS, 1, -1, false)
        end
    else
        for i = CONST_SLOT_HEAD, CONST_SLOT_AMMO do
            local item = player:getSlotItem(i)
            if item then
                if table.contains({SKULL_RED, SKULL_BLACK}, player:getSkull()) or math.random(item:isContainer() and 100 or 1000) <= player:getLossPercent() then
                    if not item:moveTo(corpse) then
                        item:remove()
                    end
                end
            end
        end
    end

    if not player:getSlotItem(CONST_SLOT_BACKPACK) then
        player:addItem(ITEM_BAG, 1, false, CONST_SLOT_BACKPACK)
    end
    return true
end

I might be looking in wrong place;
You can see my code files here
 
bump (Still need help with this)

Could this be used? I tried to do some stuff with

Lua:
local bonusLoot = source:getMonsterLevel() * 0.03
        if source:getMonsterLevel() > 0 and bonusLoot > 1 then
            chance = 100000 * bonusLoot
        end
        end

But sadly i never got any item from it (this is just example)
 
Thus lets come up with alternatives; the tfs 1.1 code for extra loot -- in reality i wouldn't mind just dropping certain item into player inventory as reward - like a candy or something; use level as % (as shown above post with that extra loot syst)
 
a bump on this;

Lets see if 3 years later we get any better solutions.

The system is really cool , and yes is possible , in my case I rework the system to work on a 13.20 and works perfectly with loot , if better level , I create the getMonsterLevel function on source code in order to know the level , as it random, then depending on level I just increase loot on monster.Lua. But this I think won’t work for your version , like I do the code since is not Tfs.

But you need to do on source is:
- create a code that knows the level is generated randomly to the monster , with this you can create the function to call the monsterLevel, with this in script after is easy to play anywhere, if monsterLevel > loot * 2.0, add extra items , storage , etc.
 
Hi,
Some time has passed, and i've decided to spend some time on this problem, and ran into problem on how to getLevel from monster in monsters.cpp.


monsters.cpp (default)
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;
        }
    }

and i made following changes
C++:
std::vector<Item*> MonsterType::createLootItem(const LootBlock& lootBlock)
{
    int32_t itemCount = 0;

    uint32_t randvalue = Monsters::getLootRandom();
    uint32_t level = Monster::getLevel();

    if (level > 0 & randvalue < lootBlock.chance) {
        float bonusLoot = g_config.getFloat(ConfigManager::MLVL_BONUSLOOT) * level;
        if (bonusLoot != 0.0) {
            randvalue += randvalue * bonusLoot;
        }
        if (Item::items[lootBlock.id].stackable) {
            itemCount = randvalue % lootBlock.countmax + 1;
        }
        else {
            itemCount = 1;
        }
    }

and i'm getting "a nonstatic member reference must be relative to a specific object"

83zwqAn.png




Monster::getLevel is defined in monster.h

C++:
        int32_t getLevel() const {
            return level;
        }


any help how to get monster's level in monsters.cpp var would be appreciated. (unless i'm doing it completely wrong - and i'm stupid which is plausible.)
 
Back
Top