Ir para conteúdo

Posts Recomendados

Olá pessoal, venho hoje pedir ajuda de alguem que saiba mecher com NPCs.

O negocio é o seguinte, eu fiz uma quest da blood herb, igual Tibia global onde você abre uma arvore seca.

Beleza...Então eu queria o seguinte, a quest usa o storage 10044 no player.

Dai o player falaria com o NPC, sobre o blood herb que então daria um outro storage pro player, que com esse storage ele abriria a arvore seca.

O player então levaria a blood herb ao NPC, que pegaria a erva e daria uma recompensa.

E também o player só poderia dar a erva pro NPC uma só vez.

 

A conversa com o NPC seria assim:

 

Hi

Hello nice person, I can help you with something?

blood herb

Ah, you would be able to get a Blood Herb on dry flies?

yes

Go to get back here and let me know.

 

Então o player vai e faz a quest.

O script por enquanto ta assim, só falta botar alguma coisa pra checar se ele ja falou com o NPC antes, caso contrario apareceria "Sorry, not possible." (coisa que eu ainda não fiz):

function onUse(cid, item, frompos, item2, topos)

 

if item.uid == 10044 then

queststatus = getPlayerStorageValue(cid,10044)

if queststatus == -1 then

doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR,"You have found a blood herb.")

doPlayerAddItem(cid,2798,1)

setPlayerStorageValue(cid,10044,1)

else

doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR,"It is empty.")

end

else

return 0

end

 

return 1

end

Ao fazer, ele volta com a planta Blood Herb:

hi

Hello nice person, I can help you with something?

blood herb

You got an herb for me?

yes

*remove a blood herb.

*dá recompensa.

Thank you, take this as a reward for work.

 

É isso, só preciso da ajuda de alguem ai para me ajudar nisso :)

Depois posso estar botando essa quest aqui no forum, e darei com certeza os créditos á quem vir a ajudar.

Obrigado.

Link para o comentário
https://xtibia.com/forum/topic/107171-fazendo-uma-quest-com-npc/
Compartilhar em outros sites

Ficaria assim:

Script Da planta:

function onUse(cid, item, frompos, item2, topos)

if item.uid == 10044 then
queststatus = getPlayerStorageValue(cid,10044)
npcconv = getPlayerStorageValue(cid,10045)
if npcconv == 1 then
	if queststatus == -1 then
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR,"You have found a blood herb.")
		doPlayerAddItem(cid,2798,1)
		setPlayerStorageValue(cid,10044,1)
	else
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR,"It is empty.")
	end 
else
	doPlayerSendCancel(uid,"Sorry, not possible.")
end	
else
return 0
end

return 1
end

 

Script do NPC:

local focus = 0
local talk_start = 0
local talk_state = 0
local target = 0
local following = false
local attacking = false

function onThingMove(creature, thing, oldpos, oldstackpos)

end


function onCreatureAppear(creature)

end


function onCreatureDisappear(cid, pos)
  if focus == cid then
	  selfSay('Good bye then.')
	  focus = 0
	  talk_start = 0
  end
end


function onCreatureTurn(creature)

end

function msgcontains(txt, str)
  return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)'))
end


