Multiple dialogue

I want to do something where when the player clicks "talk to" to a specific character then each time it's clicked it can scroll through a series of three phrase. So like the first time you click "talk to" it says something, the second time you click it, it says something else, the third time you click it says another thing, and when you click it for the fourth time it goes back to the first piece of dialogue. I want to know how I can make it change the dialogue with each click.


You'd want to use an attribute to count how many times you talked to the guy. So the speak to/talk to verb script would look something like this:

if (not HasInt (this, "times_talked")) {
  msg ("This is the first thing the guy says.")
  this.times_talked = 1
}
else if (this.times_talked = 1) {
  msg ("This is the second thing the guy says.")
  this.times_talked = 2
}
else {
  msg ("This is the last thing the guy says.")
  this.times_talked = null
}

The first time, there is no times_talked attribute, so we check for not HasInt. For the others, we check the number. If there were more than 3 options to cycle through, you would put extra else if cases before the final else. For example:

if (not HasInt (this, "times_talked")) {
  msg ("This is the first thing the guy says.")
  this.times_talked = 1
}
else if (this.times_talked = 1) {
  msg ("This is the second thing the guy says.")
  this.times_talked = 2
}
else if (this.times_talked = 2) {
  msg ("This is the third thing the guy says.")
  this.times_talked = 3
}
else if (this.times_talked = 3) {
  msg ("This is the fourth thing the guy says.")
  this.times_talked = 4
}
else {
  msg ("This is the last thing the guy says.")
  this.times_talked = null
}

Or if you have a lot of options, it might be easier to use 'switch'.

if (HasInt (this, "times_talked")) {
  this.times_talked = (this.times_talked % 3) + 1
}
else {
  this.times_talked = 1
}

switch (this.times_talked) {
  case (1) {
    msg ("This is the first thing the guy says.")
  }
  case (2) {
    msg ("This is the second thing the guy says.")
  }
  case (3) {
    msg ("This is the third thing the guy says.")
  }
}

In this case, the else clause sets the attribute to 1 the first time, and % 3 causes the attribute to cycle through the numbers 1, 2, 3, 1, 2, 3, 1, 2, 3…

Another alternative method would be to give the NPC a stringlist attribute containing all his dialogue; but that's likely more than you need, unless you're going to be adding and removing lines from the cycle in response to other events.

(If you'd prefer explanations using the script-editing GUI, just click code view for the verb and paste the code in, then you can see what it looks like in the GUI)


These are the scripts I use.
On the character you want to speak to, add an attribute called, 'thingstosay' and make it a stringlist.
Then add the responses to the stringlist one at a time.

Then your verb script of 'talk to or speak to looks like this. (My example is for an Orc guard)

if (ListCount(orc_guard.thingstosay) = 0) {
  msg ("<br>Org says,<br>\"<i>That's all I have for now.\"")
}
else {
  line = PickOneString(orc_guard.thingstosay)
  msg ("<br>Org says, <br><i>" + line)
  list remove (orc_guard.thingstosay, line)
}

This will randomly select one of the strings and print it out.
It also deletes it from the stringlist so it will not show again. It feeds pertinent information to the player. Until all lines are removed and then it tells the player. "That's all I have for now".
You can add additional lines using:

list add (orc_guard.thingstosay, "Whatever text you want to add")

What if you have certain flags that you want to add into the conversation?
Let's say the guard can tell the player about a prisoner being held in the dungeon.
Then the verb would look like this.

if (ListCount(orc_guard.thingstosay) = 0) {
  msg ("<br>Org says,<br>\"<i>That's all I have for now.\"")
}
else if (orc_guard.toldaboutvivian = True) {
  line = PickOneString(orc_guard.thingstosay)
  msg ("<br>Org says, <br><i>" + line)
  list remove (orc_guard.thingstosay, line)
}
if (orc_guard.toldaboutvivian = False) {
  orc_guard.toldaboutvivian = True
  vivian.alias = "Vivian"
  msg ("<br>Org says,<br><i>\"In the town of Carn, Lord Talbert sent for his daughter, Vivian, but we stopped her coach and kidnapped her just north of here by the foothills of Shankspur Mountains, she is being held here in the prison hall.\"<br><br/><i>He gives you a blank look.<i/>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        ")
}

Just add a boolean attribute to the orc guard called 'toldaboutvivian' and set it to False.
The alias of the woman being held was 'woman' but now if the orc tells the player about her when the player finds her, she will be shown as 'Vivian' instead of 'woman'.
Just a simple example.


Log in to post a reply.

Support

Forums