• 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 Change on enchanting script

ralke

(҂ ͠❛ ෴ ͡❛)ᕤ
Joined
Dec 17, 2011
Messages
1,713
Solutions
31
Reaction score
965
Location
Santiago - Chile
GitHub
ralke23
Twitch
ralke23
Hi again! I use TFS 1.5 downgrades 8.6 (based on nekiro) and I need help modifying my enchanting script.
Request (modify the following script)
LUA:
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}
        },
        [9949] = { -- dracoyle statue
            [COMBAT_EARTHDAMAGE] = {id = 9948} -- dracoyle statue (enchanted)
        },
        [9954] = { -- dracoyle statue
            [COMBAT_EARTHDAMAGE] = {id = 9953} -- dracoyle statue (enchanted)
        },
        [10022] = { -- worn firewalker boots
            [COMBAT_FIREDAMAGE] = {id = 9933, say = {text = "Quitate las botas antes de encantarlas."}},
            slot = {type = CONST_SLOT_FEET, 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 = {7508, 7509, 7510, 7511}}, -- small sapphire
        [2147] = {id = 7760, shrine = {7504, 7505, 7506, 7507}}, -- small ruby
        [2149] = {id = 7761, shrine = {7516, 7517, 7518, 7519}}, -- small emerald
        [2150] = {id = 7762, shrine = {7512, 7513, 7514, 7515}}, -- 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
}

function 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 table.contains(targetType.shrine, targetId) then
            player:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
            return true
        end

        if player:getMana() < items.valuables.mana then
            player:sendCancelMessage(RETURNVALUE_NOTENOUGHMANA)
            return true
        end

        if player:getSoul() < items.valuables.soul then
            player:sendCancelMessage(RETURNVALUE_NOTENOUGHSOUL)
            return true
        end
        player:addSoul(-items.valuables.soul)
        player:addMana(-items.valuables.mana)
        player:addManaSpent(items.valuables.mana)
        player:addItem(targetType.id)
        player:getPosition():sendMagicEffect(items.valuables.effect)
        --player:sendSupplyUsed(item)
        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()
                --player:sendSupplyUsed(target)
                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 not storageValue then
                        return false
                    end

                    local transform = targetItem.id and targetItem.id[storageValue]
                    if not transform then
                        return false
                    end
                    target:transform(transform.id)
                    -- Local level
                    local minLevel = 55
                    local maxLevel = 75
                    local randomLevel = math.random(minLevel, maxLevel)
                    -- ItemLevel
                    target:setItemLevel(randomLevel, false)
                    target:setRarity(COMMON)
                    -- Roll
                    local itemType = ItemType(transform.id)
                    local weaponType = itemType:getWeaponType()
                    target:rollAttribute(player, itemType, weaponType, true)
                    --target:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
                else
                    target:transform(targetItem.id)
                    -- Local level
                    local minLevel = 55
                    local maxLevel = 75
                    local randomLevel = math.random(minLevel, maxLevel)
                    -- ItemLevel
                    target:setItemLevel(randomLevel, false)
                    target:setRarity(COMMON)
                    -- Roll
                    local itemType = ItemType(targetItem.id)
                    local weaponType = itemType:getWeaponType()
                    target:rollAttribute(player, itemType, weaponType, true)
                    --target:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
                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
                --player:sendSupplyUsed(item)
                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

there should be some local variable that identifies the item onUse, taking it from table such as happens here:
LUA:
[8905] = { -- rainbow shield
            [COMBAT_FIREDAMAGE] = {id = 8906}, [COMBAT_ICEDAMAGE] = {id = 8907},
            [COMBAT_EARTHDAMAGE] = {id = 8909}, [COMBAT_ENERGYDAMAGE] = {id = 8908}
        },
in some point the script knows it is 8906, or 8907, 8909 or 8909 and then assigns the
LUA:
target:setItemLevel(randomLevel, false)
                    target:setRarity(COMMON)

so how could it be like
LUA:
[8905] = { -- rainbow shield
            [COMBAT_FIREDAMAGE] = {id = 8906, min = 50, max = 100}, [COMBAT_ICEDAMAGE] = {id = 8907, min = 50, max = 100},
            [COMBAT_EARTHDAMAGE] = {id = 8909, min = 50, max = 100}, [COMBAT_ENERGYDAMAGE] = {id = 8908, min = 50, max = 100}
        },

