Jump to content
  • 0

[Resolvido] [PEDIDO] Npc que troca 3 itens por X item


HenrikDiamond

Question

Olá galera do xtibia, o titulo ja explica bem o meu pedido e é assim:

 

Estou reconstruindo meu server pokezot, e quero que os players que tiverem as penas dos 3 lendarios poderao trocar por outro item para pegar a recompensa!

--So quero o npc q troque os itens.

 

IDS:

 

 

Penas a serem trocadas:

12149

12150

12151

Item que será recebido em troca das penas:

2200

 

 

 

Espero que possam me ajudar vlw ;)

Link to comment
Share on other sites

12 answers to this question

Recommended Posts

  • 0

hmn achei esse em outro forum acho que é oque você quer:

 

 

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end

function playerHaveItems(cid, itemid)
local items = type(itemid) == "table" and itemid or {itemid}
for i = 1, #items do
if getPlayerItemCount(cid, items) <= 0 then
return false
end
end
return true
end

function doPlayerRemoveItems(cid, itemid, count)
local items = type(itemid) == "table" and itemid or {itemid}
for i = 1, #items do
doPlayerRemoveItem(cid, items, count ~= nil and count or 1)
end
return nil
end

function creatureSayCallback(cid, type, msg)

if(not npcHandler:isFocused(cid)) then
return false
end

if msgcontains(msg, "trocar") then
if playerHaveItems(cid, {12149, 12150, 12151}) then
doPlayerRemoveItems(cid, {12149, 12150, 12151}, 300)
doPlayerAddItem(cid, 2200, 1)
else
selfSay("Você Não tem os itens necessarios.")
end
end
return true

endnpcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

 

 

Agora vá em Data/Npc/Nomedonpc.xml

 

<?xml version="1.0" encoding="UTF-8"?>
<npc name="Nomedonpc" script="trocaitems.lua" walkinterval="2000" floorchange="0">
<health now="100" max="100"/>
<look type="169" head="114" body="86" legs="114" feet="0" addons="2"/>
<parameters>
<parameter key="message_greet" value="Ola, diga {trocar} para trocar 3 items por 1."/>
</parameters>
</npc>

Edited by LioNsZ
Link to comment
Share on other sites

  • 0

Ola amigo tava procurando aqui no Xtibia e achei um olha

 

Vai em data/npc e crie um arquivo.xml, nomeia ele como você quiser, depois você cola isso dentro dele:

 

<?xml version="1.0" encoding="UTF-8"?>

<npc name="Nome do Npc" script="nome_do_arquivo.lua" walkinterval="2000" floorchange="0">
<health now="100" max="100"/>
<look type="300" head="0" body="0" legs="0" feet="0" corpse="5995"/>
<parameters>
<parameter key="message_greet" value="Hello |PLAYERNAME|! Do you want to do some {trading}?"/>
</parameters>
</npc>
  • Pronto, feito isso vai em data/npc/script, e cria um arquivo .luaé so copiar um arquivo existente e renomear, depois você cola isso dentro:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
local talkUser = NPCHANDLER_CONVbehavior == CONVERSATION_DEFAULT and 0 or cid
local shopWindow = {}
local moeda = 2200
local t = {
[12149] = {price = 1}, -- Nome do Item
[12150] = {price = 1}, -- Nome do Item
[12151] = {price = 1}, -- Nome do Item
}
local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks)
if t[item] and not doPlayerRemoveItem(cid, moeda, t[item].price) then
selfSay("Desculpe, mas voce nao tem "..t[item].price.." "..getItemNameById(moeda), cid)
else
doPlayerAddItem(cid, item)
selfSay("aqui esta seu item!", cid)
end
return true
end
if (msgcontains(msg, 'trade') or msgcontains(msg, 'TRADE'))then
for var, ret in pairs(t) do
table.insert(shopWindow, {id = var, subType = 0, buy = ret.price, sell = 0, name = getItemNameById(var)})
end
openShopWindow(cid, shopWindow, onBuy, onSell)
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Te ajudei rap ++
Edited by LioNsZ
Link to comment
Share on other sites

  • 0

Vou testar aqui ! ;)

 

 

---@Edit

 

teste aqui e nao deu certo.

O npc que você passou vende as penas.

Quero um npc q troque as penas pelo item 2200!

 

---Edit 2 ¬¬

 

Nem tinha comprado, e vi uma coisa.

 

O script é o contrario do q eu quero.

ele vende as penas pelo item 2200!

Ainda n foi resolvido

Edited by HenrikDiamond
Link to comment
Share on other sites

  • 0

Cara, ta sendo ao contrario ainda...

o NPC tem q trocar as 3 penas (12149,12150,12151) pelo protection amulet (2200)

 

esse ai troca o protection amulet por penas '-'

 

 

 

---E mesmo se eu editar o script, vai trocar as 3 penas por 3 protection amulets e eu quero so 1 em troca das 3!!

