Otfan125
Well-Known Member
Hey mens,
So I've been searching this time, done a lot of learning lua, and lurking around the forums to become more and more familiar with Lua and TFS.... and I'm still a lvl 6 no vocation noob at it, so please help me out hehe...
Anyways, I've been trying to change the way you Communicate with the Npc's, and So far from what I've gotten from the forums, I have that you're able to tell the Npc "Hi" and a modWindow will pop up and give you options to choose from. Here's the link/credit to the person who created the script: https://otland.net/threads/tfs-1-2-npc-dialogue-tree.235201/
So, What I wanted to know is that, When you say "Hi", the Npc will show you the modWindow with the list of choices like so:
How ever, in the normal script from the original thread, When you choose an option and click "Select", my character will say the text that the choice carries... So if I choose the first choice my character will say "Who are you?!"
All seems fine and dandy and it works just fine, BUT what I want to do is that when you choose an option, instead of the Npc reading your text, the script goes to the next modWindow that corresponds to the option you chose first.
here's what I have for creaturescripts\scripts\dialogue.lua
(AS YOU CAN SEE I TOOK OFF "--player:say(player:getChoiceText(choiceId),TALKTYPE_SAY)" SO MY CHARACTER WON'T SAY THE TEXT)
Now i'm not sure if the solution is within that script, so here's the other .lua script from npc\scripts\dialogue.lua
(AS YOU CAN SEE AGAIN I TOOK OFF "--if msgcontains(msg, v.text) and (v.storage == false or player:getStorageValue(v.storage[1]) == v.storage[2]) " BECAUSE I THINK THAT MSGCONTAINS(MSG, V.TEXT) IS THAT MAKES THE NPC SEND THE NEXT MODWINDOW TO THE PLAYER)
How ever with those lines the Npc doesn't do anything when I choose an option from the modWindow, and will only show me the next modWindow if I type myself manually what the choice was...
THANK YOU so much for reading and taking your time for a response, If I can explain anything more clearer please let me know!
So I've been searching this time, done a lot of learning lua, and lurking around the forums to become more and more familiar with Lua and TFS.... and I'm still a lvl 6 no vocation noob at it, so please help me out hehe...
Anyways, I've been trying to change the way you Communicate with the Npc's, and So far from what I've gotten from the forums, I have that you're able to tell the Npc "Hi" and a modWindow will pop up and give you options to choose from. Here's the link/credit to the person who created the script: https://otland.net/threads/tfs-1-2-npc-dialogue-tree.235201/
So, What I wanted to know is that, When you say "Hi", the Npc will show you the modWindow with the list of choices like so:
How ever, in the normal script from the original thread, When you choose an option and click "Select", my character will say the text that the choice carries... So if I choose the first choice my character will say "Who are you?!"
All seems fine and dandy and it works just fine, BUT what I want to do is that when you choose an option, instead of the Npc reading your text, the script goes to the next modWindow that corresponds to the option you chose first.
here's what I have for creaturescripts\scripts\dialogue.lua
Code:
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("",TALKTYPE_SAY)
end
return true
end
(AS YOU CAN SEE I TOOK OFF "--player:say(player:getChoiceText(choiceId),TALKTYPE_SAY)" SO MY CHARACTER WON'T SAY THE TEXT)
Now i'm not sure if the solution is within that script, so here's the other .lua script from npc\scripts\dialogue.lua
Code:
local npc_dialogue = {
[1] = {
message="Look what the darkness emitted.",
choices= {
[1]={text="Who are you?!", storage=false, dialogue=1, script="end"},
[2]={text="Who am I?",storage=false, dialogue=2, script="script1"},
[3]={text="How do I get out of here?",storage={1234,1}, dialogue=3, script="trade"},
[4]={text="...",storage=false, dialogue=3, script="quest"},
[5]={text="...",storage=false, dialogue=false, script="quest2"}}},
[2] = {
message="There is no escape.",
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="You will all die.",
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, "")
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
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
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
player:createDialogueWindowWithButtons(1, npc:getName(), npc_dialogue[v.dialogue].message, defaultButtons, npc_dialogue[v.dialogue].choices, true, false)
end
end
end
return true
end
-- return true
--end
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
(AS YOU CAN SEE AGAIN I TOOK OFF "--if msgcontains(msg, v.text) and (v.storage == false or player:getStorageValue(v.storage[1]) == v.storage[2]) " BECAUSE I THINK THAT MSGCONTAINS(MSG, V.TEXT) IS THAT MAKES THE NPC SEND THE NEXT MODWINDOW TO THE PLAYER)
How ever with those lines the Npc doesn't do anything when I choose an option from the modWindow, and will only show me the next modWindow if I type myself manually what the choice was...
THANK YOU so much for reading and taking your time for a response, If I can explain anything more clearer please let me know!