Ir para conteúdo

Npc Que Troca Itens Por Outros Itens


BravHart

Posts Recomendados

É o seguinte eu estou com um NPC aqui mais nao funciona direito .. .

 

Eu quero um npc chamado Gin Bester que troque:

100 demonic essence

100 soul orb

50 giant spider silk

50 vampire dust

20 ankh

Por:

1 demon backpack

100 crystal coins (1kk)

 

__

• Somente irá a recompensa se tiver os itens pedido acima, caso não tenha não pegue a recompensa.

Eu tenho esse script aqui, mais parece que não da certo ... vê se ajuda vocês ..

 

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

 

local shopModule = ShopModule:new()

npcHandler:addModule(shopModule)

 

function creatureSayCallback(cid, type, msg)

if(not npcHandler:isFocused(cid)) then

return false

end

if msgcontains(msg, 'help') then

selfSay('You can here change some items for mission.')

 

elseif msgcontains(msg, 'mission') then

if getPlayerItemCount(cid,5944) >= 100 and getPlayerItemCount(cid,6500) >= 100 and

 

getPlayerItemCount(cid,5905) >= 50 and getPlayerItemCount(cid,5879) >= 50 and getPlayerItemCount(cid,2193)

 

>= 5 then

selfSay('Did you bring me the 100 soul orb, 100 demonic essence, 50 giant spider silk, 50 vampire dust and 5 ankh?')

talk_state = 15

else

selfSay('I need 100 soul orb, 100 demonic essence, 50 giant spider silk, 50 vampire dust and 5 ankh to give you the

 

recompesation. Come back when you have them.')

talk_state = 0

end

elseif msgcontains(msg, 'yes') and talk_state == 1 then

talk_state = 0

if getPlayerItemCount(cid,5944) >= 100 and getPlayerItemCount(cid,6500) >= 100 and

 

getPlayerItemCount(cid,5905) >= 50 and getPlayerItemCount(cid,5879) >= 50 and getPlayerItemCount(cid,2193)

 

>= 5 then

if doPlayerRemoveItem(cid,5944,100) == 1 and doPlayerRemoveItem(cid,6500,100) == 1 and

 

doPlayerRemoveItem(cid,5905,50) == 1 and doPlayerRemoveItem(cid,5879,50) == 1 and

 

doPlayerRemoveItem(cid,2193,5) == 1 then

doPlayerAddItem(cid,2160,100)

doPlayerAddItem(cid,10518,1)

else

end

 

elseif msgcontains(msg, 'no') and (talk_state >= 1 and talk_state <= 5) then

selfSay('Ok than.')

talk_state = 0

end

-- Place all your code in here. Remember that hi, bye and all that stuff is already handled by the npcsystem, so you

 

do not have to take care of that yourself.

return true

end

 

end

 

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

npcHandler:addModule(FocusModule:new())

 

Desde Já, Agradeço !!

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

Testa ai:

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

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 shopModule = ShopModule:new()
npcHandler:addModule(shopModule)

local items = {
{5944, 100}, {6500, 100}, {5905, 50}, {5879, 50}, {2193, 20}
}

function item(cid, func)
if func == "count" then
	for i=1, #items do
		if getPlayerItemCount(cid, items[i][1]) >= items[i][2] == FALSE then
			return FALSE
		end
	end
elseif func == "remove" then
	for i=1, #items do
		if doPlayerRemoveItem(cid, items[i][1], items[i][2]) == FALSE then
			return FALSE
		end
	end
end

return TRUE
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, 'help') then
	selfSay('You can here change some items for mission.', cid)
elseif msgcontains(msg, 'mission') then
	if item(cid, "count") then
		selfSay('Did you bring me the 100 soul orb, 100 demonic essence, 50 giant spider silk, 50 vampire dust and 20 ankh?', cid)
		talk_state[talkUser] = 1
	else
		selfSay('I need 100 soul orb, 100 demonic essence, 50 giant spider silk, 50 vampire dust and 20 ankh to give you the recompesation. Come back when you have them.', cid)
		talk_state[talkUser] = 0
	end
elseif msgcontains(msg, 'yes') and talk_state[talkUser] == 1 then
	if item(cid, "remove") then
		doPlayerAddItem(cid,2160,100)
		doPlayerAddItem(cid,10518,1)
	end
	talk_state[talkUser] = 0
elseif msgcontains(msg, 'no') and talk_state[talkUser] == 1 then
	selfSay('Ok than.', cid)
	talk_state[talkUser] = 0
end
return true
end

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

 

*Tive q arrumar algumas coisas.

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

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