Ir para conteúdo
Banner com Efeitos

Featured Replies

Postado
  • Este é um post popular.

Esse sistema/script/sei lá o que foi desenvolvido por Karain que quis trazer um 'ar' mais moderno ao tibia.. Com esse script conversar com o npc será mais uma experiência mais amigável, continua sendo customizável mas de uma forma mais fácil!

 

d97b824e2143023e0064dfef4c8b4451.png

 

Como instalar

 

Em data/creaturescripts/creaturescrips.xml adicione

<event type="modalWindow" name="Dialogue" script="dialogue.lua"/>  

Em data/creaturescripts/scripts/login.lua adicione isso antes do "return true"

player:registerEvent("Dialogue") 

Crie em data/creaturescripts o arquivo dialogue.lua e adicione

player_choices = {}
defaultButtons = {{id = 0x00, text = "Select", enter = true, escape = false}, {id = 0x01, text = "End", enter = false, escape = true}}

function Player:getChoiceText(choice_id)
if player_choices and player_choices[self:getId()] then
return player_choices[self:getId()][choice_id].text
else
return false
end
end

function Player:createDialogueWindowWithButtons(modalWindowId, headerText, bodyText, buttonTable, choiceTable, sendToPlayer, priority)
local var = ModalWindow(modalWindowId, headerText, bodyText)
for i = 1, #buttonTable do
var:addButton(buttonTable[i].id, buttonTable[i].text)
if buttonTable[i].enter then
var:setDefaultEnterButton(buttonTable[i].id)
end
if buttonTable[i].escape then
var:setDefaultEscapeButton(buttonTable[i].id)
end
end
player_choices[self:getId()] = choiceTable
for i = 0, #choiceTable do
if choiceTable[i] ~= nil and (choiceTable[i].storage == false or self:getStorageValue(choiceTable[i].storage[1]) == choiceTable[i].storage[2]) then
var:addChoice(i, choiceTable[i].text)
end
end
if not priority then
var:setPriority(false)
end
if sendToPlayer then
var:sendToPlayer(self)
end
end

function onModalWindow(player, modalWindowId, buttonId, choiceId) -- be careful here if you have other modalwindow scripts
if buttonId == 0x00 then
player:say(player:getChoiceText(choiceId),TALKTYPE_SAY)
elseif buttonId == 0x01 then
player:say("Good Bye.",TALKTYPE_SAY)
end
return true
end  

Crie em data/npc/scripts o arquivo dialogue.lua e adicione

local npc_dialogue = {
[1] = {
message="This is the message that shows up before the choices, make sure it's long enough if you are having long choices.",
choices= {
[1]={text="Choice 1", storage=false, dialogue=1, script="end"},
[2]={text="Choice 2",storage=false, dialogue=2, script="script1"},
[3]={text="Choice 3",storage={1234,1}, dialogue=3, script="trade"},
[4]={text="Choice 4",storage=false, dialogue=3, script="quest"},
[5]={text="Choice 5",storage=false, dialogue=false, script="quest2"}}},
[2] = {
message="Bla bla bla bla bla bla bla.",
choices= {
[1]={text="Choice 1",storage=false, dialogue=1, script="end"},
[2]={text="Choice 2",storage=false, dialogue=2, script="end"},
[3]={text="Choice 3",storage={1234,1}, dialogue=false, script="end"},
[4]={text="Choice 4",storage=false, dialogue=false, script="end"},
[5]={text="Choice 5",storage=false, dialogue=3, script="end"}}},
[3] = {
message="Brought to you by Matt Shadowwing.",
choices= {
[1]={text="Choice 1",storage={1245,2}, dialogue=false, script="end"},
[2]={text="Choice 2",storage=false, dialogue=false, script="end"},
[3]={text="Choice 3",storage={1234,1}, dialogue=false, script="end"},
[4]={text="Choice 4",storage=false, dialogue=1, script="end"},
[5]={text="Choice 5",storage=false, dialogue=2, script="end"}}}
}

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 talkstate = {}
local function greetCallback(cid)
local player = Player(cid)
local npc = Npc(getNpcCid())
npcHandler:setMessage(MESSAGE_GREET, npc_dialogue[1].message)
player:createDialogueWindowWithButtons(1, npc:getName(), npc_dialogue[1].message, defaultButtons, npc_dialogue[1].choices, true, false)
talkstate[player:getId()] = 1
return true
end

local function creatureSayCallback(cid, type, msg)
local player = Player(cid)
local npc = Npc(getNpcCid())
if not npcHandler:isFocused(cid) then
return false
elseif talkstate[player:getId()] then
for _, v in pairs(npc_dialogue[talkstate[player:getId()]].choices) do
if msgcontains(msg, v.text) and (v.storage == false or player:getStorageValue(v.storage[1]) == v.storage[2]) then
if v.script == "end" then
talkstate[player:getId()] = v.dialogue
npcHandler:say(npc_dialogue[v.dialogue].message, cid)
player:createDialogueWindowWithButtons(1, npc:getName(), npc_dialogue[v.dialogue].message, defaultButtons, npc_dialogue[v.dialogue].choices, true, false)
elseif v.script == "trade" then
-- trading script here
talkstate[player:getId()] = v.dialogue
npcHandler:say(npc_dialogue[v.dialogue].message, cid)
player:createDialogueWindowWithButtons(1, npc:getName(), npc_dialogue[v.dialogue].message, defaultButtons, npc_dialogue[v.dialogue].choices, true, false)
elseif v.script == "quest" then
-- quest script here
talkstate[player:getId()] = v.dialogue
npcHandler:say(npc_dialogue[v.dialogue].message, cid)
player:createDialogueWindowWithButtons(1, npc:getName(), npc_dialogue[v.dialogue].message, defaultButtons, npc_dialogue[v.dialogue].choices, true, false)
end
end
end
end
return true
end

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

Em data/npc/lib/npcsystem/npchandler.lua altere todos os

TALKTYPE_PRIVATE_PN 

para

TALKTYPE_SAY 

Depois é só criar seu npc.xml referenciar o lua e seja feliz.. Qualquer problema eu terei que repassar para o criador pois não sou apto a dar suporte.. Estou somente trazendo para cá!

Editado por DkAngel83 (veja o histórico de edições)

Postado

Em nome da comunidade do TK, muito obrigado pela contribuição! :wow:
Seu tópico de conteúdo foi aprovado e será movido para a seção adequada. Você ganhou 1 REP+!

Se quiser sua dúvida tirada, mande PM com os links, e não com a dúvida (outros podem ter a mesma dúvida, e o fórum serve para ser usado).

 

Tópicos:


 

yNlhRVC.png

 

55px-Judo_yellow_belt.svg.png

  • 1 year later...
  • 8 months later...

Participe da conversa

Você pode postar agora e se cadastrar mais tarde. Se você tem uma conta, faça o login para postar com sua conta.

Visitante
Responder

Quem Está Navegando 0

  • Nenhum usuário registrado visualizando esta página.

Estatísticas dos Fóruns

  • Tópicos 96.9k
  • Posts 519.7k

Informação Importante

Confirmação de Termo