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

RevScripts setAttribute on itens

Belfahar

New Member
Joined
Jul 21, 2016
Messages
25
Reaction score
3
Hey guys!

Now i'm trying to create a very simple system. The player uses the hammer (37171) on the demon shield and it receives some attributes. However, it doesn't work.

Lua:
local ForgeCreation = Action()

function ForgeCreation.onUse(player, item, fromPosition, target, toPosition, isHotkey)
  
    if target.itemid == 3420 then
        item:setAttribute(DEFENSE, 88)
        item:setAttribute(DESCRIPTION, "Defense Upgrade")
        item:setAttribute(TIER, 3)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'Upgrade sucess.')
        return true
    end

end

ForgeCreation:id(37171)
ForgeCreation:register()


The player receives the success message, but nothing happens. Not even an error is indicated on the client.
 
You can find your attributeType enums near the top of item.h in the sources. They are listed under the variable name: AttrTypes_t.

Although, I'm unfamiliar with tier, and probably specific to your server distro. So you need to check where that is, and find the right enum or integer for it orrr..... It's a custom attribute, which you should then use item:setCustomAttribute() instead.

Lua:
local ForgeCreation = Action()

function ForgeCreation.onUse(player, item, fromPosition, target, toPosition, isHotkey)
 
    if target.itemid == 3420 then
        item:setAttribute(ATTR_DEFENSE, 88)
        item:setAttribute(ATTR_DESC, "Defense Upgrade")
        item:setAttribute(TIER, 3)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'Upgrade successful.')
    end
    return true

end

ForgeCreation:id(37171)
ForgeCreation:register()
 
@Fjorda
I change item: for target: and its work. Some changes works but life leech, mana leech and skills don't. Does anyone know what the parameter is to modify these attributes? On Canary.

Lua:
local HammerCreation = Action()

function HammerCreation.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local itemId = item:getId()
    
    if itemId == 37171 then
        local targetItemId = target:getId()
        
        if targetItemId == 34084 then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Works!")
            target:setAttribute(ITEM_ATTRIBUTE_ATTACK, 150)    -- OK
            target:setCustomAttribute(ITEM_PARSE_LIFELEECHAMOUNT, 900) -- Not Work
            target:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, "Upgraded.")    -- OK
            target:setTier(10) -- OK
        else
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Be carefull.")
        end
    end
    return true
end

HammerCreation:id(37171)
HammerCreation:register()
 
@Fjorda
I change item: for target: and its work. Some changes works but life leech, mana leech and skills don't. Does anyone know what the parameter is to modify these attributes? On Canary.

Lua:
local HammerCreation = Action()

function HammerCreation.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local itemId = item:getId()
   
    if itemId == 37171 then
        local targetItemId = target:getId()
       
        if targetItemId == 34084 then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Works!")
            target:setAttribute(ITEM_ATTRIBUTE_ATTACK, 150)    -- OK
            target:setCustomAttribute(ITEM_PARSE_LIFELEECHAMOUNT, 900) -- Not Work
            target:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, "Upgraded.")    -- OK
            target:setTier(10) -- OK
        else
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Be carefull.")
        end
    end
    return true
end

HammerCreation:id(37171)
HammerCreation:register()
Ahh sorry, didn't realise you wanted the attributes on the target.

So canary has a magic prefix of "ITEM_ATTRIBUTE_". and the list of attributes are by default:
C++:
enum ItemAttribute_t : uint64_t {
    NONE = 0,
    ACTIONID = 1,
    UNIQUEID = 2,
    DESCRIPTION = 3,
    TEXT = 4,
    DATE = 5,
    WRITER = 6,
    NAME = 7,
    ARTICLE = 8,
    PLURALNAME = 9,
    WEIGHT = 10,
    ATTACK = 11,
    DEFENSE = 12,
    EXTRADEFENSE = 13,
    ARMOR = 14,
    HITCHANCE = 15,
    SHOOTRANGE = 16,
    OWNER = 17,
    DURATION = 18,
    DECAYSTATE = 19,
    CORPSEOWNER = 20,
    CHARGES = 21,
    FLUIDTYPE = 22,
    DOORID = 23,
    SPECIAL = 24,
    IMBUEMENT_SLOT = 25,
    OPENCONTAINER = 26,
    QUICKLOOTCONTAINER = 27,
    DURATION_TIMESTAMP = 28,
    AMOUNT = 29,
    TIER = 30,
    STORE = 31,
    CUSTOM = 32,
    LOOTMESSAGE_SUFFIX = 33,
    STORE_INBOX_CATEGORY = 34,
};


