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

Target:getDescription()

alejandro762

Well-Known Member
Joined
Sep 6, 2021
Messages
225
Reaction score
63
Hello,

I am using this script, ( something very similar posted already on forum with "sucess" and "fail" method ) i cannot find right now the post


Here is the code,
Do not pay attention about 'fail', that's normal the script got 300+ id, i have deleted all Id's to cet a small script here,

The script is working like a charm,
I Want add a "ITEM_ATTRIBUTE_DESCRIPTION' with target:getDescription(), is working too but it show"s x2 Times the same Text i wish to know how to show It only one time, since i think im calling two times target, but i dont know why write there i tried upgradeId, itemEx, uid, item, keyConfig..
I added this line: target:setAttribute( ITEM_ATTRIBUTE_DESCRIPTION, target:getDescription().."\nRefined by "..player:getName()..".")

And i got , this: ( Some Description, is the <attribute key="description" value="Some Description" /> from items.xml )
I wish get The description from items.xml + the description who has upgraded the item.
Code:
16:03 You see a Excalibur Wand +5 (damage reflect: 5% all elements, critical hit chance 8%, critical extra damage +8%, magic level +7, protection physical +8%, holy +8%, death +8%).
It can only be wielded properly by sorcerers and druids of level 300 or higher.
Imbuements: (Empty Slot, Empty Slot, Empty Slot).
It weighs 33.00 oz.
a Excalibur Wand +5 (damage reflect: 5% all elements, critical hit chance 8%, critical extra damage +8%, magic level +7, protection physical +8%, holy +8%, death +8%).
It can only be wielded properly by sorcerers and druids of level 300 or higher.
Imbuements: (Empty Slot, Empty Slot, Empty Slot).
It weighs 33.00 oz.
Some description.
Refined by GOD.
Code:
local action = Action()

local config = {
    messages = {
        success = {
            text  = 'Your item has been upgraded to the next Tier!',
            talkType = TALKTYPE_MONSTER_SAY,
            effect   = CONST_ME_FIREWORK_RED
        },

        fail = {
            text  = 'Upgrade Failed.',
            talkType = TALKTYPE_MONSTER_SAY,
            effect   = CONST_ME_POFF
        }

    },

    gear = {
        [7865] = {tier = 1, upgraderType = 'rune', chance = 30,
            items = {
                [42033] = 40804,
         
            },
        },
    }
}

function action.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    -- Using player's position if the target item is located in a container, otherwise use the item's position located on the map
    local pos = target:getPosition().x == 65535 and player:getPosition() or target:getPosition()
    -- Make sure the player is not attempting to target a creature
    if not target:isItem() then
        player:sendCancelMessage('You must select an item.')
        pos:sendMagicEffect(CONST_ME_POFF)
        return true
    end
    -- Attempt to get the config based on which key id the player is using
    local keyConfig = config.gear[item:getId()]
    -- Adding article to full item name if possible, ex: "a sword"
    local name  = (target:getArticle() ~= '') and string.format('%s %s', target:getArticle(), target:getName()) or target:getName()
    if keyConfig then
        -- Directly attempt to access the item id to upgrade to by indexing the item list with the target item's id
        local upgradeId = keyConfig.items[target:getId()]
        -- Prevent attempting to upgrade an item that isn't in config
        if not upgradeId then
            player:sendCancelMessage(string.format('You are unable to upgrade %s with a tier %d %s.', (name == '') and 'this' or name, keyConfig.tier, keyConfig.upgraderType))
            pos:sendMagicEffect(CONST_ME_POFF)
            return true
        end
        -- Prevent attempting to upgrade a stackable item that has more than 1 in it's stack
        if target:getCount() > 1 then
            player:sendCancelMessage('You may only upgrade this item one at a time.')
            pos:sendMagicEffect(CONST_ME_POFF)
            return true
        end
        -- Use the "success" table in config if the random value is less than or equal to the chance, otherwise use the "fail" table
        local confKey = (math.random(100) <= keyConfig.chance and 'success' or 'fail')
        local resultConfig = config.messages[confKey]
        pos:sendMagicEffect(resultConfig.effect)
        player:say(resultConfig.text, resultConfig.talkType)
        if confKey == 'success' then
            target:transform(upgradeId)
            target:setAttribute( ITEM_ATTRIBUTE_DESCRIPTION, target:getDescription().."\nRefined by "..player:getName()..".")
        end
        if confKey == 'fail' and target.itemid == 40804 then
            target:transform(42033)
        end
        item:remove(1)
    end
    return true
end


for keyId, _ in pairs(config.gear) do
    action:id(keyId)
end
action:aid(7865, 7866, 7867) -- El item que hara upgrade
action:register()
 
Last edited:
Use ItemType(target:getId()):getDescription() instead
ItemType its the constructor to return the data from items.xml
My bad, exactly, i see now on luascript.cpp,
I forget to check that on sources.
Right now i understand how it works.
Thanks you @Roddet
Lua:
// itemType:getDescription()
    const ItemType* itemType = getUserdata<const ItemType>(L, 1);
    if (itemType) {
        pushString(L, itemType->description);
    } else {
        lua_pushnil(L);
    }
    return 1;
 
Back
Top