MY
npc

Como criar npc de missão

Por mylorc, 16 de out. de 2013 em Scripts

como criar npc de missão
resolvido
41
4.6k
mylorcM
16 de outubro de 2013 às 10:45

Olá,preciso criar um npc de missão,alguém me ajuda?

Assim,preciso de um npc que recolha 3 itens e de recompença ele dara ao player xp (do lvl 1 irá para o lvl 8).

Ajudem por favor.

markindootM
16 de outubro de 2013 às 11:17

<?xml version="1.0" encoding="UTF-8"?>
<npc name="NOMEDOSEUNPC" script="data/npc/scripts/NOMEDOARQUIVO.lua" walkinterval="5000" floorchange="0">
<health now="100" max="100"/>
<look type="128" head="20" body="100" legs="50" feet="99" corpse="2212"/>
<parameters>
<parameter key="message_greet" value="Ola |PLAYERNAME|. Bem vindo a minha casa. Em que posso ajudar?"/>
<parameter key="message_farewell" value="Volte quando quiser, |PLAYERNAME|!"/>
<parameter key="module_keywords" value="1" />
</parameters>
</npc>
Em data>npcs>scripts crie um arquivo.lua e cole isto 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
if(msgcontains(msg, 'kevnan')) and getPlayerStorageValue(cid, 3987) >= 1 then
selfSay('Voc\ê j\á vingou a morte de meu filho.', cid)
talkState[talkUser] = 0
end

if(msgcontains(msg, 'kevnan')) and getPlayerStorageValue(cid, 3987) <= 0 then
selfSay('Ah você conhece meu filho Kevnan? Que ótimo conhecer você. A vários dias ele saiu em uma jornada perigosa e até então não tenho notícias dele, você sabe algo a respeito?', cid)
elseif(msgcontains(msg, 'botas')) then
selfSay('Voc\ê falou botas? Diga {yes} ou {no}', cid)
talkState[talkUser] = 1
elseif(msgcontains(msg, 'mais')) then
selfSay('Acredito que quem matou meu filho foi um poderoso monstro que anda aterrorizando a região, há boatos que é um dragão jamais visto antes, se você vingar a morte do meu filho vou te dar algo que pertencia a Kevnan, algo que ele gostava muito, volte aqui quando cumprir sua {missao}.', cid)
talkState[talkUser] = 2



elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
if (getPlayerItemCount(cid, 6530) >= 1) then
selfSay('Ma.. Mas que triste notícia..... Meu filho querido, mamãe também te ama, que esteja bem onde quer que esteja..Quer saber {mais}?', cid)
talkState[talkUser] = 0
else
selfSay('De quais botas você está falando?', cid)
talkState[talkUser] = 0
end
elseif(msgcontains(msg, 'missao') and talkState[talkUser] == 2) then
if(getPlayerItemCount(cid, IDITEM1) >= 1) then

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

if(getPlayerItemCount(cid, IDITEM3) >= 1) then
selfSay('Muito obrigado por ter vingado a morte de meu filho Kevnan. Como prometido aqui está a sua recompensa.', cid)
doPlayerRemoveItem(cid, REMOVEITEM1, 1)

doPlayerRemoveItem(cid, REMOVEITEM2, 1)

doPlayerRemoveItem(cid, REMOVEITEM3, 1)
doPlayerAddLevel(cid, 15407, 7)
setPlayerStorageValue(cid, 3987, 1)
talkState[talkUser] = 0
else
selfSay('Ainda n\ão vingou a morte do meu filho Kevnan? Lembre-se que eh um dragão jamais visto antes que esta pelas regioes geladas. Voc\ê precisa trazer algo que prove que foi este monstro que matou meu filho', cid)
talkState[talkUser] = 0
end
end
return TRUE
end

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

 

 

 

ve ae se vai

Editado Outubro 16 por markindoot

mylorcM
16 de outubro de 2013 às 13:14

