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

TFS 1.X+ I have doubts about onMoveItem or another function tfs 1.4.2

Mateus Robeerto

Excellent OT User
Joined
Jun 5, 2016
Messages
1,337
Solutions
71
Reaction score
697
Location
ლ(ಠ益ಠლ)
I would like to know if it is possible to implement the functionality of gaining attributes when using specific items and having them disappear when unequipped. I am unsure if I need to use onMoveItem. I have some doubts about how to do this. Thank you very much for your attention.

I took Levi's script and adapted it to show the appearance of the item and keep the description permanent...

Lua:
local config = {
    itemUse = 8301,
    itemTarget = 2400,
    effect = CONST_ME_MAGIC_RED,
    removeItem = false,
}

local action = Action()

function action.onUse(player, item, fromPos, target, toPos, isHotkey)
    if target.itemid == config.itemTarget then
        if config.removeItem then
            item:remove()
        end

        local skillType
        local skillAmount
        local skillDescription
        local randomNumber = math.random(0, 100)
        
        if randomNumber <= 10 then
            skillAmount = math.random(0, 10)
        elseif randomNumber <= 40 then
            skillAmount = math.random(11, 40)
        elseif randomNumber <= 70 then
            skillAmount = math.random(41, 70)
        else
            skillAmount = math.random(71, 100)
        end

        local randomSkill = math.random(1, 4)
        
        if randomSkill == 1 then
            skillType = CONDITION_PARAM_SKILL_SWORD
            skillDescription = "Sword"
        elseif randomSkill == 2 then
            skillType = CONDITION_PARAM_SKILL_AXE
            skillDescription = "Axe"
        elseif randomSkill == 3 then
            skillType = CONDITION_PARAM_SKILL_CLUB
            skillDescription = "Club"
        else
            skillType = CONDITION_PARAM_SKILL_FIST
            skillDescription = "Fist"
        end
        
        local description = skillDescription .. " +" .. skillAmount .. " Skill."
        target:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, description)
        player:sendTextMessage(MESSAGE_INFO_DESCR, description)
        
        local skill = Condition(CONDITION_ATTRIBUTES)
        skill:setParameter(skillType, skillAmount)
        player:addCondition(skill)
        
        player:getPosition():sendMagicEffect(config.effect)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'Buff activated.')
        
    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You can only use this on a specific weapon.')
    end
    return true
end

action:id(config.itemUse)
action:register()

The Oen upgrade system for TFS 1.3/1.4 is really pleasing me. However, his script is quite extensive. I can't remove some parts I don't want. I would like to have separate scripts for each specific item, including common, rare, epic and legendary.

See the image, that's why I'm doing specific upgrades for common and rare items, epics, etc., separating the stones, etc. It's just that, something simple... Can anyone help me?
 
Last edited:
You can create separate scripts for rare, epic, and legendary
item upgrades by duplicating this code and adjusting the logic for each specific item type.
Customize the logic inside the onUse function according
to your needs for each item type.

Try This

Lua:
local config = {
    itemUse = 8301,
    itemTarget = 2400,
    effect = CONST_ME_MAGIC_RED,
    removeItem = false,
}

local action = Action()

function action.onUse(player, item, fromPos, target, toPos, isHotkey)
    if target.itemid == config.itemTarget then
        if config.removeItem then
            item:remove()
        end

        -- increase the item's attack value by 10%
       
        if target:isWeapon() then
            local attackValue = target:getAttribute(ITEM_ATTRIBUTE_ATTACK)
            local upgradedAttackValue = math.ceil(attackValue * 1.1) -- Increase by 10%
            target:setAttribute(ITEM_ATTRIBUTE_ATTACK, upgradedAttackValue)
            player:sendTextMessage(MESSAGE_INFO_DESCR, 'Common Item Upgrade: Weapon attack increased.')


        else
            player:sendTextMessage(MESSAGE_INFO_DESCR, 'Common Item Upgrade: No effect on this item type.')
        end

        player:getPosition():sendMagicEffect(config.effect)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'Common Item Upgrade activated.')

    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You can only use this on a specific weapon.')
    end
    return true
end

action:id(config.itemUse)
action:register()

make a few such separate scripts
and change this look

Lua:
- Rare Item Upgrade Script
local config = {
    itemUse = 8302, -- Unique item ID for rare item upgrades
    itemTarget = 2401, -- Unique item ID for rare items
    effect = CONST_ME_MAGIC_BLUE,
    removeItem = false,
}

Code:
- Epic Item Upgrade Script
local config = {
    itemUse = 8303, -- Unique item ID for epic item upgrades
    itemTarget = 2402, -- Unique item ID for epic items
    effect = CONST_ME_MAGIC_GREEN,
    removeItem = false,
}

Code:
- Legendary Item Upgrade Script
local config = {
    itemUse = 8304, -- Unique item ID for legendary item upgrades
    itemTarget = 2403, -- Unique item ID for legendary items
    effect = CONST_ME_MAGIC_YELLOW,
    removeItem = false,
}
 
You can create separate scripts for rare, epic, and legendary
item upgrades by duplicating this code and adjusting the logic for each specific item type.
Customize the logic inside the onUse function according
to your needs for each item type.

Try This

Lua:
local config = {
    itemUse = 8301,
    itemTarget = 2400,
    effect = CONST_ME_MAGIC_RED,
    removeItem = false,
}

local action = Action()

