• 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 Item Enchanting

delikerem

Member
Joined
Jan 9, 2020
Messages
118
Solutions
1
Reaction score
15
Hello,

I would like to request a revscript, I want this script just like normal "enchanting system" enchante other wepons without giving any charges.
I want to still use enchanted small sapphire etc to enchante my new weapons.

The idea is as following:
Enchante lets say Sov, this enchante gives for example +5 fire damage and can be editable.
This enchante should not make this item change in to firery item as the orginal script.
When I use another enchate lets say small sapphire witch is ice it should turn the item to +5 ice dmg and remove the old enchante.
The enchante shouldnt remove the orginal stats from the item.

I have been looking for something similar but couldnt find so I hope that someone could help me with this one.

I am using Tfx 1.4.2 10.98
 
I’m not sure if this is what you were looking for, but take a look at this topic. It includes enchanted elements and other things.
 
Hey

I have seen this one but its not it i need a script that looks like The real tibia version exept there wondering be any charges and that i can can freely choose my enchatns
 
Hey,

I didnt know that they removed the enchants, i am talking about the old style enchants that were used on spike swords etc.
 
Hey,

I didnt know that they removed the enchants, i am talking about the old style enchants that were used on spike swords etc.
Ok yeah, those were dropped in favor of imbuements. I would check on xikini's free scripting service to see if its already been made there and if not, check sarahs free scripting service. If its not made on either of those threads, try requesting it (be specific about what you want) on those threads, and maybe one of them will make it for you.