function onCreatureSay(cid, type, msg)
  msg = string.lower(msg)

  if (msgcontains(msg, 'hi') and focus == 0) and getDistanceToCreature(cid) < 4 then
	  selfSay('Hello nice person, I can help you with something?')
	  focus = cid
	  talk_start = os.clock()

  elseif msgcontains(msg, 'hi') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then
	  selfSay('Sorry, ' .. creatureGetName(cid) .. '! I talk to you in a minute.')

  elseif focus == cid then
	talk_start = os.clock()
	status = getPlayerStorageValue(cid,10045)
	if msgcontains(msg, 'blood herb') then
		if status == -1 then
			selfSay('Ah, you would be able to get a Blood Herb on dry flies?')	
			talk_state = 1
		elseif status == 1 then
			selfSay('You got an herb for me?')	
			talk_state = 2
		elseif status == 2 then
			selfSay('You can\'t do this quest again. Good Bye Then.')	
			talk_state = 0
			focus = 0
		end
	end
	if talk_state == 1 then
		if msgcontains(msg, 'yes') then
			selfSay('Go to get back here and let me know. Good Bye then.')
			setPlayerStorageValue(cid,10045,1)
			talk_state = 0
			focus = 0
		end
	elseif talk_state == 2 then	
		if msgcontains(msg, 'yes') then
			if getPlayerItemCount(cid,2798) >= 1 then
				doPlayerRemoveItem(cid,2798,1)
				selfSay('Thank you, take this as a reward for work. Good Bye Then.')	
				doPlayerAddItem(cid,ID_RECOMPENSA,QUANTIA)
				setPlayerStorageValue(cid,10045,2)
				talk_state = 0
				focus = 0
			else
				selfSay('You don\'t have the herb. Good Bye Then.')
				talk_state = 0
				focus = 0
			end	
		end	
	end
end


function onCreatureChangeOutfit(creature)

end


function onThink()
  if (os.clock() - talk_start) > 30 then
	  if focus > 0 then
		  selfSay('Next Please...')
	  end
		focus = 0
  end
	if focus ~= 0 then
		if getDistanceToCreature(focus) > 5 then
			selfSay('Good bye then.')
			focus = 0
		end
	end
end 


function onCreatureChangeOutfit(creature)

end


function onThink()
  if (os.clock() - talk_start) > 30 then
	  if focus > 0 then
		  selfSay('Next Please...')
	  end
		focus = 0
  end
	if focus ~= 0 then
		if getDistanceToCreature(focus) > 5 then
			selfSay('Good bye then.')
			focus = 0
		end
	end
end

 

Não textei, entao talvez tenha erro de sintaxe (end a menos, == em vez de =, etc), mas é 99% que funcione.

 

abraços

//skulls

Editado por Skulls
Link para o comentário
https://xtibia.com/forum/topic/107171-fazendo-uma-quest-com-npc/#findComment-692009
Compartilhar em outros sites

Deu um problema na quest, que eu arrumei;

function onUse(cid, item, frompos, item2, topos)

 

if item.uid == 10044 then

queststatus = getPlayerStorageValue(cid,10044)

npcconv = getPlayerStorageValue(cid,10045)

if npcconv == 1 then

if queststatus == -1 then

doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR,"You have found a blood herb.")

doPlayerAddItem(cid,2798,1)

setPlayerStorageValue(cid,10044,1)

else

doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR,"It is empty.")

end

else

doPlayerSendTextMessage(cid,22,"Sorry, not possible.")

end

else

return 0

end

 

return 1

end

 

E o NPC, quando eu falo HI ele não responde, e dá um erro no console:

Lua Script Error: [Npc interface]

data/npc/scripts/bloodherb.lua:onCreatureSay

 

data/npc/lib/npc.lua:44: attempt to perform arithmetic on global 'cx' (a table v

alue)

stack traceback:

data/npc/lib/npc.lua:44: in function 'getDistanceToCreature'

data/npc/scripts/bloodherb.lua:39: in function <data/npc/scripts/bloodhe

rb.lua:36>

 

O lib é assim:

-- Including the Advanced NPC System

dofile('data/npc/lib/creature.lua')

dofile('data/npc/lib/npcsystem/npcsystem.lua')

do

doPlayerAddStackable = doPlayerAddItem

--Returns table with UIDs of added items

doPlayerAddItem = function(cid, itemid, amount, subType, ignoreCap, inBackpacks)

local amount = amount or 1

local subType = subType or 0

local ignoreCap = ignoreCap and TRUE or FALSE

if(isItemStackable(itemid) == TRUE) then

return doPlayerAddStackable(cid, itemid, amount, ignoreCap), amount

end

local items = {}

local ret = 0

local a = 0

for i = 1, amount do

items = doCreateItemEx(itemid, subType)

ret = doPlayerAddItemEx(cid, items, ignoreCap)

