BE

Blacksmith

Por bepokemon, 26 de out. de 2011 em Mods, funções e outros

otserv
tibia
script
11
2.2k
bepokemonB
26 de outubro de 2011 às 06:37

<?xml version="1.0" encoding="UTF-8"?>
<mod name="Blacksmith System" version="1.0" author="Uissu" contact="xtibia.com" enabled="yes">
<description>
You can use the command: /recipes (or any registered in the talkaction) to see the avaiable recipes. (In the table: Smiths)
Put all the items in order in the desired position (which is in front of player as default) and use the hammer
(id: 2422 as default) in the items. If you placed an existing recipe you'll receive a new item.
</description>

<config name="recipeList"><![CDATA[
smiths = {
[1] = {
name = 'scale armor',finalid = 2483,count = 1,exp = 250,type = 'Armor',level = 1,
recipe = {[1] = {id=5880,count=3},[2] = {id=2467,count=1}}},
[2] = {
name = 'chain armor',finalid = 2464,count = 1,exp = 1000,type = 'Armor',level = 5,
recipe = {[1] = {id=5880,count=6},[2] = {id=2467,count=1}}},
[3] = {
name = 'brass armor',finalid = 2465,count = 1,exp = 3000,type = 'Armor',level = 10,
recipe = {[1] = {id=5880,count=10},[2] = {id=2467,count=1}}},
[4] = {
name = 'plate armor',finalid = 2463,count = 1,exp = 5000,type = 'Armor',level = 15,
recipe = {[1] = {id=5880,count=5},[2] = {id=5887,count=1},[3] = {id=2467,count=1}}},
[5] = {
name = 'dragon scale mail',finalid = 2492,count = 1,exp = 50000,type = 'Armor',level = 50,
recipe = {[1] = {id=5920,count=25},[2] = {id=2483,count=1}}},
[6] = {
name = 'golden armor',finalid = 2466,count = 1,exp = 75000,type = 'Armor',level = 60,
recipe = {[1] = {id=2157,count=10},[2] = {id=2465,count=1}}},
[7] = {
name = 'magic plate armor',finalid = 2472,count = 1,exp = 100000,type = 'Armor',level = 100,
recipe = {[1] = {id=2162,count=1},[2] = {id=5944,count=50},[3] = {id=2463,count=1}}},
[8] = {
name = 'demon armor',finalid = 2494,count = 1,exp = 250000,type = 'Armor',level = 125,
recipe = {[1] = {id=5944,count=10},[2] = {id=5888,count=5},[3] = {id=6500,count=25},[4] = {id=5906,count=100},[5] = {id=2464,count=1}}},
}
]]></config>

<action itemid="2422" event="buffer"><![CDATA[
domodlib('recipeList')

local match = FALSE
local itemPos = getPlayerLookPos(cid)

for x=1,table.maxn(smiths) do
local r = smiths[x]

for z=1,table.maxn(r.recipe) do
itemPos.stackpos = z+1
local item = getThingFromPos(itemPos)
local itemCount = math.max(1,item.type)
if (item.itemid == r.recipe[z].id) and (itemCount == r.recipe[z].count) then
if z == table.maxn(r.recipe) then
match = TRUE
break
end
end
if match == TRUE then break end
end

if match == TRUE then

if getPlayerLevel(cid) < r.level then
doPlayerSendCancel(cid, "Not enough level.")
return true
end

doCleanTile(itemPos)
doCreateItem(r.finalid, r.count, itemPos)
doSendAnimatedText(itemPos, "SUCCESS!", TEXTCOLOR_GREY)
doSendMagicEffect(itemPos, 9)
doPlayerAddExp(cid, r.exp)
doSendAnimatedText(getThingPos(cid), r.exp, TEXTCOLOR_WHITE)
doPlayerSendTextMessage(cid, 27, "You\'ve successfully smithed a "..r.name..". Gained "..r.exp.." experience.")
break
else
doPlayerSendCancel(cid, "This recipe doesn\'t seems to match.")
end
end
]]></action>
<item id="2422" article="a" name="blacksmith hammer" override="yes"/>
<talkaction words="!blacksmith;!recipes;/blacksmith;/recipes" event="buffer"><![CDATA[
domodlib('recipeList')

local text = 'All a blacksmith must know:\n\n'
local i = 0

repeat
i = i+1
local s = smiths[i].type
local t = smiths[i].recipe

text = text..'[Recipe #'..i..' '..s..' - '..smiths[i].name..']:\n'

for n=1,table.maxn(t) do
a = (table.maxn(t)+1)-n
text = text..'#'..n..' - '..t[a].count..' '..getItemNameById(t[a].id)..'\n'
end
until i == table.maxn(smiths)

doShowTextDialog(cid, 1950, text)
]]></talkaction>

</mod>

 

Voce pode editar uma receita desta maneira:

[numerodepoisdoanterior] = {
name = 'nome do prodruto',finalid = ID do Produto,count = Count do produto,exp = experiencia que vai dar,type = 'Tipo',level = level minimo,
recipe = {[1] = {id=ID,count=QUANTIDADE},[2] = {id=ID,count=QUANTIDADE}}},

 

