AD

Ajuda para arrumar Script de um NPC

Por adrianokk, 03 de abr. de 2020 em Scripts

12
1.9k
adrianokkA
03 de abril de 2020 às 18:01

Eu tenho esse NPC de teleporte no meu servidor mais queria melhorar um pouco ele.

Colocar parra quando o jogador for usar o Teleporte, retirar  valor "X" de dinheiro, mais continuar com sistema de restringir por premium e level.

e quando ele fala essa frase "Posso levar você para Ice Island por 40 gold coins?" ele esta falando no chat normal, como faz para ele falar no chat de NPC em Azul. ?

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



-- OTServ event handling functions start
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
-- OTServ event handling functions end



local travelNode = keywordHandler:addKeyword({'ice island'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Posso levar você para Ice Island por 40 gold coins?'})
	travelNode:addChildKeyword({'yes'}, StdModule.travel, {npcHandler = npcHandler, premium = true, level = 30, destination = {x=988, y=992, z=5} })
	
	travelNode:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'I wouldn\'t go there either.'})

keywordHandler:addKeyword({'destination'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I can take you to \'Ice Island\' for just a small fee.'})

-- Makes sure the npc reacts when you say hi, bye etc.
npcHandler:addModule(FocusModule:new())

 

Editado Abril 3 por adrianokk

Correção

Yan OliveiraY
10 de abril de 2020 às 15:52

Substitui todo seu código por esse:

 

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


-- VARIÁVEIS --
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
msg = string.lower(msg)
  
local id_coin = 2152 -- ID DO GOLD COIN
local quantidade_coin = 40 -- QUANTIDADE COINS QUE PRECISA PARA VIAJAR
local level = 30 --LEVEL MÍNIMO PARA VIAJAR
local position = {x= 998, y= 992, z= 5} -- POSIÇÃO DE ONDE O PLAYER IRÁ AO SER TELEPORTADO

----------------------------------- [ DIALOGO COM NPC] ---------------------------------
  
if msgcontains(msg, 'help') or msgcontains(msg, 'travel') or msgcontains(msg, 'viagem') then
   selfSay("I can take you to {Ice Island} for " ..quantidade_coin.. " gold coins. Do you want?", cid)
   talkState[talkUser] = 1
  

elseif (msgcontains(msg, 'yes') or msgcontains(msg, 'sim')) and talkState[talkUser] == 1 then 
   if isPremium(cid) then
     if getPlayerLevel(cid) >= level then
       if getPlayerItemCount(cid, id_coin) >= 40 then 
         doPlayerRemoveItem(cid, id_coin, quantidade_coin)
         selfSay("See you!", cid)
         doTeleportThing(cid, position)
         talkState[talkUser] = 0
       return true
       else
         selfSay("You don't have " ..quantidade_coin.. " gold coins.", cid)
         talkState[talkUser] = 0
       return true
       end
     else
       selfSay("You need to be at least level" ..level.. " or more to travel.", cid)
       talkState[talkUser] = 0
     return true
     end
   else
     selfSay("You need to be premium account to travel.", cid)
     talkState[talkUser] = 0
   return true
   end

elseif (msgcontains(msg, 'no') or msgcontains(msg, 'não')) and talkState[talkUser] == 1 then
  selfSay("Ok, goodbye.")
  talkState[talkUser] = 0
return true

elseif (msgcontains(msg, "yes") ~= "yes" or msgcontains(msg, "sim") ~= "sim" or msgcontains(msg, "não") ~= "não" or msgcontains(msg, "no") ~= "no") and talkState[talkUser] == 1 then
  selfSay("I didn't understand your answer. Do you want to travel or not?", cid)  
return true
end

return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Agora vai no arquivo xml desse npc e a partir da tag

<parameters>
	<TAG />
</parameters>
</npc>

substitua tudo até o final por esse:

