Ir para conteúdo

Npc Não Faz A Troca De Itens !


MUTAN0

Posts Recomendados

Olá a todos.

Este NPC tem a função de recarregar a Soft Boots, e trocar o Soul Orb e mais 5k do player por 10 infernal bolts.

Mas o problema é que ele só ta recarregando a Soft Boots, mas não ta fazendo a troca das bolts.

Quando você fala INFERNAL BOLT ele não responde nada.

 

Script:

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

 

if(msgcontains(msg, 'soft boots')) then

selfSay('Do you want to repair your worn soft boots for 10000 gold coins?', cid)

talkState[talkUser] = 1

elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then

if(getPlayerItemCount(cid, 6530) >= 1) then

if(doPlayerRemoveMoney(cid, 10000) == TRUE) then

local item = getPlayerItemById(cid, TRUE, 6530)

doTransformItem(item.uid, 2640)

selfSay('Here you are.', cid)

else

selfSay('Sorry, you don\'t have enough gold.', cid)

end

else

selfSay('Sorry, you don\'t have the item.', cid)

end

talkState[talkUser] = 0

 

if(msgcontains(msg, 'infernal bolt')) then

selfSay('Want to change a Soul Orb and 5000 gold coins by 10 Infernal Bolts?', cid)

talkState[talkUser] = 1

elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then

if(getPlayerItemCount(cid, 5944) >= 1) then

if(doPlayerRemoveMoney(cid, 5000) == TRUE) then

local item = getPlayerItemById(cid, TRUE, 5944)

doTransformItem(item.uid, 6529, 10)

selfSay('Here you are.', cid)

else

selfSay('Sorry, you don\'t have enough gold.', cid)

end

else

selfSay('Sorry, you don\'t have the item.', cid)

end

talkState[talkUser] = 0

 

elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser]) == TRUE) then

talkState[talkUser] = 0

selfSay('Ok then.', cid)

end

 

return true

end

end

 

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

npcHandler:addModule(FocusModule:new())

 

Obrigado.

Abraços :blush:

Link para o comentário
Compartilhar em outros sites

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

if(msgcontains(msg, 'soft boots')) then
selfSay('Do you want to repair your worn soft boots for 10000 gold coins?', cid)
talkState[talkUser] = 1
if(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
if(getPlayerItemCount(cid, 6530) >= 1) then
if(doPlayerRemoveMoney(cid, 10000) == TRUE) then
local item = getPlayerItemById(cid, TRUE, 6530)
doTransformItem(item.uid, 2640)
selfSay('Here you are.', cid)
else
selfSay('Sorry, you don\'t have enough gold.', cid)
end
else
selfSay('Sorry, you don\'t have the item.', cid)
end
elseif(msgcontains(msg, 'no') and and talkState[talkUser] == 1) then
talkState[talkUser] = 0
selfSay('Ok then.', cid)
end
talkState[talkUser] = 0

if(msgcontains(msg, 'infernal bolt')) then
selfSay('Want to change a Soul Orb and 5000 gold coins by 10 Infernal Bolts?', cid)
talkState[talkUser] = 1
if(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
if(getPlayerItemCount(cid, 5944) >= 1) then
if(doPlayerRemoveMoney(cid, 5000) == TRUE) then
local item = getPlayerItemById(cid, TRUE, 5944)
doTransformItem(item.uid, 6529, 10)
selfSay('Here you are.', cid)
else
selfSay('Sorry, you don\'t have enough gold.', cid)
end
else
selfSay('Sorry, you don\'t have the item.', cid)
end
elseif(msgcontains(msg, 'no') and and talkState[talkUser] == 1) then
talkState[talkUser] = 0
selfSay('Ok then.', cid)
end
talkState[talkUser] = 0

return true
end
end

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

 

Tenta esse acima.

 

Ele estava com uns erros de IF.

 

;D

Editado por lucasjockey
Link para o comentário
Compartilhar em outros sites

Nao deu certo nao :p

Tirando ainda que você boteu algumas linhas com 2 'and', e faltou um 'end' no final.

Eu concertei isso, mas dai, mesmo assim, nao mudo nada no NPC.

Mas obrigado pela tentativa :}

Link para o comentário
Compartilhar em outros sites

tenta o meuuu o/

=P

 

local phrases = {
"Hello, |PLAYERNAME|! It's a pretty sunny day, no?",
"How rude!",
"Wait! I'm talking.",
"Farewell, |PLAYERNAME|...",
noGold="Sorry, you don't have enough gold.",
noItem="Sorry, you don't have the item.",
tradeOk="It's done.",
no="Changed your mind, uh?!",
trade={"Do you want to trade","by","at cost of","gps?"}
}

local exchanges = {
{takeId=6530, takeCount=1, giveId=2640, giveCount=1, cost=10000, keywords={'soft boots'}}
{takeId=5944, takeCount=1, giveId=6529, giveCount=10, cost=5000, keywords={'infernal bolts'}}
}

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

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

local setMessages = {1,16,22,2}
for i = 1,4 do npcHandler:setMessage(setMessages[i],phrases[i])

local function itemExchange(cid, message, keywords, parameters, node)
  local exchange = exchanges[parameters.action]
  if (not npcHandler:isFocused(cid)) then return false end
  if (doPlayerTakeItem(cid, exchange.takeId, exchange.takeCount) > 0) then
  if (doPlayerRemoveMoney(cid, exchange.cost)) > 0) then
	 doPlayerAddItem(cid, exchange.giveItem, exchange.giveCount)
	 npcHandler:say(phrases.tradeOk,cid)
  else npcHandler:say(phrases.noGold,cid) end
  else npcHandler:say(phrases.noItem,cid) end
  keywordHandler:moveUp(1)
  return TRUE