Aonde fica o xp de recompença?

Eu fiz tudo,coloquei no rme e tal,mas quando abro o jogo o npc não aparece.

O que faço?

Editado Outubro 16 por mylorc

AlphaLoveA
16 de outubro de 2013 às 14:14

Creio que ele não dará em xp a recompensa, mas sim em level.

 

Eu não entendo muito de script, mas pelo que vi, ele dará 7 level ao player, fazendo assim com que ele passe do level 1 ao 8.

 

A linha em que se encontra esta parte:

doPlayerAddLevel(cid, 15407, 7)

onde está o 7, é o numero de leveis que ele vai ganhar.

 

Creio que seja isso.

markindootM
16 de outubro de 2013 às 15:02

Issu mesmo N4K4MUR4

 

Para o npc aparecer, ele funciona como se fosse uma tag essa parte em NPC :

 

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

<npc name="NOMEDOSEUNPC" script="data/npc/scripts/NOMEDOARQUIVO.lua" walkinterval="5000" floorchange="0"> <---- essa parte NOMEDOARQUIVO tem que ser igual ao que fica na pasta NPC/Scripts
<health now="100" max="100"/>
<look type="128" head="20" body="100" legs="50" feet="99" corpse="2212"/>
<parameters>
<parameter key="message_greet" value="Ola |PLAYERNAME|. Bem vindo a minha casa. Em que posso ajudar?"/>
<parameter key="message_farewell" value="Volte quando quiser, |PLAYERNAME|!"/>
<parameter key="module_keywords" value="1" />
</parameters>
</npc>

 

 

Exemplo se na pasta NPC voce colocar assim:

 

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

<npc name="Ursula" script="data/npc/scripts/Ursula.lua" walkinterval="5000" floorchange="0">
<health now="100" max="100"/>
<look type="128" head="20" body="100" legs="50" feet="99" corpse="2212"/>
<parameters>
<parameter key="message_greet" value="Ola |PLAYERNAME|. Bem vindo a minha casa. Em que posso ajudar?"/>
<parameter key="message_farewell" value="Volte quando quiser, |PLAYERNAME|!"/>
<parameter key="module_keywords" value="1" />
</parameters>
</npc>

 

Voce tem que Criar um Arquivo em NPC/script e renomear para Ursula, ficando script="data/npc/scripts/Ursula.lua" walkinterval="5000" floorchange="0"> para o script localizar o NPC.

Editado Outubro 16 por markindoot

mylorcM
16 de outubro de 2013 às 16:08

É eu fiz tudo corretamente,porém ainda não aparece no jogo.(Obs:No RME aparece)

O que podera estar ocorrendo?

zipter98Z
16 de outubro de 2013 às 16:17

Tenta 'summonar' o NPC pelo /n. Veja se ocorre algum erro no console, ou ele é summonado corretamente. Se der algum erro, poste aqui, por favor.

mylorcM
16 de outubro de 2013 às 16:33

Eu tento summonar e diz assim, Sorry,not possible.

o que fazer?

zipter98Z
16 de outubro de 2013 às 18:05

Deu algum erro no console? Se sim (provavelmente), poderia postar aqui?

mylorcM
16 de outubro de 2013 às 18:11

Esse é os arquivo:XML

 

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

<npc name="Force" script="data/npc/scripts/force.lua" walkinterval="5000" floorchange="0" access="5" level="1" maglevel="1">

<health now="100" max="100"/>

<look type="128" head="20" body="100" legs="50" feet="99" corpse="2212"/>

<parameters>

<parameter key="message_greet" value="Hello |PLAYERNAME|. Welcome to the start of the game. How can I help?{Mission}"/>

<parameter key="message_farewell" value="Come back anytime, |PLAYERNAME|!"/>

<parameter key="module_keywords" value="1" />

</parameters>

</npc>

 

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

 

