DialogModule
Posted: Mon Feb 25, 2019 8:44 pm
This is an attempt to make scripting dialog in the spawn scripts easier for those who are not use to scripting. All this really does is hide the logic from the scripter so all they have to do is set it up and add the requirements for the specific dialog.
Here is a simple example, for a complete comparison of a hailed function check the spoiler at the end of the post.
This is not required to use and the original way will still work for those who choose to not use this. For server admins who wish to use this on their server you will need to get the DialogModule.lua script from content svn.
Now how to actually use this, first thing you need to do in your spawn script is to include it at the top of the file
Now it is ready to use so when you want to create a dialog, for example in the hailed function, you need to call New() to set it up
The first parameter is the NPC that will be talking, the second parameter is the player they will be talking to. This needs to be called first in every function that will be using the dialog module for conversations.
The next step would be to add a dialog with AddDialog(), this will be what the npc says to the player
If the dialog has a voice over we would add it with AddVoiceover()
The first parameter is the voice file, the second and third parameters are the key's required to play the file. All three parameters need to be set, in the event the file does not use keys then set the parameter 2 and 3 to 0. Again this function only needs to be used if this dialog line has a voice over. It will also be applied to the the last dialog you added with AddDialog()
If the NPC plays an emote when they say this dialog we can add that with AddEmote()
This takes a string and should match the slash commands you would use in game to use the emote yourself. This is only needed if the NPC plays an emote. It will also be applied to the the last dialog you added with AddDialog()
We can only show this dialog if the player meets certain requirements by using AddRequirement()
The first parameter is the requirement type, the second parameter is a value. In this case the player will have to have completed the quest with id of 155. You can also use variables for the id part and in fact it is preferred that you do.
The AddRequirement() function can take up to 3 values depending on what type you use, for example an "on quest step" requirement would need the quest id and step so it needs two values and looks like this
The first parameter is always the requirement type, the second parameter is the first value, in this case the quest id, and the third parameter is the second value, in this case the step id.
Here is all the currently supported requirement types.
You can use this function as many times as you want but the player will have to pass ALL of them in order to see this dialog. For example
AddRequirement() will only be applied to the the last dialog you added with AddDialog()
To add an option to the dialog you would use AddOption()
You can use this multiple times to add multiple options. The first parameter is the choice the player will see, the second parameter is the callback function and is optional, if left off then when the player selects that choice it will close the dialog. The callback function must be in the spawn script as well, so in this case the spawn script must contain the following function
AddOption() will only be applied to the the last dialog you added with AddDialog()
We can also add requirements to options so they are only displayed when the player passes the check, for this we use AddOptionRequirement()
This works exactly the same ass AddRequirement() except it will only apply to the last option you added with AddOption().
Finally when you are done setting up your dialog you will call Start() to show it to the player
A few things to keep in mind.
The order you add dialogs matters. Requirements will be checked from the first dialog added to last and as soon as it finds a dialog it can display it will not bother checking the following dialogs. So if you have a dialog that has no requirements then it should be the very last one you add just before you call Start()
Any requirements you add the player has to pass ALL of them in order to see the dialog or option they are assigned to.
Here is a comparison of a script I updated to use the DialogModule
Here is a simple example, for a complete comparison of a hailed function check the spoiler at the end of the post.
ABBC3_SPOILER_SHOW
Now how to actually use this, first thing you need to do in your spawn script is to include it at the top of the file
Code: Select all
require "SpawnScripts/Generic/DialogModule"
Code: Select all
function hailed(NPC, Spawn)
Dialog.New(NPC, Spawn)
The next step would be to add a dialog with AddDialog(), this will be what the npc says to the player
Code: Select all
Dialog.AddDialog("Was that all three?")
Code: Select all
Dialog.AddVoiceover("voiceover/english/neriak/calnozz_j_melvirr/darklight_wood/tvatar_post/calnozz/calnozz008_progress.mp3", 1983465757, 3955037985)
If the NPC plays an emote when they say this dialog we can add that with AddEmote()
Code: Select all
Dialog.AddEmote("cheer")
We can only show this dialog if the player meets certain requirements by using AddRequirement()
Code: Select all
Dialog.AddRequirement(REQ_QUEST_HAS_COMPLETED_QUEST, 155)
Code: Select all
local DrawUponWellsprings = 155
...
Dialog.AddRequirement(REQ_QUEST_HAS_COMPLETED_QUEST, DrawUponWellsprings)
Code: Select all
Dialog.AddRequirement(REQ_QUEST_ON_STEP, StunningRevelation, 2)
Here is all the currently supported requirement types.
Code: Select all
REQ_RACE
REQ_CLASS
REQ_LEVEL
REQ_LEVEL_GREATER_OR_EQUAL
REQ_LEVEL_LESS_OR_EQUAL
REQ_QUEST_ELIGIBLE
REQ_QUEST_ON_STEP
REQ_QUEST_BEFORE_STEP
REQ_QUEST_PAST_STEP
REQ_QUEST_HAS_QUEST
REQ_QUEST_DOESNT_HAVE_QUEST
REQ_QUEST_NOT_ON_STEP
REQ_QUEST_HAS_COMPLETED_QUEST
REQ_QUEST_NOT_HAS_COMPLETED_QUEST
REQ_TEMP_VAR_NOT_SET
REQ_TEMP_VAR_SET
REQ_LUA_HISTORY_SET
REQ_LUA_HISTORY_NOT_SET
REQ_LOCATION_ID
REQ_TSLEVEL
REQ_TSLEVEL_GREATER_OR_EQUAL
REQ_TSLEVEL_LESS_OR_EQUAL
Code: Select all
Dialog.AddDialog("Did you collect them?")
Dialog.AddRequirement(REQ_QUEST_HAS_COMPLETED_QUEST, StunningRevelation)
Dialog.AddRequirement(REQ_QUEST_DOESNT_HAVE_QUEST, InfantileIngredients)
Dialog.AddRequirement(REQ_QUEST_NOT_HAS_COMPLETED_QUEST, InfantileIngredients)
To add an option to the dialog you would use AddOption()
Code: Select all
Dialog.AddOption("Yes, I have them here.", "Quest_DustToDust")
Dialog.AddOption("Not Yet")
Code: Select all
function Quest_DudtToDust(NPC, Spawn)
end
We can also add requirements to options so they are only displayed when the player passes the check, for this we use AddOptionRequirement()
Code: Select all
Dialog.AddOptionRequirement(REQ_QUEST_NOT_ON_STEP, InfantileIngredients, 2)
Finally when you are done setting up your dialog you will call Start() to show it to the player
Code: Select all
Dialog.Start()
The order you add dialogs matters. Requirements will be checked from the first dialog added to last and as soon as it finds a dialog it can display it will not bother checking the following dialogs. So if you have a dialog that has no requirements then it should be the very last one you add just before you call Start()
Any requirements you add the player has to pass ALL of them in order to see the dialog or option they are assigned to.
Here is a comparison of a script I updated to use the DialogModule
ABBC3_SPOILER_SHOW