Otherwise its not a hard one to make yourself. You can simply use the onHealthChange creaturescript, which has a thorough explanation on how to use it here CreatureEvent | OTS Guide (https://docs.otland.net/ots-guide/tfs-documentation/luascript-interface/creatureevent#onhealthchange-creature-attacker-primarydamage-primarytype-secondarydamage-secondarytype-origin)

If you need more example code, like for instance, how to make it revscript style, you can go to the link titled "Legendary Custom Equipment" in my signature, it has a script that contains some sample code you could learn from.
 
Ok yeah, those were dropped in favor of imbuements. I would check on xikini's free scripting service to see if its already been made there and if not, check sarahs free scripting service. If its not made on either of those threads, try requesting it (be specific about what you want) on those threads, and maybe one of them will make it for you.

Otherwise its not a hard one to make yourself. You can simply use the onHealthChange creaturescript, which has a thorough explanation on how to use it here CreatureEvent | OTS Guide (https://docs.otland.net/ots-guide/tfs-documentation/luascript-interface/creatureevent#onhealthchange-creature-attacker-primarydamage-primarytype-secondarydamage-secondarytype-origin)

If you need more example code, like for instance, how to make it revscript style, you can go to the link titled "Legendary Custom Equipment" in my signature, it has a script that contains some sample code you could learn from.
I have checked but there are nothing that works like I want
Post automatically merged:

If I'm not mistaken, this is what you were looking for from that old enchantment system; look, I found it here.

Yes but for this script i just want to add fire dmg or ice w/e without making any charges on that item, also i want this script to be able to switch between The elements without any delay with The diamonds
 
I have checked but there are nothing that works like I want
Post automatically merged:


Yes but for this script i just want to add fire dmg or ice w/e without making any charges on that item, also i want this script to be able to switch between The elements without any delay with The diamonds
Then edit this script. Learn how to make the adjustments you want to get what you need.

Or like I already previously stated, you can try requesting on xikini's free scripting service thread.
 
I made it fully in RevScript, and the other one that you wanted like this... I'll send both.

LUA:
local config = {
    equipment = {
        2383, 2391, 2423, 2429, 2430, 2445, 2454, 7380, 7383, 7384, 7389, 7392,
        7402, 7406, 7415, 8905, 10022, 24716, 24718
    },
    valuables = {2146, 2147, 2149, 2150},
    enchantItems = {2342, 7759, 7760, 7761, 7762, 24739},
    shrines = {
        ice = {7508, 7509, 7510, 7511},
        fire = {7504, 7505, 7506, 7507},
        earth = {7516, 7517, 7518, 7519},
        energy = {7512, 7513, 7514, 7515}
    }
}

local items = {
    equipment = {
        [2147] = { -- small ruby
            [COMBAT_FIREDAMAGE] = {id = 2343, targetId = 2147} -- helmet of the ancients (enchanted)
        },
        [2383] = { -- spike sword
            [COMBAT_FIREDAMAGE] = {id = 7744}, [COMBAT_ICEDAMAGE] = {id = 7763},
            [COMBAT_EARTHDAMAGE] = {id = 7854}, [COMBAT_ENERGYDAMAGE] = {id = 7869}
        },
        [2391] = { -- war hammer
            [COMBAT_FIREDAMAGE] = {id = 7758}, [COMBAT_ICEDAMAGE] = {id = 7777},
            [COMBAT_EARTHDAMAGE] = {id = 7868}, [COMBAT_ENERGYDAMAGE] = {id = 7883}
        },
        [2423] = { -- clerical mace
            [COMBAT_FIREDAMAGE] = {id = 7754}, [COMBAT_ICEDAMAGE] = {id = 7773},
            [COMBAT_EARTHDAMAGE] = {id = 7864}, [COMBAT_ENERGYDAMAGE] = {id = 7879}
        },
        [2429] = { -- barbarian axe
            [COMBAT_FIREDAMAGE] = {id = 7749}, [COMBAT_ICEDAMAGE] = {id = 7768},
            [COMBAT_EARTHDAMAGE] = {id = 7859}, [COMBAT_ENERGYDAMAGE] = {id = 7874}
        },
        [2430] = { -- knight axe
            [COMBAT_FIREDAMAGE] = {id = 7750}, [COMBAT_ICEDAMAGE] = {id = 7769},
            [COMBAT_EARTHDAMAGE] = {id = 7860}, [COMBAT_ENERGYDAMAGE] = {id = 7875}
        },
        [2445] = { -- crystal mace
            [COMBAT_FIREDAMAGE] = {id = 7755}, [COMBAT_ICEDAMAGE] = {id = 7774},
            [COMBAT_EARTHDAMAGE] = {id = 7865}, [COMBAT_ENERGYDAMAGE] = {id = 7880}
        },
        [2454] = { -- war axe
            [COMBAT_FIREDAMAGE] = {id = 7753}, [COMBAT_ICEDAMAGE] = {id = 7772},
            [COMBAT_EARTHDAMAGE] = {id = 7863}, [COMBAT_ENERGYDAMAGE] = {id = 7878}
        },
        [7380] = { -- headchopper
            [COMBAT_FIREDAMAGE] = {id = 7752}, [COMBAT_ICEDAMAGE] = {id = 7771},
            [COMBAT_EARTHDAMAGE] = {id = 7862}, [COMBAT_ENERGYDAMAGE] = {id = 7877}
        },
        [7383] = { -- relic sword
            [COMBAT_FIREDAMAGE] = {id = 7745}, [COMBAT_ICEDAMAGE] = {id = 7764},
            [COMBAT_EARTHDAMAGE] = {id = 7855}, [COMBAT_ENERGYDAMAGE] = {id = 7870}
        },
        [7384] = { -- mystic blade
            [COMBAT_FIREDAMAGE] = {id = 7746}, [COMBAT_ICEDAMAGE] = {id = 7765},
            [COMBAT_EARTHDAMAGE] = {id = 7856}, [COMBAT_ENERGYDAMAGE] = {id = 7871}
        },
        [7389] = { -- heroic axe
            [COMBAT_FIREDAMAGE] = {id = 7751}, [COMBAT_ICEDAMAGE] = {id = 7770},
            [COMBAT_EARTHDAMAGE] = {id = 7861}, [COMBAT_ENERGYDAMAGE] = {id = 7876}
        },
        [7392] = { -- orcish maul
            [COMBAT_FIREDAMAGE] = {id = 7757}, [COMBAT_ICEDAMAGE] = {id = 7776},
            [COMBAT_EARTHDAMAGE] = {id = 7867}, [COMBAT_ENERGYDAMAGE] = {id = 7882}
        },
        [7402] = { -- dragon slayer
            [COMBAT_FIREDAMAGE] = {id = 7748}, [COMBAT_ICEDAMAGE] = {id = 7767},
            [COMBAT_EARTHDAMAGE] = {id = 7858}, [COMBAT_ENERGYDAMAGE] = {id = 7873}
        },
        [7406] = { -- blacksteel sword
            [COMBAT_FIREDAMAGE] = {id = 7747}, [COMBAT_ICEDAMAGE] = {id = 7766},
            [COMBAT_EARTHDAMAGE] = {id = 7857}, [COMBAT_ENERGYDAMAGE] = {id = 7872}
        },
        [7415] = { -- cranial basher
            [COMBAT_FIREDAMAGE] = {id = 7756}, [COMBAT_ICEDAMAGE] = {id = 7775},
            [COMBAT_EARTHDAMAGE] = {id = 7866}, [COMBAT_ENERGYDAMAGE] = {id = 7881}
        },
        [8905] = { -- rainbow shield
            [COMBAT_FIREDAMAGE] = {id = 8906}, [COMBAT_ICEDAMAGE] = {id = 8907},
            [COMBAT_EARTHDAMAGE] = {id = 8909}, [COMBAT_ENERGYDAMAGE] = {id = 8908}
        },
        [10022] = { -- worn firewalker boots
            [COMBAT_FIREDAMAGE] = {id = 9933, say = {text = "Take the boots off first."}},
            slot = {type = CONST_SLOT_FEET, check = true}
        },
        [24716] = { -- werewolf amulet
            [COMBAT_NONE] = {
                id = 24717,
                effects = {failure = CONST_ME_POFF, success = CONST_ME_THUNDER},
                message = {text = "The amulet cannot be enchanted while worn."}
            },
            slot = {type = CONST_SLOT_NECKLACE, check = true}
        },
        [24718] = { -- werewolf helmet
            [COMBAT_NONE] = {
                id = {
                    [SKILL_CLUB] = {id = 24783},
                    [SKILL_SWORD] = {id = 24783},
                    [SKILL_AXE] = {id = 24783},
                    [SKILL_DISTANCE] = {id = 24783},
                    [SKILL_MAGLEVEL] = {id = 24783}
                },
                effects = {failure = CONST_ME_POFF, success = CONST_ME_THUNDER},
                message = {text = "The helmet cannot be enchanted while worn."},
                usesStorage = true
            },
            slot = {type = CONST_SLOT_HEAD, check = true}
        },
        charges = 1000, effect = CONST_ME_MAGIC_RED
    },

    valuables = {
        [2146] = {id = 7759, shrine = config.shrines.ice}, -- small sapphire
        [2147] = {id = 7760, shrine = config.shrines.fire}, -- small ruby
        [2149] = {id = 7761, shrine = config.shrines.earth}, -- small emerald
        [2150] = {id = 7762, shrine = config.shrines.energy}, -- small amethyst
        soul = 2, mana = 300, effect = CONST_ME_HOLYDAMAGE
    },

    [2342] = {combatType = COMBAT_FIREDAMAGE, targetId = 2147}, -- helmet of the ancients
    [7759] = {combatType = COMBAT_ICEDAMAGE}, -- small enchanted sapphire
    [7760] = {combatType = COMBAT_FIREDAMAGE}, -- small enchanted ruby
    [7761] = {combatType = COMBAT_EARTHDAMAGE}, -- small enchanted emerald
    [7762] = {combatType = COMBAT_ENERGYDAMAGE}, -- small enchanted amethyst
    [24739] = {combatType = COMBAT_NONE} -- moonlight crystals
}

local enchanting = Action()

function enchanting.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if not target or not target:isItem() then
        return false
    end

    local itemId, targetId = item:getId(), target:getId()
    local targetType = items.valuables[itemId] or items.equipment[items[itemId].targetId or targetId]
    if not targetType then
        return false
    end

    if targetType.shrine then
        if not isInArray(targetType.shrine, targetId) then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, Game.getReturnMessage(RETURNVALUE_NOTPOSSIBLE))
            return true
        end

        if player:getMana() < items.valuables.mana then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, Game.getReturnMessage(RETURNVALUE_NOTENOUGHMANA))
            return true
        end

        if player:getSoul() < items.valuables.soul then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, Game.getReturnMessage(RETURNVALUE_NOTENOUGHSOUL))
            return true
        end
        player:addSoul(-items.valuables.soul)
        player:addMana(-items.valuables.mana)
        player:addManaSpent(items.valuables.mana * configManager.getNumber(configKeys.RATE_MAGIC))
        player:addItem(targetType.id)
        player:getPosition():sendMagicEffect(items.valuables.effect)
        item:remove(1)
    else
        local targetItem = targetType[items[itemId].combatType]
        if not targetItem or targetItem.targetId and targetItem.targetId ~= targetId then
            return false
        end

        local isInSlot = targetType.slot and targetType.slot.check and target:getType():usesSlot(targetType.slot.type) and Player(target:getParent())
        if isInSlot then
            if targetItem.say then
                player:say(targetItem.say.text, TALKTYPE_MONSTER_SAY)
                return true
            elseif targetItem.message then
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, targetItem.message.text)
            else
                return false
            end
        else
            if targetItem.targetId then
                item:transform(targetItem.id)
                item:decay()
                target:remove(1)
            else
                if targetItem.usesStorage then
                    local vocationId = player:getVocation():getDemotion():getId()
                    local storage = storages[itemId] and storages[itemId][targetId] and storages[itemId][targetId][vocationId]
                    if not storage then
                        return false
                    end

                    local storageValue = player:getStorageValue(storage.key)
                    if storageValue == -1 then
                        return false
                    end

                    local transform = targetItem.id and targetItem.id[storageValue]
                    if not transform then
                        return false
                    end
                    target:transform(transform.id)
                else
                    target:transform(targetItem.id)
                end

                if target:hasAttribute(ITEM_ATTRIBUTE_DURATION) then
                    target:decay()
                end

                if target:hasAttribute(ITEM_ATTRIBUTE_CHARGES) then
                    target:setAttribute(ITEM_ATTRIBUTE_CHARGES, items.equipment.charges)
                end
                item:remove(1)
            end
        end
        player:getPosition():sendMagicEffect(targetItem.effects and (isInSlot and targetItem.effects.failure or targetItem.effects.success) or items.equipment.effect)
    end
    return true