local talkUser = NPCHANDLER_CONVbehavior == CONVERSATION_DEFAULT and 0 or cid

if(msgcontains(msg, 'kevnan')) and getPlayerStorageValue(cid, 3987) >= 1 then

selfSay('You've picked the itens.', cid)

talkState[talkUser] = 0

end

 

if(msgcontains(msg, 'cheap')) and getPlayerStorageValue(cid, 3987) <= 0 then

selfSay('Oh you saw the cockroaches out there know what is good in them? Ah legs ... haha', cid)

elseif(msgcontains(msg, 'legs')) then

selfSay('You talked legs? Tell {yes} or {no}', cid)

talkState[talkUser] = 1

elseif(msgcontains(msg, 'more')) then

selfSay('I believe that you can kill those cheap, come back when you get 10 legs to {mission}.', cid)

talkState[talkUser] = 2

 

 

 

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

if (getPlayerItemCount(cid, 8710) >= 10) then

selfSay('Ma. But that good news ..... Legs of cockroaches, Mom will make a soup with them .. Wondering {more}?', cid)

talkState[talkUser] = 0

else

selfSay('From what you're talking about legs?', cid)

talkState[talkUser] = 0

end

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

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

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

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

selfSay('Thank you for picking up your legs for me. As promised here is your reward.', cid)

doPlayerRemoveItem(cid, REMOVEITEM1, 1)

doPlayerRemoveItem(cid, REMOVEITEM2, 1)

doPlayerRemoveItem(cid, REMOVEITEM3, 1)

doPlayerAddLevel(cid, 15407, 7)

setPlayerStorageValue(cid, 3987, 1)

talkState[talkUser] = 0

else

selfSay('Still not got the legs? Remember that cheap is legs. You need to bring your legs to the mission', cid)

talkState[talkUser] = 0

end

end

return TRUE

end

 

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

npcHandler:addModule(FocusModule:new())

 

É isso ai,se tiver algum problema me avisa por favor.

zipter98Z
16 de outubro de 2013 às 18:18

Cerco, mas ao tentar summonar o npc, deu algum erro no distro/console? Se você pudesse postar aqui o erro, ficaria mais fácil corrigir, ou tentar corrigir, o erro.

mylorcM
16 de outubro de 2013 às 18:30

Tem skype para mim te mostrar como que é?

Por que tipo só fala Sorry,not possible algo assim,não da error.

zipter98Z
16 de outubro de 2013 às 18:40

Eu tinha um skype, só não sei onde foi parar a senha dele hu3

De qualquer maneira, tente substituir o arquivo LUA do NPC por estes: NÃO é certeza que vá funcionar, porque nunca fui bom com npcs ;/

1ª opção: --3 unidades do mesmo item.

 

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 talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
local cfg = {
storage = xxx, --Coloque aqui a storage da quest.
item = xxx, --Coloque aqui o id do item que deverá entregar ao npc.
}
if msgcontains(string.lower(msg), 'mission') or msgcontains(string.lower(msg), 'help') then
selfSay("Gostaria de me ajudar em uma missão?", cid)
talkState[talkUser] = 1
elseif (msgcontains(string.lower(msg), 'yes') or msgcontains(string.lower(msg), 'sim')) and talkState[talkUser] == 1 then
if getPlayerLevel(cid) > 1 then
selfSay("Você é muito forte para fazer esta missão.", cid)
talkState[talkUser] = 0
return true
end
if getPlayerStorageValue(cid, cfg.storage) <= 0 then
selfSay("Certo, traga-me 3 unidades do item xxx e lhe recompensarei com experiência.", cid)
setPlayerStorageValue(cid, cfg.storage, 1)
talkState[talkUser] = 0
return true
elseif getPlayerStorageValue(cid, cfg.storage) == 1 then
if getPlayerItemCount(cid, cfg.item) >= 3 then
selfSay("Obrigado!", cid)
doPlayerRemoveItem(cid, cfg.item, 3)
doPlayerAddLevel(cid, 7)
setPlayerStorageValue(cid, cfg.storage, 1)
talkState[talkUser] = 0
return true
else
selfSay("Você ainda não conseguiu os items, portanto vá busca-los!", cid)
talkState[talkUser] = 0
return true
end
elseif getPlayerStorageValue(cid, cfg.storage) == 2 then --no caso soh da pra fazer isso 1x por char...
selfSay("Obrigado novamente por me ajudar!", cid)
talkState[talkUser] = 0
return true
end
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

npcHandler:addModule(FocusModule:new())

 

 

2ª opção -- 3 items diferentes.

 

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 talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
local storage = xxx --Storage da quest.
local items = {xxx, yyy, zzz} --Items necessários (substitua as letras x, y e z pelo ID dos items).
if msgcontains(string.lower(msg), 'mission') or msgcontains(string.lower(msg), 'help') then
selfSay("Gostaria de me ajudar numa missão?", cid)
talkState[talkUser] = 1
elseif (msgcontains(string.lower(msg), 'yes') or msgcontains(string.lower(msg), 'sim')) and talkState[talkUser] == 1 then
if getPlayerLevel(cid) > 1 then
selfSay("Você é muito forte para fazer esta missão.", cid)
talkState[talkUser] = 0
return true
end
if getPlayerStorageValue(cid, storage) <= 0 then
selfSay("Traga-me esses items:xxx, yyy, zzz e lhe recompensarei com experiência.", cid)
setPlayerStorageValue(cid, storage, 1)
talkState[talkUser] = 0
return true
elseif getPlayerStorageValue(cid, storage) == 1 then
for a, b in ipairs(items) do
if getPlayerItemCount(cid, b) >= 1 then
selfSay("Obrigado!", cid)
doPlayerAddLevel(cid, 7)
doPlayerRemoveItem(cid, items, 1)
talkState[talkUser] = 0
return true
else
selfSay("Você ainda não conseguiu os items, portanto vá busca-los!", cid)
talkState[talkUser] = 0
return true
end
end
elseif getPlayerStorageValue(cid, storage) == 2 then --no caso soh da pra fazer isso 1x por char...
selfSay("Obrigado novamente!", cid)
talkState[talkUser] = 0
return true
end
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

npcHandler:addModule(FocusModule:new())

 

 

Arquivo xml:

<?xml version="1.0" encoding="UTF-8"?>
 
<npc name="Nomedonpc" script="arquivo.lua" walkinterval="0" floorchange="0" access="5" level="1" maglevel="1">
<health now="150" max="150"/>
<look type="523" head="114" body="119" legs="114" feet="114" corpse="2212"/>
 
<parameters>
<parameter key="message_greet" value="Hello |PLAYERNAME|, what do you want?"/>
</parameters>
</npc>

#EDIT: Acabei de testar o primeiro script, juntamente com o xml que passei, e funcionou perfeitamente.

#EDIT²: Pequena alterada nos scripts.

Editado Outubro 16 por zipter98

mylorcM
16 de outubro de 2013 às 19:07

Fiz,porém o npc não aparece,nem tentando summonalo,creio que o problema seje o arquivo lua,pois o xml eu troquei com outros e não resolveu.

zipter98Z
16 de outubro de 2013 às 19:34

Você testou o primeiro arquivo lua, juntamente com o arquivo xml e mudou TUDO o que foi indicado? Nome, arquivo, id dos items, storage, etc? No próprio script está mostrando onde você deve mudar. Se mesmo assim não funcionar, então realmente não sei como lhe ajudar, pois aqui funcionou perfeitamente :x

Sobre o arquivo lua, o único erro que vi que tinha, corrigi e editei lá. E, só pra confirmar, você está tentando summona-lo com o comando /n e não /m, certo? e.e

Editado Outubro 16 por zipter98