<parameters>
	<parameter key="message_greet" value="Hello |PLAYERNAME|, say {help}, {viagem} or {travel} to more informations."/>
</parameters>
</npc>

 

Fiz verificação se é premium, verificação por nível e se tem a quantidade de gold coins necessária para viajar.

 

Lembre de trocar o id do gold coin na variável id_coin, pois eu não tenho base de Tibia, então testei com Poketibia, e não sei se o id do dinheiro é o mesmo.

 

Eu testei e está funcionando. Mas testa e fale se der algum problema.

adrianokkA
11 de abril de 2020 às 13:57

cara, estou me apaixonando por você kkkkk

Yan OliveiraY
12 de abril de 2020 às 18:23
Em 11/04/2020 em 13:57, adrianokk disse:

cara, estou me apaixonando por você kkkkk

Eita, calma lá hahaha.

 

Mas que bom que funcionou, fico feliz ?.

adrianokkA
12 de abril de 2020 às 19:25

Como eu posso botar para o NPC levar o player para varias lugares diferentes ?

Yan OliveiraY
13 de abril de 2020 às 02:03
6 horas atrás, adrianokk disse:

Como eu posso botar para o NPC levar o player para varias lugares diferentes ?

Tem que saber as coordenadas e criar as condições de acordo com o lugar que quer ir. Me fala a posição de cada lugar e o nome (palavra-chave) que o player precisa dizer para ir para tal lugar, igual ali Ice Island que eu faço para você.