end

for _, id in ipairs(config.equipment) do
    enchanting:id(id)
end

for _, id in ipairs(config.valuables) do
    enchanting:id(id)
end

for _, id in ipairs(config.enchantItems) do
    enchanting:id(id)
end

enchanting:register()


Take this simple script and modify it however you like to fit your needs!
simple.
LUA:
local SPIKE_SWORD_ID = 2383

local DIAMOND_IDS = {
    [7759] = {element = COMBAT_FIREDAMAGE, name = "Fire"},
    [7760] = {element = COMBAT_ICEDAMAGE, name = "Ice"},
    [7761] = {element = COMBAT_HOLYDAMAGE, name = "Holy"},
    [7762] = {element = COMBAT_EARTHDAMAGE, name = "Earth"},
    [7763] = {element = COMBAT_ENERGYDAMAGE, name = "Energy"}
}

local elementalSwords = {}

local function enchantSword(player, item, elementInfo)
    if not player or not item then
        return false
    end

    local itemId = item:getId()
    if itemId ~= SPIKE_SWORD_ID then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "This item cannot be enchanted.")
        return false
    end

    local itemUid = item:getUniqueId()
    elementalSwords[itemUid] = elementInfo
  
    item:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, "Spike Sword of " .. elementInfo.name)
    player:sendTextMessage(MESSAGE_STATUS_SMALL, "Your sword is now a Spike Sword of " .. elementInfo.name .. ".")
    return true
end

local elementalSwordAction = Action()

function elementalSwordAction.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if not player or not item then
        return false
    end

    local diamondId = item:getId()
    local elementInfo = DIAMOND_IDS[diamondId]
    if not elementInfo then
        return false
    end

    -- Check if the player is holding a Spike Sword
    local weapon = player:getSlotItem(CONST_SLOT_LEFT)
    if not weapon or weapon:getId() ~= SPIKE_SWORD_ID then
        weapon = player:getSlotItem(CONST_SLOT_RIGHT)
    end

    if not weapon or weapon:getId() ~= SPIKE_SWORD_ID then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need to be holding a Spike Sword to use this diamond.")
        return false
    end

    if enchantSword(player, weapon, elementInfo) then
        item:remove(1)  -- Remove one diamond after successful use
        return true
    end

    return false