end

for i = 1, #exchanges do
  local exchange = exchanges[i]
  for a = 1, #exchange.keywords do
  local say = phrases.trade
  say = say[1]..' '..getItemName(exchange.takeId)..' '..say[2]..' '..getItemName(exchange.giveId)..' '..say[3]..' '..exchange.cost..' '..say[4]
  local node=keywordHandler:addKeyword({exchange.keywords[a]}, StdModule.say, {npcHandler=npcHandler, onlyFocus=true, text=say})
  node:addChildKeyword({'yes'}, itemExchange, {action = i})
  node:addChildKeyword({'no'}, StdModule.say, {npcHandler=npcHandler, onlyFocus=true, moveup=1, text=phrases.no})
  end
end

npcHandler:addModule(FocusModule:new())

Link para o comentário
Compartilhar em outros sites

Brainless, seu NPC deu um erro:

[Warning - NpcScript::NpcScript] Can not load script: data/npc/scripts/bootmaker

.lua

data/npc/scripts/bootmaker.lua:15: '}' expected (to close '{' at line 13) near '

{'

Mas...mesmo assim valeu a ajuda.

Agora de tanto mecher nele consegui um jeito de funcionar :party:

Olha como ficou:

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 money = getPlayerItemCount(cid,5944)

 

 

if(msgcontains(msg, 'soft boots') or msgcontains(msg, 'worn soft boots')) then

selfSay('Do you want to repair your worn soft boots for 10000 gold coins?', cid)

talkState[talkUser] = 1

elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then

if(getPlayerItemCount(cid, 6530) >= 1) then

if(doPlayerRemoveMoney(cid, 10000) == TRUE) then

local item = getPlayerItemById(cid, TRUE, 6530)

doTransformItem(item.uid, 6132)

selfSay('Here you are.', cid)

else

selfSay('Sorry, you don\'t have enough gold.', cid)

end

else

selfSay('Sorry, you don\'t have the item.', cid)

end

end

 

if(msgcontains(msg, 'infernal bolt') or msgcontains(msg, 'infernal bolts')) then

selfSay('Want to get 10 infernal bolts for a Soul Orb??', cid)

talkState[talkUser] = 2

elseif msgcontains(msg, 'yes') and talkState[talkUser] == 2 then

if money >= 1 then

doPlayerRemoveItem(cid, 5944, 1)

doPlayerAddItem(cid, 6529, 10)

else

selfSay('You don\'t have the item', cid)

end

 

end

 

return true

end

 

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

npcHandler:addModule(FocusModule:new())

 

Agora sim :thumbsupsmiley2:

Vou reportar como duvida sanada.

Valeu.

Editado por MUTAN0
Link para o comentário
Compartilhar em outros sites

Visitante
Este tópico está impedido de receber novos posts.
×
×
  • Criar Novo...