Ir para conteúdo
  • 0
shocks

Scripting Upgrading System

Pergunta

shocks    2
shocks

Base:  TFS 1.3 Custom

Eu recebo um erro no sistema de upgrade depois de usar o item de refinamento no item a ser refinado, isso acontece algumas vezes e nada acontece com o item de refinamento ou o item que está sendo refinado, mas há momentos em que o item refina normalmente.

Erro:

Lua Script Error: [Action Interface] 
data/actions/scripts/upgrade.lua:onUse
data/actions/scripts/upgrade.lua:52: attempt to compare number with nil

Linha de Erro: 

if(nLevel > level)then

Codigo:

Spoiler

local conf = {
   ["level"] = {
   -- [item_level] = {successPercent= CHANCE TO UPGRADE ITEM, downgradeLevel = ITEM GETS THIS LEVEL IF UPGRADE FAILS}
     [1] = {successPercent = 90},
     [2] = {successPercent = 80},
     [3] = {successPercent = 70},
     [4] = {successPercent = 60},
     [5] = {successPercent = 50},
     [6] = {successPercent = 40, downgradeLevel = 5},
     [7] = {successPercent = 30, downgradeLevel = 6},
     [8] = {successPercent = 25, downgradeLevel = 7},
     [9] = {successPercent = 20, downgradeLevel = 8},
     [10] = {successPercent = 15, downgradeLevel = 9}
   },
   ["upgrade"] = { -- how many percent attributes are rised?
     attack = 2, -- attack %
     defense = 2, -- defense %
     extraDefense = 5, -- extra defense %
     armor = 2, -- armor %   
   }
}
-- // do not touch // --
-- Upgrading system by Azi [Ersiu] --
-- Edited for TFS 1.1 by Zbizu --
local upgrading = {
  upValue = function (value, level, percent)
  if value < 0 then return 0 end
     if level == 0 then return value end
     local nVal = value
     for i = 1, level do
       nVal = nVal + (math.ceil((nVal/100*percent)))
     end
  return nVal > 0 and nVal or value
  end,
  getLevel = function (item)
  local name = Item(item):getName():split('+')
     if (#name == 1) then
       return 0
     end
     return math.abs(name[2])
  end,
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
player  = cid
cid = cid:getId()

   local it = ItemType(itemEx.itemid)
if (((it:getWeaponType() > 0 and it:getWeaponType() ~= WEAPON_WAND) or getItemAttribute(itemEx.uid, ITEM_ATTRIBUTE_ARMOR) > 0) and not isItemStackable(itemEx.itemid)) then
  local level = upgrading.getLevel(itemEx.uid)
  if(level < #conf["level"])then
  local nLevel = (conf["level"][(level+1)].successPercent >= math.random(1,100)) and (level+1) or conf["level"][level].downgradeLevel
  if(nLevel > level)then
  doSendMagicEffect(toPosition, CONST_ME_MAGIC_GREEN)
  doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Upgrade to level " .. nLevel .. " successful!")
  else
  doSendMagicEffect(toPosition, CONST_ME_BLOCKHIT)
  doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Upgrade failed. Your " .. it:getName() .. " is now on level " .. nLevel .. "")
  end
  doItemSetAttribute(itemEx.uid, ITEM_ATTRIBUTE_NAME, it:getName()..((nLevel>0) and "+"..nLevel or ""))
  doItemSetAttribute(itemEx.uid, ITEM_ATTRIBUTE_ATTACK,  upgrading.upValue(it:getAttack(), nLevel, conf["upgrade"].attack))
  doItemSetAttribute(itemEx.uid, ITEM_ATTRIBUTE_DEFENSE, upgrading.upValue(it:getDefense(), nLevel, conf["upgrade"].defense))
  doItemSetAttribute(itemEx.uid, ITEM_ATTRIBUTE_EXTRADEFENSE, upgrading.upValue(it:getExtraDefense(), nLevel, conf["upgrade"].extraDefense))
  doItemSetAttribute(itemEx.uid, ITEM_ATTRIBUTE_ARMOR, upgrading.upValue(it:getArmor(), nLevel, conf["upgrade"].armor))
  doRemoveItem(item.uid, 1)
  else
  doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Your " .. it:getName() .. " is on max level alredy.")
  end
  else
  doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You cannot upgrade this item.")
  end
  end

 

 

 

Editado por shocks
Adicionado linha de erro

Compartilhar este post


Link para o post
Compartilhar em outros sites

1 resposta a esta questão

Recommended Posts

  • 0
shocks    2
shocks

Script resolvido por discord : @TheRatazana#5726

Apenas adicionar a linha nos que faltam.

downgradeLevel = lvl
Editado por shocks
Adição do "lvl"

Compartilhar este post


Link para o post
Compartilhar em outros sites
Visitante
Este tópico está impedido de receber novos posts.

  • Quem Está Navegando   0 membros estão online

    Nenhum usuário registrado visualizando esta página.

×