and call it on
LUA:
  local minLevel = 55 --- use min from table instead
                    local maxLevel = 75 --- use max from table instead
                    local randomLevel = math.random(minLevel, maxLevel)

Ended up trying this based on GPT feedback (adding minLevel and maxLevel next to id, so it display as id = xxxx, minLevel = xxxx, maxLevel = xxx) but it didnt' work and throw this error:
1735764191217.webp
1735764218510.webp

If you want to access rainbow shields number for min, from that example, it would be exactly like this
LUA:
items.equipment[8905][COMBAT_FIREDAMAGE].min
but how could I automate the selection from the table, so it already knows which type of combat and item id is it? like replacing the 8905 and the combat_firedamage with a local function that recognize which item is going to be the outcome (I think the script already does it somewhere)

Thanks in advance
Regards!
 
Last edited:
Solution
This might do the trick..

LUA:
local combatOption = items.valuables[itemId].combatType
local minLevel = items.equipment[targetId][combatOption].min
local maxLevel = items.equipment[targetId][combatOption].max
local randomLevel = math.random(minLevel, maxLevel)
Thanks for the help bro! We had a good chat on discord trying to figure out this. It is still throwing nil for some reason.
1735770050244.webp
If someone else wish to try is welcome! For the moment I know I have to do a few prints like print(itemId), print(targetId), print(items.valuables[itemId]) but i'm really bad doing code, so I don't even know where to place the prints.

Any help is welcome!
Regards and thanks in advance :)
Post automatically merged:

Solved by @Xikini, this is the outcome:
LUA:
local items = {...
This might do the trick..

LUA:
local combatOption = items.valuables[itemId].combatType
local minLevel = items.equipment[targetId][combatOption].min
local maxLevel = items.equipment[targetId][combatOption].max
local randomLevel = math.random(minLevel, maxLevel)
 
This might do the trick..

LUA:
local combatOption = items.valuables[itemId].combatType
local minLevel = items.equipment[targetId][combatOption].min
local maxLevel = items.equipment[targetId][combatOption].max
local randomLevel = math.random(minLevel, maxLevel)
Thanks for the help bro! We had a good chat on discord trying to figure out this. It is still throwing nil for some reason.
1735770050244.webp
If someone else wish to try is welcome! For the moment I know I have to do a few prints like print(itemId), print(targetId), print(items.valuables[itemId]) but i'm really bad doing code, so I don't even know where to place the prints.

Any help is welcome!
Regards and thanks in advance :)
Post automatically merged:

