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

Lua Enchanting Gems

Blasphemy

Well-Known Member
Joined
Jan 5, 2012
Messages
387
Reaction score
67
I have a problem with Enchanting Gems system, It isn't working :S
Anyone has a working script? for tfs 1.2?



My current script is (for actions.xml):

Code:
local config = {
    manaCost = 300,
    soulCost = 2,
}

local spheres = {
    [7759] = {3, 7},
    [7760] = {1, 5},
    [7761] = {2, 6},
    [7762] = {4, 8}
}

local enchantableGems = {2147, 2146, 2149, 2150}
local enchantableItems = {2383, 7383, 7384, 7406, 7402, 2429, 2430, 7389, 7380, 2454, 2423, 2445, 7415, 7392, 2391, 2544, 8905}

local enchantingAltars = {
    {7504, 7505, 7506, 7507},
    {7508, 7509, 7510, 7511},
    {7516, 7517, 7518, 7519},
    {7512, 7513, 7514, 7515}
}

local enchantedGems = {7760, 7759, 7761, 7762}
local enchantedItems = {
    [2383] = {7744, 7763, 7854, 7869},
    [7383] = {7745, 7764, 7855, 7870},
    [7384] = {7746, 7765, 7856, 7871},
    [7406] = {7747, 7766, 7857, 7872},
    [7402] = {7748, 7767, 7858, 7873},
    [2429] = {7749, 7768, 7859, 7874},
    [2430] = {7750, 7769, 7860, 7875},
    [7389] = {7751, 7770, 7861, 7876},
    [7380] = {7752, 7771, 7862, 7877},
    [2454] = {7753, 7772, 7863, 7878},
    [2423] = {7754, 7773, 7864, 7879},
    [2445] = {7755, 7774, 7865, 7880},
    [7415] = {7756, 7775, 7866, 7881},
    [7392] = {7757, 7776, 7867, 7882},
    [2391] = {7758, 7777, 7868, 7883},
    [2544] = {7840, 7839, 7850, 7838},
    [8905] = {8906, 8907, 8909, 8908}
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if isInArray({33268, 33269}, toPosition.x) and toPosition.y == 31830 and toPosition.z == 10 and player:getStorageValue(Storage.ElementalSphere.QuestLine) > 0 then
        if not isInArray(spheres[item.itemid], player:getVocation():getId()) then
            return false
        elseif isInArray({7915, 7916}, target.itemid) then
            player:say('Turn off the machine first.', TALKTYPE_MONSTER_SAY)
            return true
        else
            player:setStorageValue(Storage.ElementalSphere.MachineGemCount, math.max(1, player:getStorageValue(Storage.ElementalSphere.MachineGemCount) + 1))
            toPosition:sendMagicEffect(CONST_ME_PURPLEENERGY)
            item:transform(item.itemid, item.type - 1)
            return true
        end
    end

    if item.itemid == 2147 and target.itemid == 2342 then
        target:transform(2343)
        target:decay()
        item:remove(1)
        toPosition:sendMagicEffect(CONST_ME_MAGIC_RED)
        return true
    end

    if item.itemid == 7760 and isInArray({9934, 10022}, target.itemid) then
        target:transform(9933)
        item:remove(1)
        toPosition:sendMagicEffect(CONST_ME_MAGIC_RED)
        return true
    end

    if isInArray(enchantableGems, item.itemid) then
        local subtype = item.type
        if subtype == 0 then
            subtype = 1
        end

        local mana = config.manaCost * subtype
        if player:getMana() < mana then
            player:sendCancelMessage(RETURNVALUE_NOTENOUGHMANA)
            return false
        end

        local soul = config.soulCost * subtype
        if player:getSoul() < soul then
            player:sendCancelMessage(RETURNVALUE_NOTENOUGHSOUL)
            return false
        end

        local targetId = table.find(enchantableGems, item.itemid)
        if not targetId or not isInArray(enchantingAltars[targetId], target.itemid) then
            return false
        end

        player:addMana(-mana)
        player:addSoul(-soul)
        item:transform(enchantedGems[targetId])
        player:addManaSpent(mana * configManager.getNumber(configKeys.RATE_MAGIC))
        player:getPosition():sendMagicEffect(CONST_ME_HOLYDAMAGE)
        return true
    end

    if item.itemid == 7761 and isInArray({9949, 9954}, target.itemid) then
        target:transform(target.itemid - 1)
        target:decay()
        item:remove(1)
        toPosition:sendMagicEffect(CONST_ME_MAGIC_GREEN)
        return true
    end

    if isInArray(enchantedGems, item.itemid) then
        if not isInArray(enchantableItems, target.itemid) then
            fromPosition:sendMagicEffect(CONST_ME_POFF)
            return false
        end

        local targetId = table.find(enchantedGems, item.itemid)
        if not targetId then
            return false
        end

        local subtype = target.type
        if not isInArray({2544, 8905}, target.itemid) then
            subtype = 1000
        end

        target:transform(enchantedItems[target.itemid][targetId], subtype)
        target:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
        item:remove(1)
        return true
    end
   
        -- enchanting rainbow shield --
    if item.itemid == 7759 and isInArray({8905, 8906, 8908, 8909}, target.itemid) then
        target:transform(8907)
        item:remove(1)
        toPosition:sendMagicEffect(CONST_ME_MAGIC_RED)
        return true
    end

    if item.itemid == 7760 and isInArray({8905, 8907, 8908, 8909}, target.itemid) then
        target:transform(8906)
        item:remove(1)
        toPosition:sendMagicEffect(CONST_ME_MAGIC_RED)
        return true
    end
   
    if item.itemid == 7761 and isInArray({8905, 8907, 8908, 8906}, target.itemid) then
        target:transform(8909)
        item:remove(1)
        toPosition:sendMagicEffect(CONST_ME_MAGIC_RED)
        return true
    end
    if item.itemid == 7762 and isInArray({8905, 8907, 8909, 8906}, target.itemid) then
        target:transform(8908)
        item:remove(1)
        toPosition:sendMagicEffect(CONST_ME_MAGIC_RED)
        return true
    end
   
    -- end enchanting rainbow shield --
   
   
    return false
end

Thank you for helping :)!
 
Well, when I use a gem in any fountain, gems doesn't enchant, else I can't enchant any enchantable weapon :/... The worst part is there's no error msg at console :S!
 
Try this one
Code:
local config = {
    [9118] = Position(32991, 31539, 4),
    [9119] = Position(32991, 31539, 1),
    [9120] = Position(33061, 31527, 14),
    [9121] = Position(32993, 31547, 4)
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local targetPosition = config[item.actionid]
    if not targetPosition then
        return true
    end

    Item(item.uid):transform(item.itemid == 1945 and 1946 or 1945)

    toPosition.x = toPosition.x - 1
    local creature = Tile(toPosition):getTopCreature()
    if not creature or not creature:isPlayer() then
        return true
    end

    if item.itemid ~= 1945 then
        return true
    end

    if item.actionid == 9120 then
        if creature:getStorageValue(Storage.TheNewFrontier.Mission05) == 7 then
            targetPosition.z = 10
        elseif creature:getStorageValue(Storage.TheNewFrontier.Mission03) == 3 then
            targetPosition.z = 12
        end
    end

    creature:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
    creature:teleportTo(targetPosition)
    targetPosition:sendMagicEffect(CONST_ME_TELEPORT)
    return true
end
 
Try this one
Code:
local config = {
    [9118] = Position(32991, 31539, 4),
    [9119] = Position(32991, 31539, 1),
    [9120] = Position(33061, 31527, 14),
    [9121] = Position(32993, 31547, 4)
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local targetPosition = config[item.actionid]
    if not targetPosition then
        return true
    end

    Item(item.uid):transform(item.itemid == 1945 and 1946 or 1945)

    toPosition.x = toPosition.x - 1
    local creature = Tile(toPosition):getTopCreature()
    if not creature or not creature:isPlayer() then
        return true
    end

    if item.itemid ~= 1945 then
        return true
    end

    if item.actionid == 9120 then
        if creature:getStorageValue(Storage.TheNewFrontier.Mission05) == 7 then
            targetPosition.z = 10
        elseif creature:getStorageValue(Storage.TheNewFrontier.Mission03) == 3 then
            targetPosition.z = 12
        end
    end

    creature:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
    creature:teleportTo(targetPosition)
    targetPosition:sendMagicEffect(CONST_ME_TELEPORT)
    return true
end
How does it work?
Is it a script for Enchant gems on their respective fountains?

srry for my noobness :(
 
I'm trying to enchant spike sword, dragonslayer, heroic axe, only enchantable weapons, If is that what you meaning???
When it comes to messing with items I hate using id's, so with that said
Try this out.
Code:
-- incase you don't have it in your compat file
function getItemIdByName(name)
    local id = ItemType(name):getId()
    if id == 0 then
        return false
    end
    return id
end
-- I made this
function getItemNameByItemId(itemid)
    local itemType = ItemType(itemId)
    if itemType:getName() == nil then
        return false
    end
    return itemType:getName():lower()
end
-- these are the gems used to enchanted the types do not edit
local gems = {
    ['small enchanted ruby'] = "firey",
    ['small enchanted emerald'] = "earth",
    ['small enchanted amethyst'] = "icy",
    ['small enchanted sapphire'] = "energy"
}
-- place all the names that are enchantable in the items table i only listed 2
-- since we are creating items by name instead of id make sure you spell them correctly :p
-- the removeAmount is how many gems it cost to enchant the item
local items = {
    ['spiked sword'] = { removeAmount = 1 },
    ['relic sword'] = { removeAmount = 1 },
    --  etc..
}

function generateName(gem, item)
    return (gem .. ' ' .. item):lower()
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local weapon = getItemNameByItemId(target.itemid)
    local gems = getItemNameByItemId(item.itemid)
    local count = player:getItemCount(item.itemid)
    if not items[weapon] then
        player:sendCancelMessage("This item can not be enchanted.")
        fromPosition:sendMagicEffect(CONST_ME_POFF)
        return false
    end

    if items[weapon].removeAmount < count then
        player:sendTextMessage(MESSAGE_INFO_DESCR, 'You do not have enough ' .. gems .. ', you need ' .. items[weapon].removeAmount .. ' gems in order to enchant this ' .. weapon .. '.')
        fromPosition:sendMagicEffect(CONST_ME_POFF)
        return false
    end
    target:transform(getItemIdByName(generateName(gems, weapon)))
    item:remove(items[weapon].removeAmount)
    toPosition:sendMagicEffect(CONST_ME_MAGIC_RED)
    return true
end
 
This script has some issues. Any vocation can enchant gems with this script. It WILL enchant a stack of gems instead of 1 by 1. Also, it will not auto stack gems after enchanted. IT WILL NOT ENCHANT A WEAPON. IT WILL ONLY ENCHANT THE GEMS.

I cant remember where I found this script, but I dont know enough about scripting yet to fix it the right way.

Code:
function onUse(cid, item, frompos, item2, topos)

local gems = {2146, 2147, 2149, 2150}
local egems = {7759, 7760, 7761, 7762}
local altars = {{7508, 7509, 7510, 7511}, {7504, 7505, 7506, 7507}, {7516, 7517, 7518, 7519}, {7512, 7513, 7514, 7515}}
local weapons = {2383, 7384, 7389, 7406, 7402, 2429, 2430, 2435, 7380, 2454, 2423, 2445, 7415, 7392, 2391, 2544, 8905}
local eweapons = {{7763, 7744, 7854, 7869}, {7765, 7746, 7856, 7871}, {7770, 7751, 7861, 7876}, {7766, 7747, 7857, 7872}, {7767, 7748, 7858, 7873}, {7768, 7749, 7859, 7874}, {7769, 7750, 7860, 7875}, {7770, 7751, 7861, 7876}, {7771, 7752, 7862, 7877}, {7772, 7753, 7863, 7878}, {7773, 7754, 7864, 7879}, {7774, 7755, 7865, 7880}, {7775, 7756, 7866, 7881}, {7776, 7757, 7867, 7882}, {7777, 7758, 7868, 7883}, {7839, 7840, 7838, 7850}, {8907, 8906, 8909, 8908}}


local type = item.type
if type == 0 then
type = 1
end

local mana = 300 * type
local soul = 2 * type

if isInArray(gems, item.itemid)== TRUE then
for aa=1, #gems do
if item.itemid == gems[aa] then
a=aa
end
end
if isInArray(altars[a], item2.itemid)== TRUE then
if getPlayerMana(cid) >= mana and getPlayerSoul(cid) >= soul then
doTransformItem(item.uid,egems[a])
doPlayerAddMana(cid,-mana)
doPlayerAddSoul(cid,-soul)
doSendMagicEffect(frompos,39)
else
doPlayerSendCancel(cid,"You dont have mana or soul points.")
end
else
return 2
end

elseif isInArray(egems, item.itemid)== TRUE then
for bb=1, #egems do
if item.itemid == egems[bb] then
b=bb
end
end
if isInArray(weapons, item2.itemid)== TRUE then
for cc=1, #weapons do
if item2.itemid == weapons[cc] then
c=cc
end
end
doTransformItem(item2.uid,eweapons[c][b],1000)
doSendMagicEffect(frompos,39)
doRemoveItem(item.uid,1)
else
doPlayerSendCancel(cid,"You can't enchanted this.")
end
else
return 0
end
return 1
end
 
Last edited:
This script has some issues. Any vocation can enchant gems with this script. It WILL enchant a stack of gems instead of 1 by 1. Also, it will not auto stack gems after enchanted. IT WILL NOT ENCHANT A WEAPON. IT WILL ONLY ENCHANT THE GEMS.

I cant remember where I found this script, but I dont know enough about scripting yet to fix it the right way.

Code:
function onUse(cid, item, frompos, item2, topos)

local gems = {2146, 2147, 2149, 2150}
local egems = {7759, 7760, 7761, 7762}
local altars = {{7508, 7509, 7510, 7511}, {7504, 7505, 7506, 7507}, {7516, 7517, 7518, 7519}, {7512, 7513, 7514, 7515}}
local weapons = {2383, 7384, 7389, 7406, 7402, 2429, 2430, 2435, 7380, 2454, 2423, 2445, 7415, 7392, 2391, 2544, 8905}
local eweapons = {{7763, 7744, 7854, 7869}, {7765, 7746, 7856, 7871}, {7770, 7751, 7861, 7876}, {7766, 7747, 7857, 7872}, {7767, 7748, 7858, 7873}, {7768, 7749, 7859, 7874}, {7769, 7750, 7860, 7875}, {7770, 7751, 7861, 7876}, {7771, 7752, 7862, 7877}, {7772, 7753, 7863, 7878}, {7773, 7754, 7864, 7879}, {7774, 7755, 7865, 7880}, {7775, 7756, 7866, 7881}, {7776, 7757, 7867, 7882}, {7777, 7758, 7868, 7883}, {7839, 7840, 7838, 7850}, {8907, 8906, 8909, 8908}}


local type = item.type
if type == 0 then
type = 1
end

local mana = 300 * type
local soul = 2 * type

if isInArray(gems, item.itemid)== TRUE then
for aa=1, #gems do
if item.itemid == gems[aa] then
a=aa
end
end
if isInArray(altars[a], item2.itemid)== TRUE then
if getPlayerMana(cid) >= mana and getPlayerSoul(cid) >= soul then
doTransformItem(item.uid,egems[a])
doPlayerAddMana(cid,-mana)
doPlayerAddSoul(cid,-soul)
doSendMagicEffect(frompos,39)
else
doPlayerSendCancel(cid,"You dont have mana or soul points.")
end
else
return 2
end

elseif isInArray(egems, item.itemid)== TRUE then
for bb=1, #egems do
if item.itemid == egems[bb] then
b=bb
end
end
if isInArray(weapons, item2.itemid)== TRUE then
for cc=1, #weapons do
if item2.itemid == weapons[cc] then
c=cc
end
end
doTransformItem(item2.uid,eweapons[c][b],1000)
doSendMagicEffect(frompos,39)
doRemoveItem(item.uid,1)
else
doPlayerSendCancel(cid,"You can't enchanted this.")
end
else
return 0
end
return 1
end
I already tried this script, I think I saw it in another topic, but didn't work tho... :/ It's for tfs 1.1 right? I'm using 1.2
 
In the week of a time frame that you have been focusing on getting a script like this to work for your server you could have at the very least learned the minimum in lua and got it working yourself.
 
In the week of a time frame that you have been focusing on getting a script like this to work for your server you could have at the very least learned the minimum in lua and got it working yourself.
Perhaps he is doing something else on his server.
 
In the week of a time frame that you have been focusing on getting a script like this to work for your server you could have at the very least learned the minimum in lua and got it working yourself.
I've been trying a lot of ways to solve this, I have tryed the same script in another server engine, and it's working... but not in my current server engine.
anyways, thanks for your help...
 
I've been trying a lot of ways to solve this, I have tryed the same script in another server engine, and it's working... but not in my current server engine.
anyways, thanks for your help...
Lots of ways but the right way. One day you will take my advice and then ask yourself why you didn't do it sooner.
 
Back
Top