Lebrando que pode ser usado em qualquer lugar e so funciona olhando de frente para os items na hora de usar o blacksmith hammer (id 2422), se alguem conseguir, eu preciso colocar 'itemPos = toPosition' (lugar aonde usei o hammer). Nao consegui de nenhuma forma em MOD pois foi meu primeiro ... Obrigado desde ja, espero que gostem.

Editado Outubro 26 por Byerne

angeldoidoA
26 de outubro de 2011 às 07:34

como funciona o script, desculpa naum entendi -'

 

Poderia agelizar fotos ?

SkyDangerousS
26 de outubro de 2011 às 10:03

Ainda não testei.

Mas script em mod é uma beleza , eu só faço em mod :>

Parabéns :>

angeldoidoA
26 de outubro de 2011 às 10:13

aah tah '--'

 

n funfo POSAPSK

Editado Outubro 26 por Snokiuthu

bepokemonB
26 de outubro de 2011 às 17:15

Ainda não testei.

Mas script em mod é uma beleza , eu só faço em mod :>

Parabéns :>

 

=D Eu comecei a fazer agora .. esse foi meu primeiro, por isso nao esta 100% como estaria em LUA

 

OBS: Eu namoro ._.'

OneshotO
28 de outubro de 2011 às 18:03

Nada mal, ficou bem feito e você soube se utilizar do controlador repeat muito bem. A parte chata é que o script não é "esperto", se eu tenho os itens para fazer uma Scale Armor e os coloco no chão em ordem contrária ao proposto pela configuração no script, a receita não é entendida. :\

 

Obrigado pela sua contribuição!

Editado Outubro 28 por Oneshot

bepokemonB
28 de outubro de 2011 às 18:54

Nada mal, ficou bem feito e você soube se utilizar do controlador repeat muito bem. A parte chata é que o script não é "esperto", se eu tenho os itens para fazer uma Scale Armor e os coloco no chão em ordem contrária ao proposto pela configuração no script, a receita não é entendida. :\

 

Obrigado pela sua contribuição!

 

Sim, nao pensei nisso porque meu script anterior era de Alquimia, onde a ordem importa, mas dando um chute era soh fazer um array para os items e ir procurando.

 

if not isInArray(array, itemid) then
'something is wrong'
return true
end

local contains = 0
local stackStart = getTileThingFromPos(toPosition).stackpos
local correctRecipe = false
repeat
for _,v in pairs(array) do
toPosition.stackpos = stackStart
item = getTileThingFromPos(toPosition)
if item.type == v.count and item.itemid = v.id then
contains = contains + 1
stackStart == stackStart-1
end
if contains == #array then
correctRecipe = true
end
end
until stackStart == 2

if correctRecipe then
-- fazer item
else
'wrong recipe.'
end

OneshotO
28 de outubro de 2011 às 20:18

Bom, vi que você está precisando do parâmetro toPosition e até esqueci de esclarecer essa dúvida.

 

O ato de declarar um evento "buffer" usando CDATA não te impede de usar funções na composição do código, ou seja:

 

<action itemid="2422" event="buffer">
<![CDATA[
function onUse(cid, item, fromPosition, itemEx, toPosition)
	return print(toPosition.x)
end
]]></action>

 

É totalmente válido.

 

Se você precisar de ajuda com a otimização da sintaxe, só falar :D

bepokemonB
29 de outubro de 2011 às 22:23

Bom, vi que você está precisando do parâmetro toPosition e até esqueci de esclarecer essa dúvida.

 

O ato de declarar um evento "buffer" usando CDATA não te impede de usar funções na composição do código, ou seja:

 

<action itemid="2422" event="buffer">
<![CDATA[
function onUse(cid, item, fromPosition, itemEx, toPosition)
	return print(toPosition.x)
end
]]></action>

 

É totalmente válido.

 

Se você precisar de ajuda com a otimização da sintaxe, só falar :D

 

Eu sei, tenho outros mods usando funçoes a questao eh que quando passei de script (que usava topositions) e coloquei em mod nao funcionou mais. E tentei muitas outras coisas tambem .. :X Seria possivel voce tentar adptar? estou meio sem tempo.

1 mês depois...
risada21R
24 de novembro de 2011 às 18:06

Sistema Nao Funciona.

Reprovado

Apenas é Possivel fazer a Leitura dos Itens.

Mas nao é Possivel Fondar.

Existe um Topico Ja Exitente ao qual achei o Tal Script.

Clique Aqui

24 de novembro de 2011 às 21:20

Entrei para falar o mesmo que o Oneshot já disse, acho que o melhor jeito de fazer o seu script interpretar os itens na ordem inversa seria este:

 

function getItens(pos, recipe)

local f = nil

for a = 1, #recipe do
s = nil
for i = 1, 255 do
pos.stackpos = i
if s ~= a then
if getThingFromPos(pos).itemid == recipe[a].id and getThingFromPos(pos).type >= recipe[a].count then
f = f and f+1 or 1
s = a
end
end
end
end

return f == #recipe
end

Editado Novembro 24 por Demonbholder