function action.onUse(player, item, fromPos, target, toPos, isHotkey)
    if target.itemid == config.itemTarget then
        if config.removeItem then
            item:remove()
        end

        -- increase the item's attack value by 10%
      
        if target:isWeapon() then
            local attackValue = target:getAttribute(ITEM_ATTRIBUTE_ATTACK)
            local upgradedAttackValue = math.ceil(attackValue * 1.1) -- Increase by 10%
            target:setAttribute(ITEM_ATTRIBUTE_ATTACK, upgradedAttackValue)
            player:sendTextMessage(MESSAGE_INFO_DESCR, 'Common Item Upgrade: Weapon attack increased.')


        else
            player:sendTextMessage(MESSAGE_INFO_DESCR, 'Common Item Upgrade: No effect on this item type.')
        end

        player:getPosition():sendMagicEffect(config.effect)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'Common Item Upgrade activated.')

    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You can only use this on a specific weapon.')
    end
    return true
end

action:id(config.itemUse)
action:register()

make a few such separate scripts
and change this look

Lua:
- Rare Item Upgrade Script
local config = {
    itemUse = 8302, -- Unique item ID for rare item upgrades
    itemTarget = 2401, -- Unique item ID for rare items
    effect = CONST_ME_MAGIC_BLUE,
    removeItem = false,
}

Code:
- Epic Item Upgrade Script
local config = {
    itemUse = 8303, -- Unique item ID for epic item upgrades
    itemTarget = 2402, -- Unique item ID for epic items
    effect = CONST_ME_MAGIC_GREEN,
    removeItem = false,
}

Code:
- Legendary Item Upgrade Script
local config = {
    itemUse = 8304, -- Unique item ID for legendary item upgrades
    itemTarget = 2403, -- Unique item ID for legendary items
    effect = CONST_ME_MAGIC_YELLOW,
    removeItem = false,
}
Thanks for responding... This script is similar to what I've already done. I separated the four stones for each specification... But I want to add, for example, random skill values, such as +10 in sword and +8 in axe, when equipping the items. Attributes appear when equipping and disappear when unequipping. He understands? That's all I want, something simple like that. The script in this post is about random attributes... Thanks again.
 
Try this

Lua:
local config = {
    itemUse = 8301,
    itemTarget = 2400,
    effect = CONST_ME_MAGIC_RED,
    removeItem = false,
}

local action = Action()

function action.onUse(player, item, fromPos, target, toPos, isHotkey)
    if target.itemid == config.itemTarget then
        if config.removeItem then
            item:remove()
        end

        if target:isWeapon() then
       
            local swordSkill = math.random(1, 10) -- Random skill value for sword
            local axeSkill = math.random(1, 8)   -- Random skill value for axe

            player:setStorageValue("swordSkill", player:getStorageValue("swordSkill") + swordSkill)
            player:setStorageValue("axeSkill", player:getStorageValue("axeSkill") + axeSkill)

            player:sendTextMessage(MESSAGE_INFO_DESCR, 'Common Item Upgrade: Equipped with +' .. swordSkill .. ' Sword and +' .. axeSkill .. ' Axe.')

        else
            player:sendTextMessage(MESSAGE_INFO_DESCR, 'Common Item Upgrade: No effect on this item type.')
        end

        player:getPosition():sendMagicEffect(config.effect)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'Common Item Upgrade activated.')

    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You can only use this on a specific weapon.')
    end
    return true
end

action:id(config.itemUse)
action:register()
 
I tested and tried to equip the sword, but nothing happened, the attributes don't appear... And you even removed the item description when looking at the item... But the script I created is working normally and you can still see the description with random skills, but the attributes don't appear when equipping... I don't know if I need to add an event, like onMoveItem or something, I don't know...
 
check

Lua:
local config = {
    itemUse = 8301,
    itemTarget = 2400,
    effect = CONST_ME_MAGIC_RED,
    removeItem = false,
}

local action = Action()

function onEquipWeapon(player, item)

    local swordSkill = math.random(1, 10) -- Random skill value for sword
    local axeSkill = math.random(1, 8)   -- Random skill value for axe

    player:setStorageValue("swordSkill", player:getStorageValue("swordSkill") + swordSkill)
    player:setStorageValue("axeSkill", player:getStorageValue("axeSkill") + axeSkill)

    player:sendTextMessage(MESSAGE_INFO_DESCR, 'Equipped with +' .. swordSkill .. ' Sword and +' .. axeSkill .. ' Axe.')
end

function onDeEquipWeapon(player, item)

    local swordSkill = item:getAttribute(ITEM_ATTRIBUTE_SWORD_SKILL)
    local axeSkill = item:getAttribute(ITEM_ATTRIBUTE_AXE_SKILL)

    player:setStorageValue("swordSkill", player:getStorageValue("swordSkill") - swordSkill)
    player:setStorageValue("axeSkill", player:getStorageValue("axeSkill") - axeSkill)
end

function action.onUse(player, item, fromPos, target, toPos, isHotkey)
    if target.itemid == config.itemTarget then
        if config.removeItem then
            item:remove()
        end

        if target:isWeapon() then
            onEquipWeapon(player, target)
        else
            player:sendTextMessage(MESSAGE_INFO_DESCR, 'Common Item Upgrade: No effect on this item type.')
        end

        player:getPosition():sendMagicEffect(config.effect)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'Common Item Upgrade activated.')
    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You can only use this on a specific weapon.')
    end
    return true
end

action:id(config.itemUse)
action:register()

local function onEquipEvent(player, item)
    if item:getId() == 2400 then
        onEquipWeapon(player, item)
    end
end

local function onDeEquipEvent(player, item)
    if item:getId() == 2400 then
        onDeEquipWeapon(player, item)
    end
end

player:onEquip(onEquipEvent)
player:onDeEquip(onDeEquipEvent)
 
Back
Top