end

for diamondId, _ in pairs(DIAMOND_IDS) do
    elementalSwordAction:id(diamondId)
end

elementalSwordAction:register()
 
Last edited:
I made it fully in RevScript, and the other one that you wanted like this... I'll send both.

LUA:
local config = {
    equipment = {
        2383, 2391, 2423, 2429, 2430, 2445, 2454, 7380, 7383, 7384, 7389, 7392,
        7402, 7406, 7415, 8905, 10022, 24716, 24718
    },
    valuables = {2146, 2147, 2149, 2150},
    enchantItems = {2342, 7759, 7760, 7761, 7762, 24739},
    shrines = {
        ice = {7508, 7509, 7510, 7511},
        fire = {7504, 7505, 7506, 7507},
        earth = {7516, 7517, 7518, 7519},
        energy = {7512, 7513, 7514, 7515}
    }
}

local items = {
    equipment = {
        [2147] = { -- small ruby
            [COMBAT_FIREDAMAGE] = {id = 2343, targetId = 2147} -- helmet of the ancients (enchanted)
        },
        [2383] = { -- spike sword
            [COMBAT_FIREDAMAGE] = {id = 7744}, [COMBAT_ICEDAMAGE] = {id = 7763},
            [COMBAT_EARTHDAMAGE] = {id = 7854}, [COMBAT_ENERGYDAMAGE] = {id = 7869}
        },
        [2391] = { -- war hammer
            [COMBAT_FIREDAMAGE] = {id = 7758}, [COMBAT_ICEDAMAGE] = {id = 7777},
            [COMBAT_EARTHDAMAGE] = {id = 7868}, [COMBAT_ENERGYDAMAGE] = {id = 7883}
        },
        [2423] = { -- clerical mace
            [COMBAT_FIREDAMAGE] = {id = 7754}, [COMBAT_ICEDAMAGE] = {id = 7773},
            [COMBAT_EARTHDAMAGE] = {id = 7864}, [COMBAT_ENERGYDAMAGE] = {id = 7879}
        },
        [2429] = { -- barbarian axe
            [COMBAT_FIREDAMAGE] = {id = 7749}, [COMBAT_ICEDAMAGE] = {id = 7768},
            [COMBAT_EARTHDAMAGE] = {id = 7859}, [COMBAT_ENERGYDAMAGE] = {id = 7874}
        },
        [2430] = { -- knight axe
            [COMBAT_FIREDAMAGE] = {id = 7750}, [COMBAT_ICEDAMAGE] = {id = 7769},
            [COMBAT_EARTHDAMAGE] = {id = 7860}, [COMBAT_ENERGYDAMAGE] = {id = 7875}
        },
        [2445] = { -- crystal mace
            [COMBAT_FIREDAMAGE] = {id = 7755}, [COMBAT_ICEDAMAGE] = {id = 7774},
            [COMBAT_EARTHDAMAGE] = {id = 7865}, [COMBAT_ENERGYDAMAGE] = {id = 7880}
        },
        [2454] = { -- war axe
            [COMBAT_FIREDAMAGE] = {id = 7753}, [COMBAT_ICEDAMAGE] = {id = 7772},
            [COMBAT_EARTHDAMAGE] = {id = 7863}, [COMBAT_ENERGYDAMAGE] = {id = 7878}
        },
        [7380] = { -- headchopper
            [COMBAT_FIREDAMAGE] = {id = 7752}, [COMBAT_ICEDAMAGE] = {id = 7771},
            [COMBAT_EARTHDAMAGE] = {id = 7862}, [COMBAT_ENERGYDAMAGE] = {id = 7877}
        },
        [7383] = { -- relic sword
            [COMBAT_FIREDAMAGE] = {id = 7745}, [COMBAT_ICEDAMAGE] = {id = 7764},
            [COMBAT_EARTHDAMAGE] = {id = 7855}, [COMBAT_ENERGYDAMAGE] = {id = 7870}
        },
        [7384] = { -- mystic blade
            [COMBAT_FIREDAMAGE] = {id = 7746}, [COMBAT_ICEDAMAGE] = {id = 7765},
            [COMBAT_EARTHDAMAGE] = {id = 7856}, [COMBAT_ENERGYDAMAGE] = {id = 7871}
        },
        [7389] = { -- heroic axe
            [COMBAT_FIREDAMAGE] = {id = 7751}, [COMBAT_ICEDAMAGE] = {id = 7770},
            [COMBAT_EARTHDAMAGE] = {id = 7861}, [COMBAT_ENERGYDAMAGE] = {id = 7876}
        },
        [7392] = { -- orcish maul
            [COMBAT_FIREDAMAGE] = {id = 7757}, [COMBAT_ICEDAMAGE] = {id = 7776},
            [COMBAT_EARTHDAMAGE] = {id = 7867}, [COMBAT_ENERGYDAMAGE] = {id = 7882}
        },
        [7402] = { -- dragon slayer
            [COMBAT_FIREDAMAGE] = {id = 7748}, [COMBAT_ICEDAMAGE] = {id = 7767},
            [COMBAT_EARTHDAMAGE] = {id = 7858}, [COMBAT_ENERGYDAMAGE] = {id = 7873}
        },
        [7406] = { -- blacksteel sword
            [COMBAT_FIREDAMAGE] = {id = 7747}, [COMBAT_ICEDAMAGE] = {id = 7766},
            [COMBAT_EARTHDAMAGE] = {id = 7857}, [COMBAT_ENERGYDAMAGE] = {id = 7872}
        },
        [7415] = { -- cranial basher
            [COMBAT_FIREDAMAGE] = {id = 7756}, [COMBAT_ICEDAMAGE] = {id = 7775},
            [COMBAT_EARTHDAMAGE] = {id = 7866}, [COMBAT_ENERGYDAMAGE] = {id = 7881}
        },
        [8905] = { -- rainbow shield
            [COMBAT_FIREDAMAGE] = {id = 8906}, [COMBAT_ICEDAMAGE] = {id = 8907},
            [COMBAT_EARTHDAMAGE] = {id = 8909}, [COMBAT_ENERGYDAMAGE] = {id = 8908}
        },
        [10022] = { -- worn firewalker boots
            [COMBAT_FIREDAMAGE] = {id = 9933, say = {text = "Take the boots off first."}},
            slot = {type = CONST_SLOT_FEET, check = true}
        },
        [24716] = { -- werewolf amulet
            [COMBAT_NONE] = {
                id = 24717,
                effects = {failure = CONST_ME_POFF, success = CONST_ME_THUNDER},
                message = {text = "The amulet cannot be enchanted while worn."}
            },
            slot = {type = CONST_SLOT_NECKLACE, check = true}
        },
        [24718] = { -- werewolf helmet
            [COMBAT_NONE] = {
                id = {
                    [SKILL_CLUB] = {id = 24783},
                    [SKILL_SWORD] = {id = 24783},
                    [SKILL_AXE] = {id = 24783},
                    [SKILL_DISTANCE] = {id = 24783},
                    [SKILL_MAGLEVEL] = {id = 24783}
                },
                effects = {failure = CONST_ME_POFF, success = CONST_ME_THUNDER},
                message = {text = "The helmet cannot be enchanted while worn."},
                usesStorage = true
            },
            slot = {type = CONST_SLOT_HEAD, check = true}
        },
        charges = 1000, effect = CONST_ME_MAGIC_RED
    },

    valuables = {
        [2146] = {id = 7759, shrine = config.shrines.ice}, -- small sapphire
        [2147] = {id = 7760, shrine = config.shrines.fire}, -- small ruby
        [2149] = {id = 7761, shrine = config.shrines.earth}, -- small emerald
        [2150] = {id = 7762, shrine = config.shrines.energy}, -- small amethyst
        soul = 2, mana = 300, effect = CONST_ME_HOLYDAMAGE
    },

    [2342] = {combatType = COMBAT_FIREDAMAGE, targetId = 2147}, -- helmet of the ancients
    [7759] = {combatType = COMBAT_ICEDAMAGE}, -- small enchanted sapphire
    [7760] = {combatType = COMBAT_FIREDAMAGE}, -- small enchanted ruby
    [7761] = {combatType = COMBAT_EARTHDAMAGE}, -- small enchanted emerald
    [7762] = {combatType = COMBAT_ENERGYDAMAGE}, -- small enchanted amethyst
    [24739] = {combatType = COMBAT_NONE} -- moonlight crystals
}

