Hello,
I found this script, I would like that instead of creating a new item it transforms the item with the same attributes as the previous one.
knight helmet LV1 to knight helmet LV2, for example
knight helmet LV1 XX (Arm:215)
Slots:
Increase 15% max melee.
Increase 15% max melee.
Increase 15% max melee.
Refine [Level: 15, Bônus: +175 Arm].
so the knight helmet LV2 would have the same attribute as level 1
on a specific tile would be the item with enchants and refinements
in two other common items, without refinements or enchantments
I found this script, I would like that instead of creating a new item it transforms the item with the same attributes as the previous one.
knight helmet LV1 to knight helmet LV2, for example
knight helmet LV1 XX (Arm:215)
Slots:
Increase 15% max melee.
Increase 15% max melee.
Increase 15% max melee.
Refine [Level: 15, Bônus: +175 Arm].
so the knight helmet LV2 would have the same attribute as level 1
on a specific tile would be the item with enchants and refinements
in two other common items, without refinements or enchantments
Lua:
--table structure:
--[ItemToUpgradeId] = {result = NewItemId, chance = chance to sucess}
local itensUpgrade = {
[25919] = {result = 25920, chance = 60},
[25920] = {result = 25921, chance = 40},
[25921] = {result = 25922, chance = 20}
}
--put a index and a tile for position, you can add more, just be sure to config.
--NOTE: this script is for a single altar, don't work with more than one at same time. Need changes or multiples files to more altars.
local sacrificePos = {
[1] = Tile(1026, 1026, 7),
[2] = Tile(1024, 1026, 7),
[3] = Tile(1024, 1027, 7)
}
local newItemPos = Tile(1027, 1026, 7)
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local targetItem = -1 --initialize a variable to hold target item id
local itensToRemove = {} --initialize a table to hold all itens userData to remove
for _, tempPos in ipairs(sacrificePos) do --for each sacrifice position
local topItem = tempPos:getTopDownItem() --get top item of the position
--Top item don't exist
if not topItem then
return true
end
--Top item in some sacrifice position don't is a upgradable item
if not itensUpgrade[topItem:getId()] then
return true
end
--for first loop occurrence, set valid item to upgrade as target item
if targetItem == -1 then
targetItem = topItem:getId()
end
--some sacrifice item is diferent of other
if targetItem ~= topItem:getId() then
return true
end
table.insert(itensToRemove, topItem)--add the item userData to table
end
local randChance = math.random(1, 100)--get a random number
local effect = 12--initialize a variable to hold effect to be sended to player
local msg = ""--initialize a variable to hold msg to be sended to player
local materialCountToRemove = 0--initialize a variable to hold the count of itens that will be removed
--if the random chance number is lower or equal to chance to sucess
if randChance <= itensUpgrade[targetItem].chance then
--sucess
materialCountToRemove = #itensToRemove --set remove count to ALL itens in table
msg = "Congratulations, your item has been upgrated to "..ItemType(itensUpgrade[targetItem].result):getName().."." --update msg
effect = CONST_ME_FIREWORK_RED --update effect
Game.createItem(itensUpgrade[targetItem].result, 1, newItemPos:getPosition()) --create the new item
else
--fail
materialCountToRemove = math.random(1, #itensToRemove)--get a random chance to remove from 1 to ALL itens
msg = "You failed to upgrade your item. You've lost "..materialCountToRemove.." "..ItemType(targetItem):getName().."."--update msg
effect = CONST_ME_POFF--update effect
end
--send effect and msg
player:getPosition():sendMagicEffect(effect)
player:sendTextMessage(MESSAGE_STATUS_SMALL, msg)
--remove material itens
for i = 1, materialCountToRemove do
--don't know if needed, don't know if when removing the item, it will be removed from table too?
local tmpItem = itensToRemove[i]
itensToRemove[i] = 0 --set to 0 the value of i Index, to preserv table size if removed itens is also removed from table
--itensToRemove[i]:remove()
tmpItem:remove()
end
return true
end