Piifafa
Member
- Joined
- Apr 16, 2023
- Messages
- 68
- Reaction score
- 18
Hello guys, I really need help developing my gem attribute system.
A version of TFS 1.2 with little 1.3 (based on Nostalrius)
At the moment my script manages to increase the refinement of the weapons, but when it fails since it comes back 1 attribute or takes it off simply nothing happens.
Knowing this, I tried to create a way in which the weapon is saved, and when the person clicks and fails he clones the weapon but removes that weapon, something like this, I don't know if possible, in the case player would not lose the weapon, but would lose the attributes that way. I know it's a little complicated but I believe that the most experienced user knows how to adjust this.
Enchantment limiter is also already working.
A version of TFS 1.2 with little 1.3 (based on Nostalrius)
At the moment my script manages to increase the refinement of the weapons, but when it fails since it comes back 1 attribute or takes it off simply nothing happens.
Knowing this, I tried to create a way in which the weapon is saved, and when the person clicks and fails he clones the weapon but removes that weapon, something like this, I don't know if possible, in the case player would not lose the weapon, but would lose the attributes that way. I know it's a little complicated but I believe that the most experienced user knows how to adjust this.
Enchantment limiter is also already working.
LUA:
local weaponTypes = {WEAPON_SWORD, WEAPON_CLUB, WEAPON_AXE}
local attrConfig = {maxValue = 10}
local attrs = {
[1] = {code = ITEM_ATTRIBUTE_LIFELEECH, effect = CONST_ME_MAGIC_GREEN},
[2] = {code = ITEM_ATTRIBUTE_MANALEECH, effect = CONST_ME_MAGIC_BLUE},
[3] = {code = ITEM_ATTRIBUTE_CRITICAL, effect = CONST_ME_CRITICAL_DAMAGE},
[4] = {code = ITEM_ATTRIBUTE_ATTACK, effect = CONST_ME_DRAWBLOOD, base = true},
[5] = {code = ITEM_ATTRIBUTE_DEFENSE, effect = CONST_ME_BLOCKHIT, base = true}
}
local gemsEeffect = {
[5245] = {chance = 10},
[5246] = {chance = 15},
[5247] = {chance = 35},
[5248] = {chance = 50},
[5249] = {chance = 100},
}
function onUse(player, item, fromPosition, target, toPosition)
if not target or not target:isItem() then
return false
end
local itemTarget = target:getId()
local itemtype = ItemType(itemTarget)
local weapontype = itemtype:getWeaponType()
if not table.contains(weaponTypes, weapontype) then
return false
end
-- Usando o atributo de descrição para armazenar a contagem de encantamentos
local description = target:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION)
local attrEnchantCount = tonumber(description:match("(%d+) time")) or 0
if attrEnchantCount >= 10 then
player:sendTextMessage(MESSAGE_INFO_DESCR, "This equipment cannot be enchanted more than 10 times.")
return false
end
if item:remove(1) then
local currentGem = gemsEeffect[item:getId()]
if math.random(1, 100) <= math.min(math.max(10, currentGem.chance)) then
local randomAttr = math.random(1, #attrs)
local getCurrentAttr = target:getAttribute(attrs[randomAttr].code)
if getCurrentAttr == nil or getCurrentAttr == 0 then
getCurrentAttr = 1
if attrs[randomAttr].base then
if attrs[randomAttr].code == ITEM_ATTRIBUTE_ATTACK then
getCurrentAttr = itemtype:getAttack() + 1
elseif attrs[randomAttr].code == ITEM_ATTRIBUTE_DEFENSE then
getCurrentAttr = itemtype:getDefense() + 1
end
end
else
getCurrentAttr = getCurrentAttr + 1
end
-- Se falhar no encantamento, remover a arma atual e adicionar uma nova
if math.random(1, 100) <= math.min(math.max(10, (1 + attrEnchantCount))) then
if item:getId() ~= 5249 then
player:say('You lost the enchantment!', TALKTYPE_MONSTER_SAY)
-- Identificar a arma equipada
local equippedWeapon = player:getWeapon()
if equippedWeapon then
-- Arma a ser criada (substitua pelo ID correto da nova arma)
local newWeaponId = equippedWeapon:getId()
-- Remover a arma atual
player:removeItem(equippedWeapon:getId(), 1)
-- Criar uma nova arma com o mesmo ID
local newWeapon = Game.createItem(newWeaponId, 1)
if newWeapon then
player:addItem(newWeaponId, 1) -- Adiciona a nova arma ao inventário
player:sendTextMessage(MESSAGE_INFO_DESCR, "You received a new weapon!")
end
end
-- Resetar o contador de encantamentos
attrEnchantCount = 0
target:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, "The enchantment was lost.")
end
else
-- Aplicar o novo encantamento
target:setAttribute(attrs[randomAttr].code, getCurrentAttr)
attrEnchantCount = attrEnchantCount + 1 -- Incrementar sempre que um encantamento for bem-sucedido
target:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, 'This equipment was enchanted ' .. attrEnchantCount .. ' time' .. (attrEnchantCount == 1 and '' or 's') .. '.')
target:getPosition():sendMagicEffect(attrs[randomAttr].effect)
end
else
player:sendTextMessage(MESSAGE_INFO_DESCR, "The enchantment failed.")
end
end
return true
end