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

BOSS Monster Loot: Unique drop (reward system)

Nihilismo

New Member
Joined
May 9, 2008
Messages
58
Reaction score
0
Hello, I have been trying to solve a problem with unique items getting looted by every participant that join the fight.
I found out that the code is not finished to avoid multiple people getting the unique item.
I am using otservbr-global.
And this is the part of the code that is unfinished.
Code:
function MonsterType.getBossReward(self, lootFactor, topScore)
    local result = {}
    if getConfigInfo("rateLoot") > 0 then
        local loot = self:getLoot() or {}
        for i = #loot, 0, -1 do
            local lootBlock = loot[i]
            if lootBlock then
                if lootBlock.unique and not topScore then
                    --continue
                else
                    self:createLootItem(lootBlock, lootFactor, result)
                end
            end
        end
    end
   
    return result
end
What i was trying to do is print the lootblock and try to get the items properties but with no success and i could not get any reference of what properties does the object contain.
lootBlock.unique is a nil value for every single item.
If anyone knows how i could fix this problem it would be appreciated
Thanks in advance.
 
Last edited:
Well i don't know why lootBlock.unique is always nil, so i modified this i know its not the best way and im new to lua but here is my "fix" it does work and it doesnt give the item if it's in the list.

Code:
function MonsterType.getBossReward(self, lootFactor, topScore)
    local itemsUnicos = {
        [24718] = {itemName = 'werewolf helmet'},
    }
    local result = {}
    if getConfigInfo("rateLoot") > 0 then
        local loot = self:getLoot() or {}
        for i = #loot, 0, -1 do
            local lootBlock = loot[i]
            if lootBlock then
                if itemsUnicos[lootBlock.itemId] and topScore then
                    self:createLootItem(lootBlock, lootFactor, result)
                end
                if not itemsUnicos[lootBlock.itemId] then
                    self:createLootItem(lootBlock, lootFactor, result)
                end
            end
        end
    end
    
    return result
end

Well if anyone has a better solution id be glad to test it out.
Thanks in advance.
 
I saw the commit but, i can't find anything that can help me know why my unique id is always nil or how i could finish the code.


Edit.
I found an error in the luascript.cpp it did not have the value unique.

Code:
void LuaScriptInterface::pushLoot(lua_State* L, const std::vector<LootBlock>& lootList)
{
    lua_createtable(L, lootList.size(), 0);

    int index = 0;
    for (const auto& lootBlock : lootList) {
        lua_createtable(L, 0, 7);

        setField(L, "itemId", lootBlock.id);
        setField(L, "chance", lootBlock.chance);
        setField(L, "subType", lootBlock.subType);
        setField(L, "maxCount", lootBlock.countmax);
        setField(L, "actionId", lootBlock.actionId);
        setField(L, "text", lootBlock.text);

        pushLoot(L, lootBlock.childLoot);
        lua_setfield(L, -2, "childLoot");

        lua_rawseti(L, -2, ++index);
    }
}

I just added
Code:
        setField(L, "unique", lootBlock.unique);
under text field and now im getting the correct value at getBossReward function
 
Last edited:
I saw the commit but, i can't find anything that can help me know why my unique id is always nil or how i could finish the code.
I found an error in the luascript.cpp it did not have the value unique.

Code:
void LuaScriptInterface::pushLoot(lua_State* L, const std::vector<LootBlock>& lootList)
{
    lua_createtable(L, lootList.size(), 0);

    int index = 0;
    for (const auto& lootBlock : lootList) {
        lua_createtable(L, 0, 7);

        setField(L, "itemId", lootBlock.id);
        setField(L, "chance", lootBlock.chance);
        setField(L, "subType", lootBlock.subType);
        setField(L, "maxCount", lootBlock.countmax);
        setField(L, "actionId", lootBlock.actionId);
        setField(L, "text", lootBlock.text);

        pushLoot(L, lootBlock.childLoot);
        lua_setfield(L, -2, "childLoot");

        lua_rawseti(L, -2, ++index);
    }
}

I just added
Code:
        setField(L, "unique", lootBlock.unique);
under text field and now im getting the correct value at getBossReward function
With this change more commit solved the problem? I'm having the same
 
No i did not use the commit at all. its an old commit that's already in my project, so if you put that line it should be fine.
 
Back
Top