if(ret ~= RETURNVALUE_NOERROR) then

break

end

a = a + 1

end

 

return items, a

end

end

function getDistanceToCreature(id)

if id == 0 or id == nil then

selfGotoIdle()

end

cx, cy, cz = getCreaturePosition(id)

if cx == nil then

return nil

end

sx, sy, sz = selfGetPosition()

return math.max(math.abs(sx - cx), math.abs(sy - cy))

end

function moveToPosition(x,y,z)

selfMoveTo(x, y, z)

end

function moveToCreature(id)

if id == 0 or id == nil then

selfGotoIdle()

end

tx, ty, tz = getCreaturePosition(id)

if tx == nil then

selfGotoIdle()

else

moveToPosition(tx, ty, tz)

end

end

 

function selfGotoIdle()

following = false

attacking = false

selfAttackCreature(0)

target = 0

end

function isPlayerPremiumCallback(cid)

return isPremium(cid) == TRUE and true or false

end

 

function msgcontains(message, keyword)

local a, b = string.find(string.lower(message), string.lower(keyword))

if a == nil or b == nil then

return false

end

return true

end

 

function selfSayChannel(cid, message)

return selfSay(message, cid, FALSE)

end

 

function doPosRemoveItem(_itemid, n, position)

local thing = getThingfromPos({x = position.x, y = position.y, z = position.z, stackpos = 1})

if thing.itemid == _itemid then

doRemoveItem(thing.uid, n)

else

return false

end

return true

end

 

Espero que saiba o que houve, mas desde já agradeço muito muito sua ajuda.

Abraços.

Link para o comentário
https://xtibia.com/forum/topic/107171-fazendo-uma-quest-com-npc/#findComment-692058
Compartilhar em outros sites

Fiz questao de testa... aqui deu certinho, so falto um end vo posta arrumado:

local focus = 0
local talk_start = 0
local talk_state = 0
local target = 0
local following = false
local attacking = false

function onThingMove(creature, thing, oldpos, oldstackpos)

end


function onCreatureAppear(creature)

end


function onCreatureDisappear(cid, pos)
  if focus == cid then
	  selfSay('Good bye then.')
	  focus = 0
	  talk_start = 0
  end
end


function onCreatureTurn(creature)

end

function msgcontains(txt, str)
  return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)'))
end


function onCreatureSay(cid, type, msg)
  msg = string.lower(msg)

  if (msgcontains(msg, 'hi') and focus == 0) and getDistanceToCreature(cid) < 4 then
	  selfSay('Hello nice person, I can help you with something?')
	  focus = cid
	  talk_start = os.clock()

  elseif msgcontains(msg, 'hi') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then
	  selfSay('Sorry, ' .. creatureGetName(cid) .. '! I talk to you in a minute.')

  elseif focus == cid then
	talk_start = os.clock()
	status = getPlayerStorageValue(cid,10045)
	if msgcontains(msg, 'blood herb') then
		if status == -1 then
			selfSay('Ah, you would be able to get a Blood Herb on dry flies?')	
			talk_state = 1
		elseif status == 1 then
			selfSay('You got an herb for me?')	
			talk_state = 2
		elseif status == 2 then
			selfSay('You can\'t do this quest again. Good Bye Then.')	
			talk_state = 0
			focus = 0
		end
	end
	if talk_state == 1 then
		if msgcontains(msg, 'yes') then
			selfSay('Go to get back here and let me know. Good Bye then.')
			setPlayerStorageValue(cid,10045,1)
			talk_state = 0
			focus = 0
		end
	elseif talk_state == 2 then	
		if msgcontains(msg, 'yes') then
			if getPlayerItemCount(cid,2798) >= 1 then
				doPlayerRemoveItem(cid,2798,1)
				selfSay('Thank you, take this as a reward for work. Good Bye Then.')	
				doPlayerAddItem(cid,ID_RECOMPENSA,QUANTIA)
				setPlayerStorageValue(cid,10045,2)
				talk_state = 0
				focus = 0
			else
				selfSay('You don\'t have the herb. Good Bye Then.')
				talk_state = 0
				focus = 0
			end	
		end	
	end
