Page 1 of 1

DialogModule

Posted: Mon Feb 25, 2019 8:44 pm
by Jabantiz
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.
ABBC3_SPOILER_SHOW
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

Code: Select all

require "SpawnScripts/Generic/DialogModule"
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

Code: Select all

function hailed(NPC, Spawn)
	Dialog.New(NPC, Spawn)
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

Code: Select all

Dialog.AddDialog("Was that all three?")
If the dialog has a voice over we would add it with AddVoiceover()

Code: Select all

Dialog.AddVoiceover("voiceover/english/neriak/calnozz_j_melvirr/darklight_wood/tvatar_post/calnozz/calnozz008_progress.mp3", 1983465757, 3955037985)
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()

Code: Select all

Dialog.AddEmote("cheer")
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()

Code: Select all

Dialog.AddRequirement(REQ_QUEST_HAS_COMPLETED_QUEST, 155)
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.

Code: Select all

local DrawUponWellsprings = 155
...
Dialog.AddRequirement(REQ_QUEST_HAS_COMPLETED_QUEST, DrawUponWellsprings)
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

Code: Select all

Dialog.AddRequirement(REQ_QUEST_ON_STEP, StunningRevelation, 2)
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.

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

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)
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()

Code: Select all

Dialog.AddOption("Yes, I have them here.", "Quest_DustToDust")
Dialog.AddOption("Not Yet")
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

Code: Select all

function Quest_DudtToDust(NPC, Spawn)
end
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()

Code: Select all

Dialog.AddOptionRequirement(REQ_QUEST_NOT_ON_STEP, InfantileIngredients, 2)
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

Code: Select all

Dialog.Start()
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
ABBC3_SPOILER_SHOW

Re: DialogModule

Posted: Mon Feb 25, 2019 8:44 pm
by Jabantiz
Here I will give examples of how to use every type of requirement. These are the types already implemented, others can be added as needed/requested.

I will use Dialog.AddRequirement in the examples but they all work exactly the same for Dialog.AddOptionRequirement, the only difference between the two functions is what it applies the requirement to.

The correct syntax for the function is

Code: Select all

Dialog.AddRequirement(type, value1, value2, value3)
value2 and value3 are optional. If I do not specify what value2 or value3 means for a type then they are not used for that type and should be left off.

REQ_RACE
Checks the players race to see if it matches the given race.
value1 = race id

Code: Select all

Dialog.AddRequirement(REQ_RACE, 8)
REQ_CLASS
Checks the players class to see if it matches the given class.
value1 = calss

Code: Select all

Dialog.AddRequirement(REQ_CLASS, 11)
REQ_LEVEL
Checks the players level to see if it matches the given level.
value1 = level

Code: Select all

Dialog.AddRequirement(REQ_LEVEL, 5)
REQ_LEVEL_GREATER_OR_EQUAL
Checks the players level to see if it is greater than or equal to the given level.
value1 = level

Code: Select all

Dialog.AddRequirement(REQ_LEVEL_GREATER_OR_EQUAL, 5)
REQ_LEVEL_LESS_OR_EQUAL
Checks the players level to see if it is less than or equal to the given level.
value1 = level

Code: Select all

Dialog.AddRequirement(REQ_LEVEL_LESS_OR_EQUAL, 5)
REQ_QUEST_ELIGIBLE
Checks to see if the player can receive the given quest.
value1 = quest id

Code: Select all

Dialog.AddRequirement(REQ_QUEST_ELIGIBLE, 8)
REQ_QUEST_ON_STEP
Checks to see if the player is on the given step of the given quest.
value1 = quest id
value2 = step id

Code: Select all

Dialog.AddRequirement(REQ_QUEST_ON_STEP, 1234, 2)
REQ_QUEST_BEFORE_STEP
Checks to see if the player is on a step before the given quest.
value1 = quest id
value2 = step id, players step must be less then this value to pass the check

Code: Select all

Dialog.AddRequirement(REQ_QUEST_BEFORE_STEP, 1234, 8)
REQ_QUEST_PAST_STEP
Checks to see if the player is past the given step.
value1 = quest id
value2 = step id, players step must be greater then this value to pass the check

Code: Select all

Dialog.AddRequirement(REQ_QUEST_PAST_STEP, 1234, 4)
REQ_QUEST_HAS_QUEST
Checks to see if the player has the given quest.
value1 = quest id

