local chance = nil
function onUse(cid, item, fromPosition, itemEx, toPosition)
if isInArray({0, 65535}, toPosition.x) then
return false
elseif getTileItemById(toPosition, 2555).uid < 1 then
return doPlayerSendCancel(cid, 'You must put the ingredients on an anvil.')
end
local tmp, match = {}
for ret, v in pairs(forges) do
for i = 1, #v.recipe do
local g = getTileItemById(toPosition, v.recipe[i][1])
if g.uid > 0 and math.max(1, g.type) == v.recipe[i][2] then
table.insert(tmp, g.uid)
if i == #v.recipe then
match = ret
chance = v.chance
end
else
tmp = {}
break
end
end
if match then
break
end
end
if match then
for i = 1, #tmp do
doRemoveItem(tmp[i], forges[match].recipe[i][2])
end
if(chance >= math.random(1, 1000)) then
doItemSetAttribute(doCreateItem(match, 1, toPosition), "description", "".. getItemInfo(match).description .."".. (config.credits == true and "\nIt has forged by ".. getCreatureName(cid) .."." or ""))
doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, "You have created ".. getItemInfo(match).article .." ".. getItemNameById(match)..".")
doSendMagicEffect(toPosition, CONST_ME_MAGIC_RED)
doSendAnimatedText(toPosition, "Success!", TEXTCOLOR_GREEN)
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, "Something went wrong.")
doSendMagicEffect(toPosition, CONST_ME_POFF)
doSendAnimatedText(toPosition, "Failure!", TEXTCOLOR_RED)
end
return true
end
return doPlayerSendCancel(cid, "This forge recipe doesn't exist.")
end
Vamos ver se assim vai...