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

Enchanting.lua Script tfs 1.3

Dorianek

Member
Joined
Nov 29, 2018
Messages
247
Reaction score
10
Location
Poland
After choosing small emerald on the shrine, nothing happens, no portal

did not work.

Enchanting.lua

C++:
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}
}s

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:say('Not enough mana, separate one gem in your backpack and try again.', TALKTYPE_MONSTER_SAY)
            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
    return false
end

Shrinesportal

C++:
local portals = {
    --Carlin
    [9069] = {position = Position(32192, 31419, 2), storage = 10017}, --ice
    [9070] = {position = Position(32972, 32227, 7), storage = 10017}, --earth
    [9071] = {position = Position(32911, 32336, 15), storage = 10017}, --fire
    [9072] = {position = Position(33059, 32716, 5), storage = 10017}, --electric

    --Thais
    [9073] = {position = Position(32192, 31419, 2), storage = 10018}, --ice
    [9074] = {position = Position(32972, 32227, 7), storage = 10018}, --earth
    [9075] = {position = Position(32911, 32336, 15), storage = 10018}, --fire
    [9076] = {position = Position(33059, 32716, 5), storage = 10018}, --electric

    --Venore
    [9077] = {position = Position(32192, 31419, 2), storage = 10019}, --ice
    [9078] = {position = Position(32972, 32227, 7), storage = 10019}, --earth
    [9079] = {position = Position(32911, 32336, 15), storage = 10019}, --fire
    [9080] = {position = Position(33059, 32716, 5), storage = 10019}, --electric

    --Ab'Dendriel
    [9081] = {position = Position(32192, 31419, 2), storage = 10020}, --ice
    [9082] = {position = Position(32972, 32227, 7), storage = 10020}, --earth
    [9083] = {position = Position(32911, 32336, 15), storage = 10020}, --fire
    [9084] = {position = Position(33059, 32716, 5), storage = 10020}, --electric

    --Kazodron
    [9085] = {position = Position(32192, 31419, 2), storage = 10021 }, --ice
    [9086] = {position = Position(32972, 32227, 7), storage = 10021}, --earth
    [9087] = {position = Position(32911, 32336, 15), storage = 10021}, --fire
    [9088] = {position = Position(33059, 32716, 5), storage = 10021}, --electric

    --Darashia
    [9089] = {position = Position(32192, 31419, 2), storage = 10022}, --ice
    [9090] = {position = Position(32972, 32227, 7), storage = 10022}, --earth
    [9091] = {position = Position(32911, 32336, 15), storage = 10022}, --fire
    [9092] = {position = Position(33059, 32716, 5), storage = 10022}, --electric

    --Ankrahmun
    [9093] = {position = Position(32192, 31419, 2), storage = 10023}, --ice
    [9094] = {position = Position(32972, 32227, 7), storage = 10023}, --earth
    [9095] = {position = Position(32911, 32336, 15), storage = 10023}, --fire
    [9096] = {position = Position(33059, 32716, 5), storage = 10023}, --electric

    --Edron
    [9097] = {position = Position(32192, 31419, 2), storage = 10024}, --ice
    [9098] = {position = Position(32972, 32227, 7), storage = 10024}, --earth
    [9099] = {position = Position(32911, 32336, 15), storage = 10024}, --fire
    [9100] = {position = Position(33059, 32716, 5), storage = 10024}, --electric

    --Liberty Bay
    [9101] = {position = Position(32192, 31419, 2), storage = 10025}, --ice
    [9102] = {position = Position(32972, 32227, 7), storage = 10025}, --earth
    [9103] = {position = Position(32911, 32336, 15), storage = 10025}, --fire
    [9104] = {position = Position(33059, 32716, 5), storage = 10025}, --electric

    --Port Hope
    [9105] = {position = Position(32192, 31419, 2), storage = 10026}, --ice
    [9106] = {position = Position(32972, 32227, 7), storage = 10026}, --earth
    [9107] = {position = Position(32911, 32336, 15), storage = 10026}, --fire
    [9108] = {position = Position(33059, 32716, 5), storage = 10026}, --electric

    --Svargrond
    [9109] = {position = Position(32192, 31419, 2), storage = 10027}, --ice
    [9110] = {position = Position(32972, 32227, 7), storage = 10027}, --earth
    [9111] = {position = Position(32911, 32336, 15), storage = 10027}, --fire
    [9112] = {position = Position(33059, 32716, 5), storage = 10027}, --electric

    --Yalahari
    [9113] = {position = Position(32192, 31419, 2), storage = 10028}, --ice
    [9114] = {position = Position(32972, 32227, 7), storage = 10028}, --earth
    [9115] = {position = Position(32911, 32336, 15), storage = 10028}, --fire
    [9116] = {position = Position(33059, 32716, 5), storage = 10028}, --electric
   
    --Oramond
    [9117] = {position = Position(32192, 31419, 2), storage = 10029}, --ice
    [9118] = {position = Position(32972, 32227, 7), storage = 10029}, --earth
    [9119] = {position = Position(32911, 32336, 15), storage = 10029}, --fire
    [9120] = {position = Position(33059, 32716, 5), storage = 10029} --electric
}

function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return true
    end

    local portal = portals[item.uid]
    if not portal or player:getLevel() < 30 then
        player:teleportTo(fromPosition, true)
        player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
        player:say('Only players of level 30 or higher may enter this portal.', TALKTYPE_MONSTER_SAY)
        return true
    end

    player:teleportTo(portal.position)
    player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
    player:setStorageValue(portal.storage, 1)
    return true
end


Shrinesportal_out

C++:
local config = {
    {storageKey = 10017, teleportPosition = Position(32360, 31781, 9)},
    {storageKey = 10018, teleportPosition = Position(32369, 32242, 6)},
    {storageKey = 10019, teleportPosition = Position(32958, 32077, 5)},
    {storageKey = 10020, teleportPosition = Position(32681, 31686, 2)},
    {storageKey = 10021, teleportPosition = Position(32646, 31925, 11)},
    {storageKey = 10022, teleportPosition = Position(33230, 32392, 5)},
    {storageKey = 10023, teleportPosition = Position(33130, 32815, 4)},
    {storageKey = 10024, teleportPosition = Position(33266, 31835, 9)},
    {storageKey = 10025, teleportPosition = Position(32337, 32837, 8)},
    {storageKey = 10026, teleportPosition = Position(32628, 32743, 4)},
    {storageKey = 10027, teleportPosition = Position(32213, 31132, 8)},
    {storageKey = 10028, teleportPosition = Position(32786, 31245, 5)},
    {storageKey = 10029, teleportPosition = Position(33594, 31899, 4)}
}

function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return
    end

    for i = 1, #config do
        local table = config[i]
        if player:getStorageValue(table.storageKey) >= 1 then
            player:teleportTo(table.teleportPosition)
            table.teleportPosition:sendMagicEffect(CONST_ME_TELEPORT)
            player:setStorageValue(table.storageKey, 0)
            return true
        end
    end

    player:teleportTo(player:getTown():getTemplePosition())
    player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
    return true
end
 
Last edited:
Back
Top