Code: Select all

Dialog.AddRequirement(REQ_QUEST_HAS_QUEST, 1234)
REQ_QUEST_DOESNT_HAVE_QUEST
Checks to see if the player does not have the given quest.
value1 = quest id

Code: Select all

Dialog.AddRequirement(REQ_QUEST_DOESNT_HAVE_QUEST, 1234)
REQ_QUEST_NOT_ON_STEP
Checks to see if the player is not on the given step.
value1 = quest id
value2 = step id, players step must not be the same as this value in order to pass this check

Code: Select all

Dialog.AddRequirement(REQ_QUEST_NOT_ON_STEP, 1234, 3)
REQ_QUEST_HAS_COMPLETED_QUEST
Checks to see if the player has completed the given quest.
value1 = quest id

Code: Select all

Dialog.AddRequirement(REQ_QUEST_HAS_COMPLETED_QUEST, 1234)
REQ_QUEST_NOT_HAS_COMPLETED_QUEST
Checks to see if the player has not completed the given quest.
value1 = quest id

Code: Select all

Dialog.AddRequirement(REQ_QUEST_NOT_HAS_COMPLETED_QUEST, 1234)
REQ_TEMP_VAR_NOT_SET
Checks to see if the temporary variable is not set to the given value on the player.
value1 = temporary variable name
value2 = temporary variable value

Code: Select all

Dialog.AddRequirement(REQ_TEMP_VAR_NOT_SET, "cub", nil)
REQ_TEMP_VAR_SET
Checks to see if the temporary variable is set to the given value on the player.
value1 = temporary variable name
value2 = temporary variable value

Code: Select all

Dialog.AddRequirement(REQ_TEMP_VAR_SET, "foo", "bar")
REQ_LUA_HISTORY_SET
Checks to see if the lua history is set to the given value(s) on the player
value1 = lua history id
value2 = lua history value1
value2 = lua history value2, not all lua history has a value2 so this parameter is optional and can be left off

Code: Select all

Dialog.AddRequirement(REQ_LUA_HISTORY_SET, 1234, 5678)
REQ_LUA_HISTORY_NOT_SET
Checks to see if the lua history is not set to the given value(s) on the player
value1 = lua history id
value2 = lua history value1
value2 = lua history value2, not all lua history has a value2 so this parameter is optional and can be left off

Code: Select all

Dialog.AddRequirement(REQ_LUA_HISTORY_NOT_SET, 123, 456, 789)
REQ_LOCATION_ID
Checks to see if the NPC's location id matches the given value
value1 = location id

Code: Select all

Dialog.AddRequirement(REQ_LOCATION_ID, 1234)
REQ_TSLEVEL
Checks the players level to see if it matches the given level.
value1 = level

Code: Select all

Dialog.AddRequirement(REQ_TSLEVEL, 5)
REQ_TSLEVEL_GREATER_OR_EQUAL
Checks the players level to see if it is greater than or equal to the given level.
value1 = level

Code: Select all

Dialog.AddRequirement(REQ_TSLEVEL_GREATER_OR_EQUAL, 5)
REQ_TSLEVEL_LESS_OR_EQUAL
Checks the players level to see if it is less than or equal to the given level.
value1 = level

Code: Select all

Dialog.AddRequirement(REQ_TSLEVEL_LESS_OR_EQUAL, 5)

Re: DialogModule

Posted: Mon Feb 25, 2019 9:09 pm
by neatz09
Great write up and thank you much jabantiz

Re: DialogModule

Posted: Mon Feb 25, 2019 9:24 pm
by Cynnar
Very nice! Hope it helps scripting, and those wanting to give it a try.

To add to this, Jabantiz has mentioned You can also use variables for the id part and in fact it is preferred that you do. This will become standard eventually, and it will help us update scripts faster in the future, and make scripts even easier to read.

If you need more examples let us know and we will get some posted up.

Re: DialogModule

Posted: Mon Feb 25, 2019 10:53 pm
by Jabantiz
Updated the second post with examples of all the requirement types.

Re: DialogModule

Posted: Sat Aug 20, 2022 1:24 am
by Ememjr
Updated post and dialog module to add Tradeskill requirements

Re: DialogModule

Posted: Sat Aug 20, 2022 1:26 am
by Ememjr
Updated post and dialog module to add Tradeskill requirements