adrianokkA
14 de abril de 2020 às 12:29
{'ice island'} = {x=2449, y=2305, z=6
 premium = false
quantidade_coin = 5

{'fuchsia'} = {x=1044, y=1396, z=6}

 premium = false
quantidade_coin = 

 

{'azalea'} = {x=1132, y=2748, z=6}

 premium = TRUE
quantidade_coin = 
Yan OliveiraY
14 de abril de 2020 às 15:35
3 horas atrás, adrianokk disse:
{'ice island'} = {x=2449, y=2305, z=6
 premium = false
quantidade_coin = 5

{'fuchsia'} = {x=1044, y=1396, z=6}

 premium = false
quantidade_coin = 

 

{'azalea'} = {x=1132, y=2748, z=6}

 premium = TRUE
quantidade_coin = 

 

Substitua o código por este:

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


-- VARIÁVEIS --
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
msg = string.lower(msg)
  
local id_coin = 2152 -- ID DO GOLD COIN
local quantidade_coin_ice_island = 40 -- QUANTIDADE COINS QUE PRECISA PARA VIAJAR PARA ICE ISLAND
local quantidade_coin_fuchsia = 40 -- QUANTIDADE COINS QUE PRECISA PARA VIAJAR PARA FUCHSIA
local quantidade_coin_azalea = 200 -- QUANTIDADE COINS QUE PRECISA PARA VIAJAR PARA AZALEA
local level = 30 --LEVEL MÍNIMO PARA VIAJAR
local position_ice_island = {x= 2449, y= 2305, z= 6} -- POSIÇÃO DE ONDE O PLAYER IRÁ AO SER TELEPORTADO EM ICE ISLAND
local position_fuchsia = {x= 1044, y= 1396, z= 6} -- POSIÇÃO DE ONDE O PLAYER IRÁ AO SER TELEPORTADO EM FUCHSIA
local position_azalea = {x= 1132, y= 2748, z= 6} -- POSIÇÃO DE ONDE O PLAYER IRÁ AO SER TELEPORTADO EM AZALEA

----------------------------------- [ DIALOGO COM NPC] ---------------------------------
  
if msgcontains(msg, 'help') or msgcontains(msg, 'travel') or msgcontains(msg, 'viagem') then
   selfSay("I can take you to {Ice Island} for "..quantidade_coin_ice_island.. " coins,  to {Fuchsia} for " ..quantidade_coin_fuchsia.. " coins or to {Azalea} for " ..quantidade_coin_azalea.. " coins. Say the name of place that you want to travel.", cid)
   talkState[talkUser] = 1
  
--- AZALEA ---
elseif msgcontains(msg, 'Azalea')) and talkState[talkUser] == 1 then 
   if isPremium(cid) then
     if getPlayerLevel(cid) >= level then
       if getPlayerItemCount(cid, id_coin) >= quantidade_coin_azalea then 
         doPlayerRemoveItem(cid, id_coin, quantidade_coin_azalea)
         selfSay("Good Luck!", cid)
         doTeleportThing(cid, position_azalea)
         talkState[talkUser] = 0
       return true
       else
         selfSay("You don't have " ..quantidade_coin_azalea.. " gold coins.", cid)
         talkState[talkUser] = 0
       return true
       end
     else
       selfSay("You need to be at least level" ..level.. " or more to travel.", cid)
       talkState[talkUser] = 0
     return true
     end
   else
     selfSay("You need to be premium account to travel to {Azalea}.", cid)
     talkState[talkUser] = 0
   return true
   end

--- ICE ISLAND ---
elseif msgcontains(msg, 'Ice Island') and talkState[talkUser] == 1 then
    if getPlayerLevel(cid) >= level then
        if getPlayerItemCount(cid, id_coin) >= quantidade_coin_ice_island then 
           doPlayerRemoveItem(cid, id_coin, quantidade_coin_ice_island)
           selfSay("Good luck!", cid)
           doTeleportThing(cid, position_ice_island)
           talkState[talkUser] = 0
        return true
        else
           selfSay("You don't have " ..quantidade_coin_ice_island.. " gold coins.", cid)
           talkState[talkUser] = 0
        return true
        end
    else
       selfSay("You need to be at least level" ..level.. " or more to travel.", cid)
       talkState[talkUser] = 0
    return true
    end

--- FUCHSIA ---
elseif msgcontains(msg, 'Fuchsia') and talkState[talkUser] == 1 then
    if getPlayerLevel(cid) >= level then
        if getPlayerItemCount(cid, id_coin) >= quantidade_coin_fuchsia then 
           doPlayerRemoveItem(cid, id_coin, quantidade_coin_fuchsia)
           selfSay("Good luck!", cid)
           doTeleportThing(cid, position_fuchsia)
           talkState[talkUser] = 0
        return true
        else
           selfSay("You don't have " ..quantidade_coin_fuchsia.. " gold coins.", cid)
           talkState[talkUser] = 0
        return true
        end
    else
       selfSay("You need to be at least level" ..level.. " or more to travel.", cid)
       talkState[talkUser] = 0
    return true
    end

elseif (msgcontains(msg, "Ice Island") ~= "Ice Island" or msgcontains(msg, "Fuchsia") ~= "Fuchsia" or msgcontains(msg, "Azalea") ~= "Azalea") and talkState[talkUser] == 1 then
  selfSay("I don't know this place.", cid)  
return true
end

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

Eu ajustei o script, então agora o player precisa falar o nome do lugar que quer ir.  Como você não colocou a quantidade coins para dois lugares, eu deixei 40 e o lugar para vip 200. Mas isso você pode mudar. Só tem acesso vip Azalea assim como pediu. 

 

Teste e me fale se deu certo.

Editado Abril 14 por Yan18

adrianokkA
19 de abril de 2020 às 12:24

@Yan18 Desculpa a demora, porque eu to fazendo o server sozinho, tava cansado e passei uns deias sem mexer nele.

só voltei ontem a mexer e testei o NPC hoje. O NPC esta funcionando direitinho, mas queria saber 2 coisas.

 

1- para eu add uma confirmação ex (jogador confirmas com um "YES" ou "NO" se realmente deseja viajar)

2-a função "creatureSayCallback"  joga o npc no local em vez de teleportar. Qual função seria para fazer ele ser teleportado mesmo ?

Editado Abril 19 por adrianokk

Yan OliveiraY
19 de abril de 2020 às 13:00
33 minutos atrás, adrianokk disse:

@Yan18 Desculpa reviver o tópico agora, porque eu to fazendo o server sozinho, tava cansado e passei uns deias sem mexer nele.

só voltei ontem a mexer e testei o NPC hoje. Mas deu esse erro aqui

 

  Ocultar conteúdo

[Error - LuaScriptInterface::loadFile] data/npc/scripts/Teleporte_Test.lua:114: 'end' expected (to close 'function' at line 11) near '<eof>'
[19/04/2020 12:19:24] [Warning - NpcScript::NpcScript] Cannot load script: data/npc/scripts/Teleporte_Test.lua
[19/04/2020 12:19:24] data/npc/scripts/Teleporte_Test.lua:114: 'end' expected (to close 'function' at line 11) near '<eof>'

 

Sem problemas! Entendo como é, é ruim mesmo kk, também edito o meu sozinho.

 

Sobre o script, não deu esse problema para mim, você copiou corretamente? Porém achei dois erros que tinha no script, um estava com 1 parênteses a mais, e o outro problema era porque coloquei as letras iniciais maiúscula, e tem que ser tudo minúsculo no código. Testei aqui e está funcionando agora.

 

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


-- VARIÁVEIS --
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
msg = string.lower(msg)
  
local id_coin = 2152 -- ID DO GOLD COIN
local quantidade_coin_ice_island = 40 -- QUANTIDADE COINS QUE PRECISA PARA VIAJAR PARA ICE ISLAND
local quantidade_coin_fuchsia = 40 -- QUANTIDADE COINS QUE PRECISA PARA VIAJAR PARA FUCHSIA
local quantidade_coin_azalea = 200 -- QUANTIDADE COINS QUE PRECISA PARA VIAJAR PARA AZALEA
local level = 30 --LEVEL MÍNIMO PARA VIAJAR
local position_ice_island = {x= 2449, y= 2305, z= 6} -- POSIÇÃO DE ONDE O PLAYER IRÁ AO SER TELEPORTADO EM ICE ISLAND
local position_fuchsia = {x= 1044, y= 1396, z= 6} -- POSIÇÃO DE ONDE O PLAYER IRÁ AO SER TELEPORTADO EM FUCHSIA
local position_azalea = {x= 1132, y= 2748, z= 6} -- POSIÇÃO DE ONDE O PLAYER IRÁ AO SER TELEPORTADO EM AZALEA

----------------------------------- [ DIALOGO COM NPC] ---------------------------------
  
if msgcontains(msg, 'help') or msgcontains(msg, 'travel') or msgcontains(msg, 'viagem') then
   selfSay("I can take you to {Ice Island} for "..quantidade_coin_ice_island.. " coins,  to {Fuchsia} for " ..quantidade_coin_fuchsia.. " coins or to {Azalea} for " ..quantidade_coin_azalea.. " coins. Say the name of place that you want to travel.", cid)
   talkState[talkUser] = 1
  
--- AZALEA ---
elseif msgcontains(msg, 'azalea') and talkState[talkUser] == 1 then 
   if isPremium(cid) then
     if getPlayerLevel(cid) >= level then
       if getPlayerItemCount(cid, id_coin) >= quantidade_coin_azalea then 
         doPlayerRemoveItem(cid, id_coin, quantidade_coin_azalea)
         selfSay("Good Luck!", cid)
         doTeleportThing(cid, position_azalea)
         talkState[talkUser] = 0
       return true
       else
         selfSay("You don't have " ..quantidade_coin_azalea.. " gold coins.", cid)
         talkState[talkUser] = 0
       return true
       end
     else
       selfSay("You need to be at least level" ..level.. " or more to travel.", cid)
       talkState[talkUser] = 0
     return true
     end
   else
     selfSay("You need to be premium account to travel to {Azalea}.", cid)
     talkState[talkUser] = 0
   return true
   end

--- ICE ISLAND ---
elseif msgcontains(msg, 'ice island') and talkState[talkUser] == 1 then
    if getPlayerLevel(cid) >= level then
        if getPlayerItemCount(cid, id_coin) >= quantidade_coin_ice_island then 
           doPlayerRemoveItem(cid, id_coin, quantidade_coin_ice_island)
           selfSay("Good luck!", cid)
           doTeleportThing(cid, position_ice_island)
           talkState[talkUser] = 0
        return true
        else
           selfSay("You don't have " ..quantidade_coin_ice_island.. " gold coins.", cid)
           talkState[talkUser] = 0
        return true
        end
    else
       selfSay("You need to be at least level" ..level.. " or more to travel.", cid)
       talkState[talkUser] = 0
    return true
    end

--- FUCHSIA ---
elseif msgcontains(msg, 'fuchsia') and talkState[talkUser] == 1 then
    if getPlayerLevel(cid) >= level then
        if getPlayerItemCount(cid, id_coin) >= quantidade_coin_fuchsia then 
           doPlayerRemoveItem(cid, id_coin, quantidade_coin_fuchsia)
           selfSay("Good luck!", cid)
           doTeleportThing(cid, position_fuchsia)
           talkState[talkUser] = 0
        return true
        else
           selfSay("You don't have " ..quantidade_coin_fuchsia.. " gold coins.", cid)
           talkState[talkUser] = 0
        return true
        end
    else
       selfSay("You need to be at least level" ..level.. " or more to travel.", cid)
       talkState[talkUser] = 0
    return true
    end

elseif (msgcontains(msg, "Ice Island") ~= "Ice Island" or msgcontains(msg, "Fuchsia") ~= "Fuchsia" or msgcontains(msg, "Azalea") ~= "Azalea") and talkState[talkUser] == 1 then
  selfSay("I don't know this place.", cid)  
return true
end

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

Qualquer problema só falar. 

adrianokkA
19 de abril de 2020 às 13:03

foi erro meu. eu ja arrumei isso, eu acabei de alterara publicação ali em cima

so queria saber essas 2 coisas aqui
 

1- para eu add uma confirmação ex (jogador confirmas com um "YES" ou "NO" se realmente deseja viajar)

2-a função "creatureSayCallback"  joga o npc no local em vez de teleportar. Qual função seria para fazer ele ser teleportado mesmo ?

 

Yan OliveiraY
19 de abril de 2020 às 13:25
18 minutos atrás, adrianokk disse:

foi erro meu. eu ja arrumei isso, eu acabei de alterara publicação ali em cima

so queria saber essas 2 coisas aqui
 

1- para eu add uma confirmação ex (jogador confirmas com um "YES" ou "NO" se realmente deseja viajar)

2-a função "creatureSayCallback"  joga o npc no local em vez de teleportar. Qual função seria para fazer ele ser teleportado mesmo ?

 

Só pegar o que mandei por último ali que já está tudo arrumado.

 

Para adicionar uma confirmação tem que criar uma condição elseif com msgcontains e yes, igual fiz no primeiro script quando só pediu com 1 cidade. Porém eu tirei o diálogo de yes porque não faz sentido manter quando você tem mais de uma cidade para viajar. Caso o player não queira só falar não, mas ele ter que falar yes e depois uma das cidades não tem sentido, vai confirmar duas vezes uma coisa que o player só quer em uma. Então é mais fácil do jeito que deixei, fora que iria dar mais trabalho, porque a palavra chave está no msgcontains, então se trabalhar com yes, vai ter que criar mais um estado de fala (talkState[Talkuser]) para 2, porque o yes seria a 1, e seria uma coisa a mais sem sentido. Mas ai fica por sua conta.

 

Sobre teleportar, não entendi muito bem, você quer teleportar o npc?