Advertisement
Guest User

upgrade

a guest
Jul 22nd, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.86 KB | None | 0 0
  1. --- Sistema de Upgrade de itens feito por Killua.
  2. --- Sistema feito com base no do Bronson Server.
  3.  
  4. local vocations = {1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12} -- Vocações que podem refinar itens
  5.  
  6. local ids_bloqueados = {2160, 5706, 2463} -- Itens que não podem ser refinados
  7.  
  8. local controle = {
  9. {level = 0, quantOre = 1, chance = 100}, -- Level do item, quantidade de Iron Ore necessaria, chance de sucesso
  10. {level = 1, quantOre = 1, chance = 50},
  11. {level = 2, quantOre = 1, chance = 20},
  12. {level = 3, quantOre = 1, chance = 1},
  13. {level = 4, quantOre = 1, chance = 1}
  14. }
  15.  
  16. function getItemLevel(uid)
  17. if uid > 0 then
  18. return getItemAttribute(uid, "lvl") or 0
  19. end
  20. return false
  21. end
  22.  
  23. function doItemAddLevel(uid, count)
  24. if uid > 0 and tonumber(count) > 0 then
  25. return doItemSetAttribute(uid, "lvl", getItemLevel(uid) + count)
  26. end
  27. return false
  28. end
  29.  
  30. function onUse(cid, item, fromPosition, itemEx, toPosition)
  31. if not isInArray(vocations, getPlayerVocation(cid)) then
  32. return doPlayerSendCancel(cid, "Sua vocacao nao pode refinar.")
  33. elseif isInArray(ids_bloqueados, itemEx.uid) then
  34. return doPlayerSendCancel(cid, "This is not a valid upgrade tool.")
  35. end
  36.  
  37. if getItemInfo(itemEx.itemid).attack > 0 or getItemInfo(itemEx.itemid).defense > 0 or getItemInfo(itemEx.itemid).armor > 0 then
  38. for _, upgrade in pairs(controle) do
  39. local atk = getItemAttribute(itemEx.uid, "attack") or getItemInfo(itemEx.itemid).attack
  40. local def = getItemAttribute(itemEx.uid, "defense") or getItemInfo(itemEx.itemid).defense
  41. local arm = getItemAttribute(itemEx.uid, "armor") or getItemInfo(itemEx.itemid).armor
  42. local chance = math.random(1, 100)
  43. if getItemLevel(itemEx.uid) == upgrade.level then
  44. if doPlayerRemoveItem(cid, 8306, upgrade.quantOre) then
  45. doSendMagicEffect(getThingPos(itemEx.uid), CONST_ME_CRAPS)
  46. if chance <= upgrade.chance then
  47. if getItemLevel(itemEx.uid) == 0 then
  48. doItemSetAttribute(itemEx.uid, "description", "Esse item foi refinado por" ..getCreatureName(cid))
  49. end
  50. doItemAddLevel(itemEx.uid, 1)
  51. doItemSetAttribute(itemEx.uid, "name", getItemNameById(itemEx.itemid).. " + " ..getItemLevel(itemEx.uid))
  52. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have upgraded "..getItemNameById(itemEx.itemid).." to level +" ..getItemLevel(itemEx.uid))
  53. --doBroadcastMessage("The player " .. getCreatureName(cid) .. " was successful in upgrading "..getItemNameById(itemEx.itemid).." to level +" ..getItemLevel(itemEx.uid).." Congratulations.", MESSAGE_STATUS_CONSOLE_BLUE)
  54. if getItemInfo(itemEx.itemid).attack > 0 then
  55. doItemSetAttribute(itemEx.uid, "attack", atk + 1)
  56. return true
  57. elseif getItemInfo(itemEx.itemid).armor > 0 then
  58. doItemSetAttribute(itemEx.uid, "armor", arm + 1)
  59. return true
  60. elseif getItemInfo(itemEx.itemid).defense > 0 and getItemInfo(itemEx.itemid).attack <= 0 then
  61. doItemSetAttribute(itemEx.uid, "defense", def + 1)
  62. return true
  63. end
  64. else
  65. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have failed in upgrade.")
  66. return true
  67. end
  68. else
  69. doPlayerSendCancel(cid, "error report to GameMaster.")
  70. end
  71. end
  72. end
  73. else
  74. doPlayerSendCancel(cid, "This is not a valid upgrade tool.")
  75. end
  76. return true
  77. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement