Ir para conteúdo

Featured Replies

Postado

Galera, seguinte! Preciso de um NPC que funcione como no Tibia 7.6, que compra e venda itens como no 7.6, tendo que falar "buy" e "sell" e a quantidade antes do item que deseja comprar ou vender, não como funciona hoje em dia que se fala "Trade" e aparece uma lista do lado. Segue o exemplo de como preciso:

 

Conversa entre player e NPC:

Player: Hi

NPC: Hello, Player, what you want for me? I'm selling and buying some itens...

Player: Buy 50 Mana Potion

NPC: You want to buy 50 Mana Potion for 1000 Gold Coins?

Player: Yes

NPC: Here is...

Player: Sell 100 Vials

NPC: You want to sell 100 Vials for 200 Gold Coins?

Player: Yes

Npc: Here is...

 

Basicamente isso... Como era antigamente. Quero poder ter um NPC que venda: Mace, Sword, Carlin Sword, Axe, etc e que compre: Mace, Sword, Carlin Sword, etc.

É possível? Alguém consegue? 

Rep++ com muito amor

  • Respostas 6
  • Visualizações 3.4k
  • Created
  • Última resposta

Top Posters In This Topic

Most Popular Posts

Posted Images

Postado

e seu servidor é 8.60?

 

pra fzr um npc desse vai precisar de uma gambiarrinha kk

 

 

MemeCenter_1453764771394_433.jpg

 

 

-------------------------------------------------------------------------------------

 

data > npc > lib

 

crie um arquivo.lua e renomei para

 

 npc-func.lua

local focuses = {}
function isFocused(cid, t)
for i, v in pairs(t) do
    if(v == cid) then
        return true
    end
end
return false
end

function addFocus(cid, t)
if(not isFocused(cid, t)) then
    table.insert(t, cid)
end
end

function setFocus(t)
for i, v in pairs(t) do
    if(isPlayer(v)) then
        doNpcSetCreatureFocus(v)
        return
    end
end
doNpcSetCreatureFocus(0)
end

function removeFocus(cid, t)
for i, v in pairs(t) do
    if(v == cid) then
        table.remove(t, i)
        setFocus(focuses)
        break
    end
end
end

function onCreatureDisappear(cid)
if isFocused(cid, focuses) then
 removeFocus(cid, focuses)
    if isPlayer(cid) then
     closeShopWindow(cid)
    end
end
end

 

 

 

--------------------------

 

data > npc

 

nome do seu npc.xml

<?xml version="1.0" encoding="UTF-8"?>
<npc name="nome do seu npc" script="oldbuyer.lua" walkinterval="5000" floorchange="0">
<health now="100" max="100"/>
<look type="133" head="114" body="119" legs="132" feet="114"/>
</npc>

 

 

data > npc > scripts

 

oldbuyer.lua

dofile("data/npc/lib/npc-func.lua")
local focuses = {} -- do not change

local shop = {
[{"axe", "axes"}] = {id=2386, buy = 20 , sell= 8}, -- id do item, por quanto ele vai comprar e por quanto ele vai vender, se colocar 0 ele n vende ou se colocar 0 nao compra o item
[{"club", "clubs"}] = {id=2382, buy = 20 , sell= 8},
[{"broadsword", "broadswords"}] =  {id=2413, buy = 100 , sell= 0},
[{"mastermind shield","mastermind shields"}] =  {id=2514, buy = 50000 , sell= 30000},
[{"demon backpack","demon backpacks"}] =  {id=10518, buy = 10000 , sell= 5000},
[{"scarab coin","scarab coins"}] =  {id=2159, buy = 50 , sell= 30}
}

function onBuy(cid, item, amount, price)
	if amount <= 100 then
		if doPlayerRemoveMoney(cid, price) then
			if isItemStackable(item) or amount == 1 then
				doPlayerAddItem(cid, item, amount)
			else
				for i = 1, amount do
					doPlayerAddItem(cid, item, 1)
				end
			end
		selfSay('Here your item(s)!', cid) talk_step = 1
		else
    		selfSay('You need '..price..' Gold Coins!', cid) talk_step = 1
		end
	else
    		selfSay('You have buy a maximum of 100 items at a time.', cid) talk_step = 1
	end
return true
end
function onSell(cid, item, amount, price)
	if amount <= 100 then
		if doPlayerRemoveItem(cid, item, amount) then
			doPlayerAddMoney(cid, price) 
			selfSay('Here is '..price..' Gold Coins.', cid) talk_step = 1
		else
    			selfSay('Sorry, but you no have '..amount..' '..getItemNameById(item)..' for sell!', cid) talk_step = 1
		end
	else
    		selfSay('You have to sell a maximum of 100 items at a time.', cid) talk_step = 1
	end
return true
end
function onCreatureSay(cid, type, msg)
local cid_Say = msg:lower()
  if ((cid_Say == "hi") and not (isFocused(cid, focuses))) then
       selfSay("Hello, "..getCreatureName(cid).."! what you want for me? I'm selling and buying some itens...", cid)
       addFocus(cid, focuses)
       selfFocus(cid)
       talk_step = 1
  elseif talk_step == 1 and cid_Say == "bye" then
    	selfSay('bye '..getCreatureName(cid)..'!', cid)
	removeFocus(cid, focuses) 
  elseif talk_step == 1 then
local t,ret = {},0
for var in string.gmatch(cid_Say, "[^%s]+") do
 ret = ret +1
  if ret < 3 then
   table.insert(t, var)
     else
  t[3] = (t[3] == nil and var or t[3].. " "..var)
 end
end 
if not isInArray({"buy", "sell"}, t[1])  then
   selfSay('just buy and sell items, be right!', cid) return true
end
notSellOrBuy = false
           for var, ret in pairs(shop) do
                for _, check in pairs(var) do
                    if t[3] == check then
                        type,pos,name = ret.type,ret.pos,ret.name
			itemid, amount, tipo = ret.id, tonumber(t[2]), t[1]
			price = (t[1] == "buy" and ret.buy*amount or ret.sell*amount)
				if t[1] == "sell" and ret.sell == 0 then
       					return selfSay('Sorry, I do not want to buy this item at the moment!', cid)
				elseif  t[1] == "buy" and ret.buy == 0 then
       					return selfSay('Sorry, I do not want sell this item at the moment!', cid)
				elseif  not tonumber(t[2]) then
       					return selfSay('say amount!! ex: buy 2 axes.', cid)
				end
				selfSay('You want to '..(t[1] == 'buy' and 'buy' or 'sell')..' '..amount..' '..t[3]..' for '..price..' Gold Coins?.', cid)
				talk_step = 2
				notSellOrBuy = true
				break
                    end
                end
            end
if not notSellOrBuy then
       selfSay('Sorry, I do not buy or sell this item.', cid) 
end
elseif talk_step == 2 and cid_Say == "yes" then
	if tipo == 'buy' then
		onBuy(cid, itemid, amount, price)
	else
		onSell(cid, itemid, amount, price)
	end
elseif talk_step == 2 and cid_Say == "no" then
	selfSay('Then ok... Bye!', cid)
	removeFocus(cid, focuses)
	talk_step = 0
end
return true
end
function onThink()
for _, focus in pairs(focuses) do
    if not isCreature(focus) then
     removeFocus(focus, focuses)
         talk_step = 0
    else
     local distance = getDistanceTo(focus) or 5
        if distance > 4 then
            selfSay("Hmpf!", focus)
            removeFocus(focus, focuses)
              talk_step = 0
        end
    end
end
setFocus(focuses)
end

 

vodkart_logo.png

[*Ninguém será digno do sucesso se não usar suas derrotas para conquistá-lo.*]

 

DISCORDvodkart#6090

 

Postado
  • Autor
20 horas atrás, Vodkart disse:

e seu servidor é 8.60?

 

pra fzr um npc desse vai precisar de uma gambiarrinha kk

 

 

MemeCenter_1453764771394_433.jpg

 

 

-------------------------------------------------------------------------------------

 

data > npc > lib

 

crie um arquivo.lua e renomei para

 

 npc-func.lua