Solved by @Xikini, this is the outcome:
LUA:
local items = {
    equipment = {
        [2147] = { -- small ruby
            [COMBAT_FIREDAMAGE] = {id = 2343, targetId = 2147} -- helmet of the ancients (enchanted)
        },
        [2383] = { -- spike sword
            [COMBAT_FIREDAMAGE] = {id = 7744, min = 20, max = 30}, [COMBAT_ICEDAMAGE] = {id = 7763, min = 20, max = 30},
            [COMBAT_EARTHDAMAGE] = {id = 7854, min = 20, max = 30}, [COMBAT_ENERGYDAMAGE] = {id = 7869, min = 20, max = 30}
        },
        [2391] = { -- war hammer
            [COMBAT_FIREDAMAGE] = {id = 7758, min = 20, max = 30}, [COMBAT_ICEDAMAGE] = {id = 7777, min = 20, max = 30},
            [COMBAT_EARTHDAMAGE] = {id = 7868, min = 20, max = 30}, [COMBAT_ENERGYDAMAGE] = {id = 7883}
        },
        [2423] = { -- clerical mace
            [COMBAT_FIREDAMAGE] = {id = 7754, min = 20, max = 30}, [COMBAT_ICEDAMAGE] = {id = 7773, min = 20, max = 30},
            [COMBAT_EARTHDAMAGE] = {id = 7864, min = 20, max = 30}, [COMBAT_ENERGYDAMAGE] = {id = 7879, min = 20, max = 30}
        },
        [2429] = { -- barbarian axe
            [COMBAT_FIREDAMAGE] = {id = 7749, min = 20, max = 30}, [COMBAT_ICEDAMAGE] = {id = 7768, min = 20, max = 30},
            [COMBAT_EARTHDAMAGE] = {id = 7859, min = 20, max = 30}, [COMBAT_ENERGYDAMAGE] = {id = 7874, min = 20, max = 30}
        },
        [2430] = { -- knight axe
            [COMBAT_FIREDAMAGE] = {id = 7750, min = 20, max = 30}, [COMBAT_ICEDAMAGE] = {id = 7769, min = 20, max = 30},
            [COMBAT_EARTHDAMAGE] = {id = 7860, min = 20, max = 30}, [COMBAT_ENERGYDAMAGE] = {id = 7875, min = 20, max = 30}
        },
        [2445] = { -- crystal mace
            [COMBAT_FIREDAMAGE] = {id = 7755, min = 20, max = 30}, [COMBAT_ICEDAMAGE] = {id = 7774, min = 20, max = 30},
            [COMBAT_EARTHDAMAGE] = {id = 7865}, [COMBAT_ENERGYDAMAGE] = {id = 7880, min = 20, max = 30}
        },
        [2454] = { -- war axe
            [COMBAT_FIREDAMAGE] = {id = 7753, min = 20, max = 30}, [COMBAT_ICEDAMAGE] = {id = 7772, min = 20, max = 30},
            [COMBAT_EARTHDAMAGE] = {id = 7863, min = 20, max = 30}, [COMBAT_ENERGYDAMAGE] = {id = 7878, min = 20, max = 30}
        },
        [7380] = { -- headchopper
            [COMBAT_FIREDAMAGE] = {id = 7752, min = 20, max = 30}, [COMBAT_ICEDAMAGE] = {id = 7771, min = 20, max = 30},
            [COMBAT_EARTHDAMAGE] = {id = 7862, min = 20, max = 30}, [COMBAT_ENERGYDAMAGE] = {id = 7877, min = 20, max = 30}
        },
        [7383] = { -- relic sword
            [COMBAT_FIREDAMAGE] = {id = 7745, min = 20, max = 30}, [COMBAT_ICEDAMAGE] = {id = 7764, min = 20, max = 30},
            [COMBAT_EARTHDAMAGE] = {id = 7855}, [COMBAT_ENERGYDAMAGE] = {id = 7870, min = 20, max = 30}
        },
        [7384] = { -- mystic blade
            [COMBAT_FIREDAMAGE] = {id = 7746, min = 20, max = 30}, [COMBAT_ICEDAMAGE] = {id = 7765, min = 20, max = 30},
            [COMBAT_EARTHDAMAGE] = {id = 7856, min = 20, max = 30}, [COMBAT_ENERGYDAMAGE] = {id = 7871, min = 20, max = 30}
        },
        [7389] = { -- heroic axe
            [COMBAT_FIREDAMAGE] = {id = 7751, min = 20, max = 30}, [COMBAT_ICEDAMAGE] = {id = 7770, min = 20, max = 30},
            [COMBAT_EARTHDAMAGE] = {id = 7861, min = 20, max = 30}, [COMBAT_ENERGYDAMAGE] = {id = 7876, min = 20, max = 30}
        },
        [7392] = { -- orcish maul
            [COMBAT_FIREDAMAGE] = {id = 7757, min = 20, max = 30}, [COMBAT_ICEDAMAGE] = {id = 7776, min = 20, max = 30},
            [COMBAT_EARTHDAMAGE] = {id = 7867, min = 20, max = 30}, [COMBAT_ENERGYDAMAGE] = {id = 7882, min = 20, max = 30}
        },
        [7402] = { -- dragon slayer
            [COMBAT_FIREDAMAGE] = {id = 7748, min = 20, max = 30}, [COMBAT_ICEDAMAGE] = {id = 7767, min = 20, max = 30},
            [COMBAT_EARTHDAMAGE] = {id = 7858, min = 20, max = 30}, [COMBAT_ENERGYDAMAGE] = {id = 7873, min = 20, max = 30}
        },
        [7406] = { -- blacksteel sword
            [COMBAT_FIREDAMAGE] = {id = 7747, min = 20, max = 30}, [COMBAT_ICEDAMAGE] = {id = 7766, min = 20, max = 30},
            [COMBAT_EARTHDAMAGE] = {id = 7857, min = 20, max = 30}, [COMBAT_ENERGYDAMAGE] = {id = 7872, min = 20, max = 30}
        },
        [7415] = { -- cranial basher
            [COMBAT_FIREDAMAGE] = {id = 7756, min = 20, max = 30}, [COMBAT_ICEDAMAGE] = {id = 7775, min = 20, max = 30},
            [COMBAT_EARTHDAMAGE] = {id = 7866, min = 20, max = 30}, [COMBAT_ENERGYDAMAGE] = {id = 7881, min = 20, max = 30}
        },
        [8905] = { -- rainbow shield
            [COMBAT_FIREDAMAGE] = {id = 8906, min = 180, max = 190}, [COMBAT_ICEDAMAGE] = {id = 8907, min = 180, max = 190},
            [COMBAT_EARTHDAMAGE] = {id = 8909, min = 180, max = 190}, [COMBAT_ENERGYDAMAGE] = {id = 8908, min = 180, max = 190}
        },
        [9949] = { -- dracoyle statue
            [COMBAT_EARTHDAMAGE] = {id = 9948} -- dracoyle statue (enchanted)
        },
        [9954] = { -- dracoyle statue
            [COMBAT_EARTHDAMAGE] = {id = 9953} -- dracoyle statue (enchanted)
        },
        [10022] = { -- worn firewalker boots
            [COMBAT_FIREDAMAGE] = {id = 9933, say = {text = "Quitate las botas antes de encantarlas."}},
            slot = {type = CONST_SLOT_FEET, 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 = {7508, 7509, 7510, 7511}}, -- small sapphire
        [2147] = {id = 7760, shrine = {7504, 7505, 7506, 7507}}, -- small ruby
        [2149] = {id = 7761, shrine = {7516, 7517, 7518, 7519}}, -- small emerald
        [2150] = {id = 7762, shrine = {7512, 7513, 7514, 7515}}, -- 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
}

function 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 table.contains(targetType.shrine, targetId) then
            player:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
            return true
        end
   
        if player:getMana() < items.valuables.mana then
            player:sendCancelMessage(RETURNVALUE_NOTENOUGHMANA)
            return true
        end
   
        if player:getSoul() < items.valuables.soul then
            player:sendCancelMessage(RETURNVALUE_NOTENOUGHSOUL)
            return true
        end
        player:addSoul(-items.valuables.soul)
        player:addMana(-items.valuables.mana)
        player:addManaSpent(items.valuables.mana)
        player:addItem(targetType.id)
        player:getPosition():sendMagicEffect(items.valuables.effect)
        --player:sendSupplyUsed(item)
        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()
                --player:sendSupplyUsed(target)
                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 not storageValue then
                        return false
                    end
   
                    local transform = targetItem.id and targetItem.id[storageValue]
                    if not transform then
                        return false
                    end
                    target:transform(transform.id)
                    if targetItem.min then
                        -- Local level
                        local minLevel = targetItem.min
                        local maxLevel = targetItem.max
                        local randomLevel = math.random(minLevel, maxLevel)
                        -- ItemLevel
                        target:setItemLevel(randomLevel, false)
                        target:setRarity(COMMON)
                        -- Roll
                        local itemType = ItemType(transform.id)
                        local weaponType = itemType:getWeaponType()
                        target:rollAttribute(player, itemType, weaponType, true)
                        --target:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
                    end
                else
                    target:transform(targetItem.id)
                    if targetItem.min then
                        -- Local level
                        local minLevel = targetItem.min
                        local maxLevel = targetItem.max
                        local randomLevel = math.random(minLevel, maxLevel)
                        -- ItemLevel
                        target:setItemLevel(randomLevel, false)
                        target:setRarity(COMMON)
                        -- Roll
                        local itemType = ItemType(targetItem.id)
                        local weaponType = itemType:getWeaponType()
                        target:rollAttribute(player, itemType, weaponType, true)
                        --target:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
                    end
                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
                --player:sendSupplyUsed(item)
                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

VERY IMPORTANT MESSAGE FROM XIKINI:
1735787890140.webp
 
Last edited:
Solution

Similar threads

Back
Top