end
end


function onCreatureChangeOutfit(creature)

end


function onThink()
  if (os.clock() - talk_start) > 30 then
	  if focus > 0 then
		  selfSay('Next Please...')
	  end
		focus = 0
  end
	if focus ~= 0 then
		if getDistanceToCreature(focus) > 5 then
			selfSay('Good bye then.')
			focus = 0
		end
	end
end

lembrando que eh 8.1 o ot que eu tenho entao pode ter algum problema de sistema de npc. Faz assim posta um npc do seu ot preu ver o sistema.

abraços

 

//skulls

Link para o comentário
https://xtibia.com/forum/topic/107171-fazendo-uma-quest-com-npc/#findComment-692153
Compartilhar em outros sites

Skulls, deu o mesmo erro quando fui falar Hi;

Lua Script Error: [Npc interface]

data/npc/scripts/bloodherb.lua:onCreatureSay

 

data/npc/lib/npc.lua:38: attempt to perform arithmetic on global 'cx' (a table v

alue)

stack traceback:

data/npc/lib/npc.lua:38: in function 'getDistanceToCreature'

data/npc/scripts/bloodherb.lua:39: in function <data/npc/scripts/bloodhe

rb.lua:36>

Mas o tibiaa4e me passou esses dias um NPC de missoes, tipo esse, que funciona no meu, só que eu não consegui faze-lo para essa quest.

O NPC é assim, pro meu OT:

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, 'fighting spirit') then

if getPlayerStorageValue(cid,30004) == -1 then

selfSay('Well. In past i made various fighting spirit, but now is very hard to found a correctly material...', cid)

selfSay('...But a {Royal helmet} uses a good metal. You interressed in trade {two royal helmets} to one fighting spirit ?', cid)

talkState[talkUser] = 1

elseif getPlayerStorageValue(cid,30004) == 1 then

selfSay('Do you have a two royal helmet ?', cid)

talkState[talkUser] = 2

end

 

elseif msgcontains(msg, 'warrior sweat') then

if getPlayerStorageValue(cid,30006) == 1 then

selfSay('Oh, The Thunder need material of warrior sweat ? Well, i give some material, but you need help me. You interessed ?', cid)

talkState[talkUser] = 3

elseif getPlayerStorageValue(cid,30006) == 2 then

selfSay('Do you have a four warrior helmet ?', cid)

talkState[talkUser] = 4

end

 

elseif msgcontains(msg, 'huge chunk') then

if getPlayerStorageValue(cid,30007) == -1 then

selfSay('Oh, i see you like my work. Well i have some huge chunk, but suckers barbarians have stoled my sword. Well if you help me ?', cid)

talkState[talkUser] = 5

elseif getPlayerStorageValue(cid,30007) == 1 then

selfSay('You have a head of general ?', cid)

talkState[talkUser] = 7

elseif getPlayerStorageValue(cid,30008) == 1 and getPlayerStorageValue (cid,30007) == 2 then

selfSay('Oh. I see you have made my mission. You trade {Giant Sword} for a one huge chunk ?', cid)

talkState[talkUser] = 9

end

 

elseif msgcontains(msg, 'letter') then

if getPlayerStorageValue(cid,30010) == 1 then

selfSay('Oh, you have a letter of veronica for me ?', cid)

talkState[talkUser] = 10

end

 

elseif talkState[talkUser] == 1 then

if msgcontains(msg, 'yes') then

selfSay('Ok. I wait you take me a two royal helmets. When you have this ask me about a {fighting spirit}.', cid)

talkState[talkUser] = 2

setPlayerStorageValue(cid,30004,1)

else

selfSay('Well. What you need ?', cid)

 

end

 

 

elseif talkState[talkUser] == 2 then

if msgcontains(msg, 'yes') then

if doPlayerRemoveItem(cid,2498,2) == 1 then

