Refiz outro sistema meu, agora o Blacksmith System, ele ficou fácil de configurar e agora é baseado em uma function addForge, contida no script.
Para iniciar o sistema, faça 2 bancadas no mapa, a de cima com 1 alavanca de actionid 51121, caso tenha dúvida nesta parte, olhe as screenshoots no final do tópico.
Depois de fazer isto, faça um script chamado blacksmith.lua em actions/scripts/others contendo:
function addForge(cid, reward, tablepos, itemsneeded, percent)
if (percent > 100) then
percent = 100
end
playerpos = getPlayerPosition(cid)
errors = 0
for k,v in pairs(itemsneeded) do
itemstackpos = k+1
itemidneed = v['itemid']
itemidquantity = v['quantity']
itemposition = {x=tablepos.x, y=tablepos.y, z=tablepos.z, stackpos = itemstackpos}
itemfromposition = getThingfromPos(itemposition)
if (itemidquantity == 1) then
itemidquantity = itemfromposition.type
end
if itemfromposition.itemid == itemidneed and itemfromposition.type == itemidquantity then
else
errors = 1
end
end
if (errors == 1) then
doSendMagicEffect(playerpos,2)
return FALSE
else
chance = math.random(0,100)
if (chance <= percent) then
forja = true
end
for k,v in pairs(itemsneeded) do
itemstackpos = k+1
itemidneed = v['itemid']
itemidquantity = v['quantity']
itemposition = {x=tablepos.x, y=tablepos.y, z=tablepos.z, stackpos = 2}
itemfromposition = getThingfromPos(itemposition)
doRemoveItem(itemfromposition.uid,itemidquantity)
end
if (forja == true) then
doSendMagicEffect(tablepos,13)
doSendAnimatedText(playerpos,"Congratz!",180)
doPlayerAddItem(cid, reward['itemid'], reward['quantity'])
doPlayerSendTextMessage(cid, 21, "Congratulations! You got ".. reward['quantity'] .." ".. getItemName(reward['itemid']) .."(s).")
else
doSendMagicEffect(tablepos,2)
doSendAnimatedText(playerpos,"Fail.",180)
doPlayerSendTextMessage(cid, 21, "The recipe was good, but it failed.")
end
return TRUE
end
end
function onUse(cid, item, fromPosition, itemEx, toPosition)
if (item.itemid == 1945) then
doTransformItem(item.uid,1946)
else
doTransformItem(item.uid,1945)
end
-- table need to stays below the lever
-- a mesa dos items precisa estar abaixo da alavanca
tablepos = {x=toPosition.x, y=toPosition.y+1, z=toPosition.z}
-- blacksmith configs below
-- configurações de forjas aqui embaixo
items = {}
items[1] = {}
items[1]['itemid'] = 2674
items[1]['quantity'] = 2
items[2] = {}
items[2]['itemid'] = 2676
items[2]['quantity'] = 3
reward = {}
reward['itemid'] = 2671
reward['quantity'] = 50
percent = 100
if (addForge(cid, reward, tablepos, items,percent) == TRUE) then end
items = {}
items[1] = {}
items[1]['itemid'] = 2671
items[1]['quantity'] = 5
items[2] = {}
items[2]['itemid'] = 2666
items[2]['quantity'] = 5
items[3] = {}
items[3]['itemid'] = 2515
items[3]['quantity'] = 1
reward = {}
reward['itemid'] = 2676
reward['quantity'] = 5
percent = 50
if (addForge(cid, reward, tablepos, items, percent) == TRUE) then end
items = {}
items[1] = {}
items[1]['itemid'] = 2463
items[1]['quantity'] = 1
reward = {}
reward['itemid'] = 2515
reward['quantity'] = 1
percent = 10
if (addForge(cid, reward, tablepos, items, percent) == TRUE) then end
-- here you can add new combinations of items
-- aqui você pode fazer novas combinações de items
end
Salve e feche.
Embaixo e em cima das partes que estão negritadas, é onde você configurará suas forjas, combinações de items, que será explicado no final do tópico.
Para finalizar o sistema, adiciona no arquivo actions.xml localizado em data/actions a seguinte tag:
<action actionid="51121" script="other/blacksmith.lua"/>
Ao salvar, acabamos nossos scripts.
Adicionando forjas
Para adicionar uma combinação de items, forja, adicione em cima de:
-- here you can add new combinations of items-- aqui você pode fazer novas combinações de items
O seguinte:
items = {}items[1] = {}
items[1]['itemid'] = 2463
items[1]['quantity'] = 1
reward = {}
reward['itemid'] = 2515
reward['quantity'] = 1
percent = 10
if (addForge(cid, reward, tablepos, items, percent) == TRUE) then end
De azul, é onde estam os items, aqui você configura todos os itemsid e quantidade destes mesmos items.
De vermelho, onde é configurado o prêmio desta forja quando ocorrer tudo certo.
De verde, é a porcentagem de acerto da forja, quanto menor, menos acertos. Sendo 100, 100% de acerto.
Em negrito, a function que ativa as forjas, aqui não precisa mexer.
Um pouco de prática e você aprende adicionar todas as forjas (Não é aconselhável usar items iguais para mais de 1 forja.)
Screenshoots:
Nota: A ordem dos items, é a ordem de visão, sendo o item[1], o primeiro a ser visto (o que está em cima).
//Yunie