[ModalWindow][TFS 1.2][NPC] Sistema de Diálogo

DeCarvalho
em Globalevents e Spells

DeCarvalho

Procurando Host
avatar
Barão
Barão

INFOS

Grupo: BarãoRegistrado: 28/10/10Posts: 206Char no Tibia: Mage Junkie

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á!

RigBy

Katrina? Romero Brito?
avatar
Visconde
Visconde

INFOS

Grupo: ViscondeRegistrado: 05/02/14Posts: 411Gênero: MasculinoChar no Tibia: Zeh Sergipano

Legal, eu tinha feito um sistema quase assim só que para 8.6, mas não fico tão bom quanto esse.



DXBXk1i.gif

DeCarvalho

Procurando Host
avatar
Barão
Barão

INFOS

Grupo: BarãoRegistrado: 28/10/10Posts: 206Char no Tibia: Mage Junkie

Eu tava online na hora que o karain tinha postado.. dei uma testada por alto e pedi autorização pra trazer... particularmente não me ganhou.. mas tem gente que curte né :D isso de modalwindow é bem top e deixa com um ar bem moderno mesmo :D

Vampiresco

A única certeza é a morte...
avatar
Cavaleiro
Cavaleiro

INFOS

Grupo: CavaleiroRegistrado: 26/02/10Posts: 158Gênero: MasculinoChar no Tibia: Vampiresco

Desculpe, este sistema funciona na versão 8.6? Excelente, mesmo que não...

Sou o tal humilde Deus, que cria o mais perfeito e justo mundo a se viver.. .. ..

DeCarvalho

Procurando Host
avatar
Barão
Barão

INFOS

Grupo: BarãoRegistrado: 28/10/10Posts: 206Char no Tibia: Mage Junkie

Bom dia fera, bem, é por isso que usamos as tags para identificar o sistema.. [TFS 1.2] quer dizer que é para servidores que utilizam essa versão.. bem funciona em tfs 1.1 também..

 

Se não me engano, é possível usar 8.6 com 1.2,m mas imagino que o seu seja outra versão.. enfim..

 

O comentou ter feito um para 8.6, quem sabe, se por acaso, voc~e pedir com jeitinho ele não venha a liberar :D

daniofordon

avatar
Campones
Campones

INFOS

Grupo: CamponesRegistrado: 24/09/15Posts: 7

good :)

robiie123

avatar
Campones
Campones

INFOS

Grupo: CamponesRegistrado: 29/12/15Posts: 9

pra que server isso ai ?

kaleudd

avatar
Conde
Conde

INFOS

Grupo: CondeRegistrado: 15/06/15Posts: 729

teria como adaptar para tfs 0.3.6?

Luga03

Gabriel Lucena :D
avatar
Conde
Conde

INFOS

Grupo: CondeRegistrado: 14/04/15Posts: 956Gênero: Masculino

teria como adaptar para tfs 0.3.6?

Não, pois o Tfs 0.3.6 não tem a função de ModalWindow nas sources, a não ser que alguem consiga extrair está função do Tfs 1.1 ou 1.2

Hello! How are you? It's fine? 

 

Okay, so you like my helps? if yes, then do you can like my post, give-me a reputation, you can't?

 

Good morning for everyone! And have a good day!

sprague

avatar
Campones
Campones

INFOS

Grupo: CamponesRegistrado: 15/01/11Posts: 1Char no Tibia: Blade-Keller

não funcionou para mim, image.png.4c287a2df5c93136deefbfe254cdc7d7.png

image.png