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

OTClient tooltips issue

  • Thread starter Thread starter verdehile95
  • Start date Start date
V

verdehile95

Guest
Why is it that when I kill a boss, I get an item with random attributes, and when I use an item that gives a random weapon, this weapon has no attributes? How to make weapons received from the chest also have these attributes?sabre 1.webpsabre 2.webp
LUA:
-- ID skrzyni
local CHEST_ID = 29866


local weapons = {
    29869, --
    29870, --
    29871, --
    29872, --
    29873, -- 
    29874, -- 
    29875, -- 
    29876  -- 
}

-- Szanse na unikatowe cechy zdefiniowane w RARITY_CHANCE
local RARITY_CHANCE = {
    { id = ITEM_RARITY_COMMON, chance = 40 },
    { id = ITEM_RARITY_RARE, chance = 15 },
    { id = ITEM_RARITY_EPIC, chance = 10 },
    { id = ITEM_RARITY_LEGENDARY, chance = 2 },
    { id = ITEM_RARITY_BRUTAL, chance = 1 },
}

local function getRandomRarity()
    local totalChance = 0
    for _, rarity in ipairs(RARITY_CHANCE) do
        totalChance = totalChance + rarity.chance
    end

    local roll = math.random(1, totalChance)
    local accumulated = 0

    for _, rarity in ipairs(RARITY_CHANCE) do
        accumulated = accumulated + rarity.chance
        if roll <= accumulated then
            return rarity.id
        end
    end

    return ITEM_RARITY_COMMON -- Domyślnie common, jeśli coś pójdzie nie tak
end

local function applyRarityAttributes(item, rarityId)
    local modifiers = {
        [ITEM_RARITY_COMMON] = { amount = 0, factor = 0 },
        [ITEM_RARITY_RARE] = { amount = 2, factor = 20 },
        [ITEM_RARITY_EPIC] = { amount = 4, factor = 30 },
        [ITEM_RARITY_LEGENDARY] = { amount = 6, factor = 50 },
        [ITEM_RARITY_BRUTAL] = { amount = 7, factor = 80 },
    }

    local attributes = {
        { id = TOOLTIP_ATTRIBUTE_INCREMENTS, type = {COMBAT_PHYSICALDAMAGE}, min = 2, max = 4, chance = 5 },
        { id = TOOLTIP_ATTRIBUTE_INCREMENTS, type = {COMBAT_ENERGYDAMAGE}, min = 2, max = 4, chance = 5 },
        { id = TOOLTIP_ATTRIBUTE_INCREMENTS, type = {COMBAT_FIREDAMAGE}, min = 2, max = 4, chance = 5 },
        { id = TOOLTIP_ATTRIBUTE_INCREMENTS, type = {COMBAT_ENERGYDAMAGE, COMBAT_EARTHDAMAGE, COMBAT_FIREDAMAGE, COMBAT_DEATHDAMAGE, COMBAT_HOLYDAMAGE, COMBAT_ICEDAMAGE}, min = 1, max = 2, chance = 1 },
        { id = TOOLTIP_ATTRIBUTE_CRITICALHIT_CHANCE, min = 1, max = 2, chance = 1 },
    }

    for _, attr in ipairs(attributes) do
        if math.random(1, 100) <= attr.chance then
            local value = math.random(attr.min, attr.max)
            item:setAttribute(attr.id, value)
        end
    end
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    -- Sprawdzenie, czy przedmiot używany to skrzynia
    if item.itemid ~= CHEST_ID then
        return false
    end

    -- Losowanie broni z listy
    local randomIndex = math.random(1, #weapons)
    local weaponId = weapons[randomIndex]

    -- Losowanie rzadkości
    local rarityId = getRandomRarity()

    -- Tworzenie losowej broni w plecaku gracza
    local newItem = player:addItem(weaponId, 1)
    if newItem then
        -- Nadanie unikatowych atrybutów na podstawie rzadkości
        applyRarityAttributes(newItem, rarityId)

        -- Usunięcie skrzyni po użyciu
        player:removeItem(CHEST_ID, 1)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have received a unique weapon!")
    else
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "Your inventory is full. Clear some space and try again.")
    end

    return true
end
i try with this code but don't work
 
i try with this code but don't work
It looks like AI hallucination.

You cannot modify element damage attributes with OTS engine. They are not stored in database, they are always loaded from items.xml, so each item with ID X must have same element damage value.
To make it work, you would need a lot of C++ changes in engine, to make it store element damage attributes in database and to load it from individual item, not .xml in every place it uses element damage in C++/Lua.
 
so why is it that when I kill a monster I get a Saber with random attributes and rarity, and when I kill a monster, I get no rarity
Post automatically merged:

<item id="2385" article="a" name="sabre">
<attribute key="weight" value="2500" />
<attribute key="defense" value="10" />
<attribute key="loottype" value="equipment" />
<attribute key="attack" value="12" />
<attribute key="elementEarth" value="1" />
<attribute key="weaponType" value="sword" />
<attribute key="extradef" value="1" />
</item>
this is my drop from mobz moba.webp and this is my drop from chest z skrzyni.webp

If it drops from the mob with bonuses, how can I make it drop from the chest with bonuses?
 
Last edited by a moderator:
If it drops from the mob with bonuses, how can I make it drop from the chest with bonuses?
If you already got code to drop monster items with bonuses in engine, post how engine adds these attributes into items (Lua/C++).
Normal TFS cannot add 'element damage' to items. It's declared in items.xml and cannot be modified.
<attribute key="elementEarth" value="1" />
That's exactly how it looks like in items.xml. Does your mobs drop item ID 2385 with different elementEarth values (post how they do it) or it drops multiple item IDs and they have different elements bonuses?
 
oh i missunderstand your request, well that return anything?

TOOLTIP_ATTRIBUTE_INCREMENTS
ITEM_RARITY_COMMON

this item:setAttribute(x, x)
seems to return nil

do you register this in source, its work like that?
show the code where boss dying that will help a lot.
 
Last edited:
Back
Top