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

Solved help with item change attributes depending of vocation

ijuchia

New Member
Joined
Dec 30, 2014
Messages
17
Reaction score
1
TFS 1.X

I'm looking for a script where a item changes its stats depending on the vocation

for example a helmet
that if the vocation is knight onlook i see helmet arm:10 +1 sword +1 axe + club
that if the vocation is a mage i see helmet arm:10 +1 magic level
or paladin i see helmet arm:10 +1 distance

first of all, Thanks
 
Solution
movement script
[Lua] --// Do not touch local conditionSlots = { [CONST_SLOT_HEAD] = {condition - Pastebin.com

in events/scripts/player.lua
under
Lua:
local decayId = itemType:getDecayId()
if decayId ~= -1 then
    description = string.format("%s\nDecays to: %d", description, decayId)
end
add
Lua:
local itemBonus = itemBonusConfig[thing:getId()]
if itemBonus then
    local vocBonuses = itemBonus[self:getVocation():getId()]
    if vocBonuses then
        for _, v in pairs(vocBonuses) do
            if v.string then
                description = string.format("%s\n+%d %s", description, v.value, v.string)
            elseif v.strings then
                local strings = {"+".. v.value .." "}
                local size = #v.strings...
movement script
[Lua] --// Do not touch local conditionSlots = { [CONST_SLOT_HEAD] = {condition - Pastebin.com

in events/scripts/player.lua
under
Lua:
local decayId = itemType:getDecayId()
if decayId ~= -1 then
    description = string.format("%s\nDecays to: %d", description, decayId)
end
add
Lua:
local itemBonus = itemBonusConfig[thing:getId()]
if itemBonus then
    local vocBonuses = itemBonus[self:getVocation():getId()]
    if vocBonuses then
        for _, v in pairs(vocBonuses) do
            if v.string then
                description = string.format("%s\n+%d %s", description, v.value, v.string)
            elseif v.strings then
                local strings = {"+".. v.value .." "}
                local size = #v.strings
                for i = 1, size do
                    local string = v.strings[i]
                    strings[#strings+1] = string .. (i ~= size and ", " or "")
                end
                description = string.format("%s\n%s", description, table.concat(strings))
            end
        end
    end
end

note: if you use this some things wont properly work like regeneration or absorb % on items (since you have to use a script for onEquip and onDeEquip)
if you want it to still work, you need to change MoveEvent::fireEquip in movements.cpp to this:
C++:
uint32_t MoveEvent::fireEquip(Player* player, Item* item, slots_t slot, bool boolean)
{
    if (scripted) {
        if (getEventType() == MOVE_EVENT_EQUIP) {
            EquipItem(this, player, item, slot, boolean);
        } else if (getEventType() == MOVE_EVENT_DEEQUIP) {
            DeEquipItem(this, player, item, slot, boolean);
        }
        return executeEquip(player, item, slot);
    } else {
        return equipFunction(this, player, item, slot, boolean);
    }
}
 
Last edited:
Solution
movement script
[Lua] --// Do not touch local conditionSlots = { [CONST_SLOT_HEAD] = {condition - Pastebin.com

in events/scripts/player.lua
under
Lua:
local decayId = itemType:getDecayId()
if decayId ~= -1 then
    description = string.format("%s\nDecays to: %d", description, decayId)
end
add
Lua:
local itemBonus = itemBonusConfig[thing:getId()]
if itemBonus then
    local vocBonuses = itemBonus[self:getVocation():getId()]
    if vocBonuses then
        for _, v in pairs(vocBonuses) do
            if v.string then
                description = string.format("%s\n+%d %s", description, v.value, v.string)
            elseif v.strings then
                local strings = {"+".. v.value .." "}
                local size = #v.strings
                for i = 1, size do
                    local string = v.strings[i]
                    strings[#strings+1] = string .. (i ~= size and ", " or "")
                end
                description = string.format("%s\n%s", description, table.concat(strings))
            end
        end
    end
end

note: if you use this some things wont properly work like regeneration or absorb % on items (since you have to use a script for onEquip and onDeEquip)
if you want it to still work, you need to change MoveEvent::fireEquip in movements.cpp to this:
C++:
uint32_t MoveEvent::fireEquip(Player* player, Item* item, slots_t slot, bool boolean)
{
    if (scripted) {
        if (getEventType() == MOVE_EVENT_EQUIP) {
            EquipItem(this, player, item, slot, boolean);
        } else if (getEventType() == MOVE_EVENT_DEEQUIP) {
            DeEquipItem(this, player, item, slot, boolean);
        }
        return executeEquip(player, item, slot);
    } else {
        return equipFunction(this, player, item, slot, boolean);
    }
}

thank you very much, what a good man I am going to review
 
Will it work with custom vocations ? and how do i use the movement script ?
Yes, work with a custom vocation, you need to configure this part in yellow for the item you want and the number 1, 2, 3 ,4
are the vocation
Lua:
    [[COLOR=#ffff00]2506[/COLOR]] = {
        [1] = {
            {param = CONDITION_PARAM_STAT_MAGICPOINTS, value = 1, string = "Magic Level"}
        },
        [2] = {
            {param = CONDITION_PARAM_STAT_MAGICPOINTS, value = 1, string = "Magic Level"}
        },
        [3] = {
            {param = CONDITION_PARAM_SKILL_DISTANCE, value = 1, string = "Distance"}
        },
        [4] = {
            {param = CONDITION_PARAM_SKILL_MELEE, value = 1, strings = {"Sword", "Axe", "Club", "Fist"}},
        },
    }
}
 
I added the c++ code and when im compiling i have this problem now. It says "function doesnt accept 3 arguments". How can i fix it ? Im suing tfs1.3
 

Attachments

Back
Top