local enchanting = Action()

function enchanting.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if not target or not target:isItem() then
        return false
    end

    local itemId, targetId = item:getId(), target:getId()
    local targetType = items.valuables[itemId] or items.equipment[items[itemId].targetId or targetId]
    if not targetType then
        return false
    end

    if targetType.shrine then
        if not isInArray(targetType.shrine, targetId) then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, Game.getReturnMessage(RETURNVALUE_NOTPOSSIBLE))
            return true
        end

        if player:getMana() < items.valuables.mana then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, Game.getReturnMessage(RETURNVALUE_NOTENOUGHMANA))
            return true
        end

        if player:getSoul() < items.valuables.soul then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, Game.getReturnMessage(RETURNVALUE_NOTENOUGHSOUL))
            return true
        end
        player:addSoul(-items.valuables.soul)
        player:addMana(-items.valuables.mana)
        player:addManaSpent(items.valuables.mana * configManager.getNumber(configKeys.RATE_MAGIC))
        player:addItem(targetType.id)
        player:getPosition():sendMagicEffect(items.valuables.effect)
        item:remove(1)
    else
        local targetItem = targetType[items[itemId].combatType]
        if not targetItem or targetItem.targetId and targetItem.targetId ~= targetId then
            return false
        end

        local isInSlot = targetType.slot and targetType.slot.check and target:getType():usesSlot(targetType.slot.type) and Player(target:getParent())
        if isInSlot then
            if targetItem.say then
                player:say(targetItem.say.text, TALKTYPE_MONSTER_SAY)
                return true
            elseif targetItem.message then
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, targetItem.message.text)
            else
                return false
            end
        else
            if targetItem.targetId then
                item:transform(targetItem.id)
                item:decay()
                target:remove(1)
            else
                if targetItem.usesStorage then
                    local vocationId = player:getVocation():getDemotion():getId()
                    local storage = storages[itemId] and storages[itemId][targetId] and storages[itemId][targetId][vocationId]
                    if not storage then
                        return false
                    end

                    local storageValue = player:getStorageValue(storage.key)
                    if storageValue == -1 then
                        return false
                    end

                    local transform = targetItem.id and targetItem.id[storageValue]
                    if not transform then
                        return false
                    end
                    target:transform(transform.id)
                else
                    target:transform(targetItem.id)
                end

                if target:hasAttribute(ITEM_ATTRIBUTE_DURATION) then
                    target:decay()
                end

                if target:hasAttribute(ITEM_ATTRIBUTE_CHARGES) then
                    target:setAttribute(ITEM_ATTRIBUTE_CHARGES, items.equipment.charges)
                end
                item:remove(1)
            end
        end
        player:getPosition():sendMagicEffect(targetItem.effects and (isInSlot and targetItem.effects.failure or targetItem.effects.success) or items.equipment.effect)
    end
    return true