If your specific attribute isn't here, it will be a custom attribute.
 
@Fjorda I've tried various possibilities and still haven't succeeded. I've searched through the sources looking for definitions, but I still don't know how to apply them in the script.

I wanted to better understand the application of the Custom and Special conditions. Or if perhaps I could apply the bonus using the path of imbuements.

C++:
setAttribute(ITEM_ATTRIBUTE_CUSTOM, value)
setAttribute(ITEM_ATTRIBUTE_SPECIAL, value)
setAttribute(ITEM_ATTRIBUTE_IMBUEMENT_SLOT, value)

addItemImbuementStats(imbuement)
addImbuement(slot, imbuement->getID(), baseImbuement->duration)

setCustomAttribute(const std::string &key, const bool value)
addCustomAttribute(key, customAttribute)
removeCustomAttribute(const std::string &attributeName)


ItemParse::parseShowAttributes(tmpStrValue, valueAttribute, itemType)
ItemParse::parseCriticalHit(tmpStrValue, valueAttribute, itemType);
ItemParse::parseLifeAndManaLeech(tmpStrValue, valueAttribute, itemType);
ItemParse::parseMaxHitAndManaPoints(tmpStrValue, valueAttribute, itemType);

itemType.getAbilities().skills[SKILL_CRITICAL_HIT_CHANCE] = pugi::cast<int32_t>(valueAttribute.value()
itemType.getAbilities().skills[SKILL_LIFE_LEECH_AMOUNT] = pugi::cast<int32_t>(valueAttribute.value()
itemType.getAbilities().skills[SKILL_MANA_LEECH_AMOUNT] = pugi::cast<int32_t>(valueAttribute.value()
itemType.getAbilities().statsPercent[STAT_MAXHITPOINTS] = pugi::cast<int32_t>(valueAttribute.value()
itemType.getAbilities().statsPercent[STAT_MAXMANAPOINTS] = pugi::cast<int32_t>(valueAttribute.value()


const phmap::flat_hash_map<std::string, ImbuementTypes_t> ImbuementsTypeMap = {
    { "elemental damage", IMBUEMENT_ELEMENTAL_DAMAGE },
    { "life leech", IMBUEMENT_LIFE_LEECH },
    { "mana leech", IMBUEMENT_MANA_LEECH },
    { "critical hit", IMBUEMENT_CRITICAL_HIT },
    { "elemental protection death", IMBUEMENT_ELEMENTAL_PROTECTION_DEATH },
    { "elemental protection earth", IMBUEMENT_ELEMENTAL_PROTECTION_EARTH },
    { "elemental protection fire", IMBUEMENT_ELEMENTAL_PROTECTION_FIRE },
    { "elemental protection ice", IMBUEMENT_ELEMENTAL_PROTECTION_ICE },
    { "elemental protection energy", IMBUEMENT_ELEMENTAL_PROTECTION_ENERGY },
    { "elemental protection holy", IMBUEMENT_ELEMENTAL_PROTECTION_HOLY },
    { "increase speed", IMBUEMENT_INCREASE_SPEED },
    { "skillboost axe", IMBUEMENT_SKILLBOOST_AXE },
    { "skillboost sword", IMBUEMENT_SKILLBOOST_SWORD },
    { "skillboost club", IMBUEMENT_SKILLBOOST_CLUB },
    { "skillboost shielding", IMBUEMENT_SKILLBOOST_SHIELDING },
    { "skillboost distance", IMBUEMENT_SKILLBOOST_DISTANCE },
    { "skillboost magic level", IMBUEMENT_SKILLBOOST_MAGIC_LEVEL },
    { "increase capacity", IMBUEMENT_INCREASE_CAPACITY }
};

getCustomAttribute(std::to_string(ITEM_IMBUEMENT_SLOT + slot))
setCustomAttribute(std::to_string(ITEM_IMBUEMENT_SLOT + slot), valueDuration)

getCombatName
getSkillName
 
Just check your items.cpp and check how it serializes/deserializes the custom attributes for imbuements. Then you know which the correct enum is.

You could try IMBUEMENT_LIFE_LEECH but im not exactly sure if this is for the amount without any further data.
 
Back
Top