doPlayerAddItem(cid,8761,1)

selfSay('Here your fighting spirit, now i need finish my work.', cid)

talkState[talkUser] = 0

end

elseif msgcontains(msg, 'no') then

selfSay('Well. When you have a two royal helmets, come back here.', cid)

talkState[talkUser] = 0

end

 

elseif talkState[talkUser] == 3 then

if msgcontains(msg, 'yes') then

selfSay('Ok, now i need finish some equipments for war, and soldier need {four warrior helmets}, take me this and i give material to warrior sweat...', cid)

talkState[talkUser] = 6

setPlayerStorageValue(cid,30006,2)

end

 

elseif talkState[talkUser] == 4 then

if msgcontains(msg, 'yes') then

if doPlayerRemoveItem(cid,2475,4) == 1 then

doPlayerAddItem(cid,5940,1)

setPlayerStorageValue(cid,30006,3)

selfSay('Here, send this for {thunder} and he know whats do.', cid)

talkState[talkUser] = 0

end

elseif msgcontains(msg, 'no') then

selfSay('Well. When you have four warrior helmets, come back here.', cid)

talkState[talkUser] = 0

end

 

elseif talkState[talkUser] == 5 then

if msgcontains(msg, 'yes') then

selfSay('I need a thing very simples for me, but i need finish some weapons. Then, burn {five beds} of barbarians generals, in lost city. You interessed ?', cid)

talkState[talkUser] = 6

end

 

elseif talkState[talkUser] == 6 then

if msgcontains(msg, 'yes') then

selfSay('After, take me a head of one barbarian general. Later report me.', cid)

talkState[talkUser] = 0

setPlayerStorageValue(cid,30007,1)

end

 

elseif talkState[talkUser] == 7 then

if msgcontains(msg, 'yes') then

if doPlayerRemoveItem(cid,2475,4) == 1 then

selfSay('Cool.This globet is beautiful. Now i need some thing to make huge... You interessed ?', cid)

setPlayerStorageValue(cid,30007,2)

talkState[talkUser] = 8

end

elseif msgcontains(msg, 'no') then

selfSay('Well. When you have four warrior helmets, come back here.', cid)

talkState[talkUser] = 0

end

 

elseif talkState[talkUser] == 8 then

if msgcontains(msg, 'yes') then

selfSay('I need new weapon, and now give {giant sword} and i give a huge. Report me when you have.', cid)

setPlayerStorageValue(cid,30008,1)

talkState[talkUser] = 0

end

 

elseif talkState[talkUser] == 9 then

if msgcontains(msg, 'yes') then

if doPlayerRemoveItem(cid,2393,1) == 1 then

selfSay('Very nice. Now make good things with your huge.', cid)

setPlayerStorageValue(cid,30008,2)

doPlayerAddItem(cid,5892,1)

talkState[talkUser] = 8

end

elseif msgcontains(msg, 'no') then

selfSay('Well. Take me a Giant sword, more fast possible.', cid)

talkState[talkUser] = 0

end

 

elseif talkState[talkUser] == 10 then

if msgcontains(msg, 'yes') then

if doPlayerRemoveItem(cid,8370,1) == 1 then

selfSay('Oh. Great, Veronica need help, i send some things for she. Report this for veronica ', cid)

setPlayerStorageValue(cid,30010,2)

talkState[talkUser] = 8

end

elseif msgcontains(msg, 'no') then

selfSay('Don\'t make loss my time.', cid)

talkState[talkUser] = 0

end

 

return true

end

end

 

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

npcHandler:addModule(FocusModule:new())

 

E tambem, voce poderia me explicar uma coisinha, tipo me explicar onde eu uso setPlayerStorageValue e getPlayerStorageValue, impregado num script?

Eu to me errando nisso, com os NPCs que faço.

Obrigadão ae Skulls :D

Abraços.

Link para o comentário
https://xtibia.com/forum/topic/107171-fazendo-uma-quest-com-npc/#findComment-692247
Compartilhar em outros sites

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