end

for _, id in ipairs(config.equipment) do
    enchanting:id(id)
end

for _, id in ipairs(config.valuables) do
    enchanting:id(id)
end

for _, id in ipairs(config.enchantItems) do
    enchanting:id(id)
end

enchanting:register()


Take this simple script and modify it however you like to fit your needs!
simple.
LUA:
local SPIKE_SWORD_ID = 2383

local DIAMOND_IDS = {
    [7759] = {element = COMBAT_FIREDAMAGE, name = "Fire"},
    [7760] = {element = COMBAT_ICEDAMAGE, name = "Ice"},
    [7761] = {element = COMBAT_HOLYDAMAGE, name = "Holy"},
    [7762] = {element = COMBAT_EARTHDAMAGE, name = "Earth"},
    [7763] = {element = COMBAT_ENERGYDAMAGE, name = "Energy"}
}

local elementalSwords = {}

local function enchantSword(player, item, elementInfo)
    if not player or not item then
        return false
    end

    local itemId = item:getId()
    if itemId ~= SPIKE_SWORD_ID then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "This item cannot be enchanted.")
        return false
    end

    local itemUid = item:getUniqueId()
    elementalSwords[itemUid] = elementInfo
 
    item:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, "Spike Sword of " .. elementInfo.name)
    player:sendTextMessage(MESSAGE_STATUS_SMALL, "Your sword is now a Spike Sword of " .. elementInfo.name .. ".")
    return true
end

local elementalSwordAction = Action()

function elementalSwordAction.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if not player or not item then
        return false
    end

    local diamondId = item:getId()
    local elementInfo = DIAMOND_IDS[diamondId]
    if not elementInfo then
        return false
    end

    -- Check if the player is holding a Spike Sword
    local weapon = player:getSlotItem(CONST_SLOT_LEFT)
    if not weapon or weapon:getId() ~= SPIKE_SWORD_ID then
        weapon = player:getSlotItem(CONST_SLOT_RIGHT)
    end

    if not weapon or weapon:getId() ~= SPIKE_SWORD_ID then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need to be holding a Spike Sword to use this diamond.")
        return false
    end

    if enchantSword(player, weapon, elementInfo) then
        item:remove(1)  -- Remove one diamond after successful use
        return true
    end

    return false
end

for diamondId, _ in pairs(DIAMOND_IDS) do
    elementalSwordAction:id(diamondId)
end

elementalSwordAction:register()
Thx man i will give it a try hopefully it works
 
I made it fully in RevScript, and the other one that you wanted like this... I'll send both.

LUA:
local config = {
    equipment = {
        2383, 2391, 2423, 2429, 2430, 2445, 2454, 7380, 7383, 7384, 7389, 7392,
        7402, 7406, 7415, 8905, 10022, 24716, 24718
    },
    valuables = {2146, 2147, 2149, 2150},
    enchantItems = {2342, 7759, 7760, 7761, 7762, 24739},
    shrines = {
        ice = {7508, 7509, 7510, 7511},
        fire = {7504, 7505, 7506, 7507},
        earth = {7516, 7517, 7518, 7519},
        energy = {7512, 7513, 7514, 7515}
    }
}