local focuses = {}
function isFocused(cid, t)
for i, v in pairs(t) do
    if(v == cid) then
        return true
    end
end
return false
end

function addFocus(cid, t)
if(not isFocused(cid, t)) then
    table.insert(t, cid)
end
end

function setFocus(t)
for i, v in pairs(t) do
    if(isPlayer(v)) then
        doNpcSetCreatureFocus(v)
        return
    end
end
doNpcSetCreatureFocus(0)
end

function removeFocus(cid, t)
for i, v in pairs(t) do
    if(v == cid) then
        table.remove(t, i)
        setFocus(focuses)
        break
    end
end
end

function onCreatureDisappear(cid)
if isFocused(cid, focuses) then
 removeFocus(cid, focuses)
    if isPlayer(cid) then
     closeShopWindow(cid)
    end
end
end

 

 

 

--------------------------

 

data > npc

 

nome do seu npc.xml


<?xml version="1.0" encoding="UTF-8"?>
<npc name="nome do seu npc" script="oldbuyer.lua" walkinterval="5000" floorchange="0">
<health now="100" max="100"/>
<look type="133" head="114" body="119" legs="132" feet="114"/>
</npc>

 

 

data > npc > scripts

 

oldbuyer.lua


dofile("data/npc/lib/npc-func.lua")
local focuses = {} -- do not change

local shop = {
[{"axe", "axes"}] = {id=2386, buy = 20 , sell= 8}, -- id do item, por quanto ele vai comprar e por quanto ele vai vender, se colocar 0 ele n vende ou se colocar 0 nao compra o item
[{"club", "clubs"}] = {id=2382, buy = 20 , sell= 8},
[{"broadsword", "broadswords"}] =  {id=2413, buy = 100 , sell= 0},
[{"mastermind shield","mastermind shields"}] =  {id=2514, buy = 50000 , sell= 30000},
[{"demon backpack","demon backpacks"}] =  {id=10518, buy = 10000 , sell= 5000},
[{"scarab coin","scarab coins"}] =  {id=2159, buy = 50 , sell= 30}
}

function onBuy(cid, item, amount, price)
	if amount <= 100 then
		if doPlayerRemoveMoney(cid, price) then
			if isItemStackable(item) or amount == 1 then
				doPlayerAddItem(cid, item, amount)
			else
				for i = 1, amount do
					doPlayerAddItem(cid, item, 1)
				end
			end
		selfSay('Here your item(s)!', cid) talk_step = 1
		else
    		selfSay('You need '..price..' Gold Coins!', cid) talk_step = 1
		end
	else
    		selfSay('You have buy a maximum of 100 items at a time.', cid) talk_step = 1
	end
return true
end
function onSell(cid, item, amount, price)
	if amount <= 100 then
		if doPlayerRemoveItem(cid, item, amount) then
			doPlayerAddMoney(cid, price) 
			selfSay('Here is '..price..' Gold Coins.', cid) talk_step = 1
		else
    			selfSay('Sorry, but you no have '..amount..' '..getItemNameById(item)..' for sell!', cid) talk_step = 1
		end
	else
    		selfSay('You have to sell a maximum of 100 items at a time.', cid) talk_step = 1
	end
return true
end
function onCreatureSay(cid, type, msg)
local cid_Say = msg:lower()
  if ((cid_Say == "hi") and not (isFocused(cid, focuses))) then
       selfSay("Hello, "..getCreatureName(cid).."! what you want for me? I'm selling and buying some itens...", cid)
       addFocus(cid, focuses)
       selfFocus(cid)
       talk_step = 1
  elseif talk_step == 1 and cid_Say == "bye" then
    	selfSay('bye '..getCreatureName(cid)..'!', cid)
	removeFocus(cid, focuses) 
  elseif talk_step == 1 then
local t,ret = {},0
for var in string.gmatch(cid_Say, "[^%s]+") do
 ret = ret +1
  if ret < 3 then
   table.insert(t, var)
     else
  t[3] = (t[3] == nil and var or t[3].. " "..var)
 end
end 
if not isInArray({"buy", "sell"}, t[1])  then
   selfSay('just buy and sell items, be right!', cid) return true