Edited by HenrikDiamond
Link to comment
Share on other sites

  • 0

prontinho:

.lua

 

 

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
if getPlayerItemCount(cid, 12149) and getPlayerItemCount(cid, 12150) and getPlayerItemCount(cid, 12151) < 1 then
doPlayerPopupFYI(cid, "Esta faltando algum item para pegar sua recompensa")
return true
end
if getPlayerItemCount(cid, 12149) and getPlayerItemCount(cid, 12150) and getPlayerItemCount(cid, 12151) > 1 then -- troca recompensa para o que o player terá que dizer para pegar as penas.
doPlayerRemoveItem(cid, 12149, 1)
doPlayerRemoveItem(cid, 12150, 1)
doPlayerRemoveItem(cid, 12151, 1)
doPlayerAddItem(cid, 2200, 1)
doPlayerPopupFYI(cid, "Voce ganhou um "..getItemNameById(2200)..".")
return true
end
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

.xml

<?xml version="1.0" encoding="UTF-8"?>
<npc name="Lendarios" script="lendarios.lua" walkinterval="0" floorchange="0" access="5" level="1" maglevel="1">
<health now="150" max="150"/>
<look type="606" head="86" body="86" legs="86" feet="86" addons="3"/>
<parameters>
<parameter key="message_greet" value="Olá"/>
</parameters>
</npc>

 

 

Link to comment
Share on other sites

  • 0

Sim Zipter

 

 

 

 

---Erro no seu Npc xml homer

 

[01/05/2014 14:11:15] [Error - Npc interface]
[01/05/2014 14:11:15] (Unknown script file)
[01/05/2014 14:11:15] Description:
[01/05/2014 14:11:15] Stack size changed!
[01/05/2014 14:11:21] [Warning - Npc::loadFromXml] Cannot load npc file (data/npc/granger.xml).
[01/05/2014 14:11:21] Line: 8, Info: Input is not proper UTF-8, indicate encoding !
[01/05/2014 14:11:21] Bytes: 0xE1 0x22 0x2F 0x3E

 

Ta dando erro na mensagem me parece..

 

 

<?xml version="1.0" encoding="UTF-8"?>

<npc name="Granger" script="granger.lua" walkinterval="0" floorchange="0" access="5" level="1" maglevel="1">
<health now="150" max="150"/>
<look type="606" head="86" body="86" legs="86" feet="86" addons="3"/>

<parameters>
<parameter key="message_greet" value="Olá"/>
</parameters>
</npc>

 

 

Edited by HenrikDiamond
Link to comment
Share on other sites

  • 0


local keywordHandler = KeywordHandler:new()

local npcHandler = NpcHandler:new(keywordHandler)

NpcSystem.parseParameters(npcHandler)

local talkState = {}

function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end

function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end

function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end

function onThink() npcHandler:onThink() end

function creatureSayCallback(cid, type, msg)

if(not npcHandler:isFocused(cid)) then

return false

end

local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

local ids = {{12149, 12150, 12151}, 2200}

local feathers = ids[1]

local str = ""

local check = 0

local storage = 91821

if msgcontains(msg:lower(), "trade") or msgcontains(msg:lower(), "troca") then

for i = 1, #feathers do

if str == "" then

str = "1 "..getItemNameById(feathers)

else

str = str..", 1 "..getItemNameById(feathers)

end

end

if getPlayerStorageValue(cid, storage) > -1 then

selfSay("You already traded with me.", cid)

talkState[talkUser] = 0

return true

else

selfSay("Do you want trade "..str.." for 1 "..getItemNameById(ids[2]).."?", cid)

talkState[talkUser] = 1

return true

end

elseif msgcontains(msg:lower(), "yes") and talkState[talkUser] == 1 then

for i = 1, #feathers do

if getPlayerItemCount(cid, feathers) > 0 then

check = check + 1

end

end

if check == #feathers then

selfSay("Thank you!", cid)

for i = 1, #feathers do

doPlayerRemoveItem(cid, feathers, 1)

end

doPlayerAddItem(cid, ids[2], 1)

setPlayerStorageValue(cid, storage, 1)

talkState[talkUser] = 0

return true

else

selfSay("Hey, you don't have all the feathers.", cid)

talkState[talkUser] = 0

return true

end

elseif msgcontains(msg:lower(), "no") and talkState[talkUser] == 1 then

selfSay("Ok, good bye!")

talkState[talkUser] = 0

return true

end

return true

end

 

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

npcHandler:addModule(FocusModule:new())

 

Edited by zipter98
Link to comment
Share on other sites

  • 0
  • Administrador
A questão neste tópico de suporte foi respondida e/ou o autor do tópico resolveu o problema. Este tópico está fechado e foi movido para Suporte - Resolvidos. Se você tiver outras dúvidas, crie um novo tópico.
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...