local items = {
    equipment = {
        [2147] = { -- small ruby
            [COMBAT_FIREDAMAGE] = {id = 2343, targetId = 2147} -- helmet of the ancients (enchanted)
        },
        [2383] = { -- spike sword
            [COMBAT_FIREDAMAGE] = {id = 7744}, [COMBAT_ICEDAMAGE] = {id = 7763},
            [COMBAT_EARTHDAMAGE] = {id = 7854}, [COMBAT_ENERGYDAMAGE] = {id = 7869}
        },
        [2391] = { -- war hammer
            [COMBAT_FIREDAMAGE] = {id = 7758}, [COMBAT_ICEDAMAGE] = {id = 7777},
            [COMBAT_EARTHDAMAGE] = {id = 7868}, [COMBAT_ENERGYDAMAGE] = {id = 7883}
        },
        [2423] = { -- clerical mace
            [COMBAT_FIREDAMAGE] = {id = 7754}, [COMBAT_ICEDAMAGE] = {id = 7773},
            [COMBAT_EARTHDAMAGE] = {id = 7864}, [COMBAT_ENERGYDAMAGE] = {id = 7879}
        },
        [2429] = { -- barbarian axe
            [COMBAT_FIREDAMAGE] = {id = 7749}, [COMBAT_ICEDAMAGE] = {id = 7768},
            [COMBAT_EARTHDAMAGE] = {id = 7859}, [COMBAT_ENERGYDAMAGE] = {id = 7874}
        },
        [2430] = { -- knight axe
            [COMBAT_FIREDAMAGE] = {id = 7750}, [COMBAT_ICEDAMAGE] = {id = 7769},
            [COMBAT_EARTHDAMAGE] = {id = 7860}, [COMBAT_ENERGYDAMAGE] = {id = 7875}
        },
        [2445] = { -- crystal mace
            [COMBAT_FIREDAMAGE] = {id = 7755}, [COMBAT_ICEDAMAGE] = {id = 7774},
            [COMBAT_EARTHDAMAGE] = {id = 7865}, [COMBAT_ENERGYDAMAGE] = {id = 7880}
        },
        [2454] = { -- war axe
            [COMBAT_FIREDAMAGE] = {id = 7753}, [COMBAT_ICEDAMAGE] = {id = 7772},
            [COMBAT_EARTHDAMAGE] = {id = 7863}, [COMBAT_ENERGYDAMAGE] = {id = 7878}
        },
        [7380] = { -- headchopper
            [COMBAT_FIREDAMAGE] = {id = 7752}, [COMBAT_ICEDAMAGE] = {id = 7771},
            [COMBAT_EARTHDAMAGE] = {id = 7862}, [COMBAT_ENERGYDAMAGE] = {id = 7877}
        },
        [7383] = { -- relic sword
            [COMBAT_FIREDAMAGE] = {id = 7745}, [COMBAT_ICEDAMAGE] = {id = 7764},
            [COMBAT_EARTHDAMAGE] = {id = 7855}, [COMBAT_ENERGYDAMAGE] = {id = 7870}
        },
        [7384] = { -- mystic blade
            [COMBAT_FIREDAMAGE] = {id = 7746}, [COMBAT_ICEDAMAGE] = {id = 7765},
            [COMBAT_EARTHDAMAGE] = {id = 7856}, [COMBAT_ENERGYDAMAGE] = {id = 7871}
        },
        [7389] = { -- heroic axe
            [COMBAT_FIREDAMAGE] = {id = 7751}, [COMBAT_ICEDAMAGE] = {id = 7770},
            [COMBAT_EARTHDAMAGE] = {id = 7861}, [COMBAT_ENERGYDAMAGE] = {id = 7876}
        },
        [7392] = { -- orcish maul
            [COMBAT_FIREDAMAGE] = {id = 7757}, [COMBAT_ICEDAMAGE] = {id = 7776},
            [COMBAT_EARTHDAMAGE] = {id = 7867}, [COMBAT_ENERGYDAMAGE] = {id = 7882}
        },
        [7402] = { -- dragon slayer
            [COMBAT_FIREDAMAGE] = {id = 7748}, [COMBAT_ICEDAMAGE] = {id = 7767},
            [COMBAT_EARTHDAMAGE] = {id = 7858}, [COMBAT_ENERGYDAMAGE] = {id = 7873}
        },
        [7406] = { -- blacksteel sword
            [COMBAT_FIREDAMAGE] = {id = 7747}, [COMBAT_ICEDAMAGE] = {id = 7766},
            [COMBAT_EARTHDAMAGE] = {id = 7857}, [COMBAT_ENERGYDAMAGE] = {id = 7872}
        },
        [7415] = { -- cranial basher
            [COMBAT_FIREDAMAGE] = {id = 7756}, [COMBAT_ICEDAMAGE] = {id = 7775},
            [COMBAT_EARTHDAMAGE] = {id = 7866}, [COMBAT_ENERGYDAMAGE] = {id = 7881}
        },
        [8905] = { -- rainbow shield
            [COMBAT_FIREDAMAGE] = {id = 8906}, [COMBAT_ICEDAMAGE] = {id = 8907},
            [COMBAT_EARTHDAMAGE] = {id = 8909}, [COMBAT_ENERGYDAMAGE] = {id = 8908}
        },
        [10022] = { -- worn firewalker boots
            [COMBAT_FIREDAMAGE] = {id = 9933, say = {text = "Take the boots off first."}},
            slot = {type = CONST_SLOT_FEET, check = true}
        },
        [24716] = { -- werewolf amulet
            [COMBAT_NONE] = {
                id = 24717,
                effects = {failure = CONST_ME_POFF, success = CONST_ME_THUNDER},
                message = {text = "The amulet cannot be enchanted while worn."}
            },
            slot = {type = CONST_SLOT_NECKLACE, check = true}
        },
        [24718] = { -- werewolf helmet
            [COMBAT_NONE] = {
                id = {
                    [SKILL_CLUB] = {id = 24783},
                    [SKILL_SWORD] = {id = 24783},
                    [SKILL_AXE] = {id = 24783},
                    [SKILL_DISTANCE] = {id = 24783},
                    [SKILL_MAGLEVEL] = {id = 24783}
                },
                effects = {failure = CONST_ME_POFF, success = CONST_ME_THUNDER},
                message = {text = "The helmet cannot be enchanted while worn."},
                usesStorage = true
            },
            slot = {type = CONST_SLOT_HEAD, check = true}
        },
        charges = 1000, effect = CONST_ME_MAGIC_RED
    },

    valuables = {
        [2146] = {id = 7759, shrine = config.shrines.ice}, -- small sapphire
        [2147] = {id = 7760, shrine = config.shrines.fire}, -- small ruby
        [2149] = {id = 7761, shrine = config.shrines.earth}, -- small emerald
        [2150] = {id = 7762, shrine = config.shrines.energy}, -- small amethyst
        soul = 2, mana = 300, effect = CONST_ME_HOLYDAMAGE
    },

    [2342] = {combatType = COMBAT_FIREDAMAGE, targetId = 2147}, -- helmet of the ancients
    [7759] = {combatType = COMBAT_ICEDAMAGE}, -- small enchanted sapphire
    [7760] = {combatType = COMBAT_FIREDAMAGE}, -- small enchanted ruby
    [7761] = {combatType = COMBAT_EARTHDAMAGE}, -- small enchanted emerald
    [7762] = {combatType = COMBAT_ENERGYDAMAGE}, -- small enchanted amethyst
    [24739] = {combatType = COMBAT_NONE} -- moonlight crystals
}