end
notSellOrBuy = false
           for var, ret in pairs(shop) do
                for _, check in pairs(var) do
                    if t[3] == check then
                        type,pos,name = ret.type,ret.pos,ret.name
			itemid, amount, tipo = ret.id, tonumber(t[2]), t[1]
			price = (t[1] == "buy" and ret.buy*amount or ret.sell*amount)
				if t[1] == "sell" and ret.sell == 0 then
       					return selfSay('Sorry, I do not want to buy this item at the moment!', cid)
				elseif  t[1] == "buy" and ret.buy == 0 then
       					return selfSay('Sorry, I do not want sell this item at the moment!', cid)
				elseif  not tonumber(t[2]) then
       					return selfSay('say amount!! ex: buy 2 axes.', cid)
				end
				selfSay('You want to '..(t[1] == 'buy' and 'buy' or 'sell')..' '..amount..' '..t[3]..' for '..price..' Gold Coins?.', cid)
				talk_step = 2
				notSellOrBuy = true
				break
                    end
                end
            end
if not notSellOrBuy then
       selfSay('Sorry, I do not buy or sell this item.', cid) 
end
elseif talk_step == 2 and cid_Say == "yes" then
	if tipo == 'buy' then
		onBuy(cid, itemid, amount, price)
	else
		onSell(cid, itemid, amount, price)
	end
elseif talk_step == 2 and cid_Say == "no" then
	selfSay('Then ok... Bye!', cid)
	removeFocus(cid, focuses)
	talk_step = 0
end
return true
end
function onThink()
for _, focus in pairs(focuses) do
    if not isCreature(focus) then
     removeFocus(focus, focuses)
         talk_step = 0
    else
     local distance = getDistanceTo(focus) or 5
        if distance > 4 then
            selfSay("Hmpf!", focus)
            removeFocus(focus, focuses)
              talk_step = 0
        end
    end
end
setFocus(focuses)
end

 

caara, muito obrigado pela atenção, mas não funcionou. Eu tive alguns erros tentando de várias maneiras. Exemplos:

 

1: Obi.xml - Diretório: data/npc

image.png.10ee52fdf26c56003ec3cdca2421e577.png

2: oldbuyer.lua - Diretório: data/npc/scripts

image.png.345cc9dac8ba6174484064a3b1038d38.png

3: npcold.lua

 image.png.b36c7f674a3b5895ee37fa074994b932.png

4: Erro

image.png.be43e4ad39a29ccf68b8a5c3b703201d.png

 

------

 

Então decidi fazer uma mudança no .xml, qual? Decidi usar o meu NPC original mudando apenas o Script:

 

1: Obi.xml

image.thumb.png.46fbc7cca560d111a98140fe6f207985.png

2: Erro

image.png.f099d89730eee4c639dabb38cdc266b4.png

 

 

Cê sabe o que pode ser?

 

Postado

@TibiaParadise

 

funciona sim, eu testei aqui... Acontece que o box code do fórum buga o script

 

sobre editar o NPC XML, ele não vai responder como você colocou.

 

usa assim:

 

 

Obi.xml

https://pastebin.com/raw/PKfAhjxU

 

e o script:

 

oldbuyer.lua

https://pastebin.com/raw/jMraP6nW

 

 

------------------------------------------------------------

 

ssdsdsds.jpg

------------------------------------------------------------

 

o que é o npcold.lua ? nem postei isso.

 

 

edit -- vc trocou o nome do arquivo, entendi. enfim, usa os arquivos que te passei no pastebin

vodkart_logo.png

[*Ninguém será digno do sucesso se não usar suas derrotas para conquistá-lo.*]

 

DISCORDvodkart#6090

 

Participe da conversa

Você pode postar agora e se cadastrar mais tarde. Se você tem uma conta, faça o login para postar com sua conta.

Visitante
Responder

Quem Está Navegando 0

  • Nenhum usuário registrado visualizando esta página.

Conteúdo Similar

Estatísticas dos Fóruns

  • Tópicos 96.9k
  • Posts 519.6k

Informação Importante

Confirmação de Termo