local enchanting = Action()

function enchanting.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if not target or not target:isItem() then
        return false
    end

    local itemId, targetId = item:getId(), target:getId()
    local targetType = items.valuables[itemId] or items.equipment[items[itemId].targetId or targetId]
    if not targetType then
        return false
    end

    if targetType.shrine then
        if not isInArray(targetType.shrine, targetId) then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, Game.getReturnMessage(RETURNVALUE_NOTPOSSIBLE))
            return true
        end

        if player:getMana() < items.valuables.mana then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, Game.getReturnMessage(RETURNVALUE_NOTENOUGHMANA))
            return true
        end

        if player:getSoul() < items.valuables.soul then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, Game.getReturnMessage(RETURNVALUE_NOTENOUGHSOUL))
            return true
        end
        player:addSoul(-items.valuables.soul)
        player:addMana(-items.valuables.mana)
        player:addManaSpent(items.valuables.mana * configManager.getNumber(configKeys.RATE_MAGIC))
        player:addItem(targetType.id)
        player:getPosition():sendMagicEffect(items.valuables.effect)
        item:remove(1)
    else
        local targetItem = targetType[items[itemId].combatType]
        if not targetItem or targetItem.targetId and targetItem.targetId ~= targetId then
            return false
        end

        local isInSlot = targetType.slot and targetType.slot.check and target:getType():usesSlot(targetType.slot.type) and Player(target:getParent())
        if isInSlot then
            if targetItem.say then
                player:say(targetItem.say.text, TALKTYPE_MONSTER_SAY)
                return true
            elseif targetItem.message then
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, targetItem.message.text)
            else
                return false
            end
        else
            if targetItem.targetId then
                item:transform(targetItem.id)
                item:decay()
                target:remove(1)
            else
                if targetItem.usesStorage then
                    local vocationId = player:getVocation():getDemotion():getId()
                    local storage = storages[itemId] and storages[itemId][targetId] and storages[itemId][targetId][vocationId]
                    if not storage then
                        return false
                    end

                    local storageValue = player:getStorageValue(storage.key)
                    if storageValue == -1 then
                        return false
                    end

                    local transform = targetItem.id and targetItem.id[storageValue]
                    if not transform then
                        return false
                    end
                    target:transform(transform.id)
                else
                    target:transform(targetItem.id)
                end

                if target:hasAttribute(ITEM_ATTRIBUTE_DURATION) then
                    target:decay()
                end

                if target:hasAttribute(ITEM_ATTRIBUTE_CHARGES) then
                    target:setAttribute(ITEM_ATTRIBUTE_CHARGES, items.equipment.charges)
                end
                item:remove(1)
            end
        end
        player:getPosition():sendMagicEffect(targetItem.effects and (isInSlot and targetItem.effects.failure or targetItem.effects.success) or items.equipment.effect)
    end
    return true
end

for _, id in ipairs(config.equipment) do
    enchanting:id(id)
end

for _, id in ipairs(config.valuables) do
    enchanting:id(id)
end

for _, id in ipairs(config.enchantItems) do
    enchanting:id(id)
end

enchanting:register()


Take this simple script and modify it however you like to fit your needs!
simple.
LUA:
local SPIKE_SWORD_ID = 2383

local DIAMOND_IDS = {
    [7759] = {element = COMBAT_FIREDAMAGE, name = "Fire"},
    [7760] = {element = COMBAT_ICEDAMAGE, name = "Ice"},
    [7761] = {element = COMBAT_HOLYDAMAGE, name = "Holy"},
    [7762] = {element = COMBAT_EARTHDAMAGE, name = "Earth"},
    [7763] = {element = COMBAT_ENERGYDAMAGE, name = "Energy"}
}

local elementalSwords = {}

local function enchantSword(player, item, elementInfo)
    if not player or not item then
        return false
    end

    local itemId = item:getId()
    if itemId ~= SPIKE_SWORD_ID then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "This item cannot be enchanted.")
        return false
    end

    local itemUid = item:getUniqueId()
    elementalSwords[itemUid] = elementInfo
 
    item:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, "Spike Sword of " .. elementInfo.name)
    player:sendTextMessage(MESSAGE_STATUS_SMALL, "Your sword is now a Spike Sword of " .. elementInfo.name .. ".")
    return true
end

local elementalSwordAction = Action()

function elementalSwordAction.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if not player or not item then
        return false
    end

    local diamondId = item:getId()
    local elementInfo = DIAMOND_IDS[diamondId]
    if not elementInfo then
        return false
    end

    -- Check if the player is holding a Spike Sword
    local weapon = player:getSlotItem(CONST_SLOT_LEFT)
    if not weapon or weapon:getId() ~= SPIKE_SWORD_ID then
        weapon = player:getSlotItem(CONST_SLOT_RIGHT)
    end

    if not weapon or weapon:getId() ~= SPIKE_SWORD_ID then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need to be holding a Spike Sword to use this diamond.")
        return false
    end

    if enchantSword(player, weapon, elementInfo) then
        item:remove(1)  -- Remove one diamond after successful use
        return true
    end

    return false
end

for diamondId, _ in pairs(DIAMOND_IDS) do
    elementalSwordAction:id(diamondId)
end

elementalSwordAction:register()
Hey,

Ive tested the script, it kinda works but it doesnt apply physical + 5 fire or ice or something to the weapon.

Adding physical + 5 fire is the main idea of this script, so if ur kind and could help me add this thing and possible to make it editable i would
appreciate it very much.
 
Back
Top