Author Topic: State Weights - by Japheth  (Read 21130 times)

Offline Ghreyfain

  • Moderator
  • Planewalker
  • *****
  • Posts: 4705
  • Gender: Male
    • Pocket Plane Group
State Weights - by Japheth
« on: April 01, 2004, 06:25:30 PM »
In certain dialogues in BG2/TOB (and possibly IWD/PST as well, I'm not sure) the dialogues are made using weighted systems.  Celogan.dlg is an example of one of them, and there are many more.

You can take a look at the decompiled celogan .d file here.

The first thing you'll notice is the warning you get.  It tells you right off that the dialog file contains non-trivial weights.

Now, I'll explain how it works.

If you take a look at State #88 in that URL I posted above you'll see this:


IF WEIGHT #16 /* Triggers after states #: 92 95 even though they appear after this state */
~Global("feudplot","GLOBAL",1)
!Dead("trfued01")
!Dead("trfued05")
Global("Loganmantle","GLOBAL",1)~ THEN BEGIN 88 // from:
  SAY ~Greetings, <CHARNAME>, how goes the... quest in the tomb?  Do you bring the mantle to me, so that this feud of the Lurraxols and the Alibakkars may be ended?~ /* #47095 */
  IF ~~ THEN REPLY ~No, I do not have the mantle with me.~ /* #47096 */ GOTO 89
  IF ~PartyHasItem("misc8l")~ THEN REPLY ~I have the mantle, but I cannot give it to you, Lord Logan.~ /* #47097 */ GOTO 90
  IF ~PartyHasItem("misc8l")~ THEN REPLY ~Yes, I have the mantle... take it so that my involvement with these families is done.~ /* #47098 */ DO ~TakePartyItem("misc8l")~ GOTO 91
END


Now if you look at State #92, you'll see this:


IF WEIGHT #5 ~Dead("cefald01")
Global("LoganMad","GLOBAL",0)
Global("GrovePoisoned","GLOBAL",1)
~ THEN BEGIN 92 // from:
  SAY ~By Torm, <CHARNAME>! I have just received word! What have you done?? Are you mad?~ /* #50665 */
  IF ~~ THEN REPLY ~What seems to be the problem, Lord Coprith?~ /* #50667 */ GOTO 93
  IF ~~ THEN REPLY ~I've taken care of your druid problem. They won't be bothering you again.~ /* #56478 */ GOTO 93
END


Now, if feudplot was 1, trfued01 wasn't dead, trfued05 wasn't dead, LoganMantle was 1, cefald01 was dead, LoganMad was 0 and GrovePoisoned was 1 (basically all the conditions for both states were met), State #92 would trigger *before* State #88 because it's weight takes precedence over State #88's weight.


WeiDU will preserve the conditional weighting in the dialog and you can still append and add state and transition triggers par normal.  You can also set state weights with WeiDU as well if you think it's needed (although I don't recommend using SET WEIGHT).
Earn Money Sleeping.

Offline Awake

  • Enigma
  • Planewalker
  • *****
  • Posts: 56
  • Gender: Male
  • The Raven
    • Black Wyrm Lair Forums
Re: State Weights - by Japheth
« Reply #1 on: September 07, 2004, 08:50:23 PM »
Ghreyfain (or did Japheth do this), i love your tutorials ;D, but i just don't understand this one. If you could direct me to a stronger one, more directed at someone who has no idea what he is reading, that would be great, or if you could just add on to this one a little bit, thanks.
« Last Edit: September 07, 2004, 08:53:59 PM by Awake »

Offline icelus

  • Global Moderator
  • Planewalker
  • *****
  • Posts: 3173
  • Gender: Male
Re: State Weights - by Japheth
« Reply #2 on: September 07, 2004, 08:54:06 PM »
<Moongaze> Luckily BWL has a very understanding and friendly admin.

Offline Awake

  • Enigma
  • Planewalker
  • *****
  • Posts: 56
  • Gender: Male
  • The Raven
    • Black Wyrm Lair Forums
Re: State Weights - by Japheth
« Reply #3 on: September 08, 2004, 07:05:49 PM »
yeah, i tried that one, but i don't get it still. well, i get the idea but that's it. I'm working on some dialogue right now, and i need to know if this will be important, i don't know how to incorporate it or anything. :'(

Actually, i don't think i even get the idea, i get the idea, but i don't get the idea. Why is it necessary to set weights? Doesn't the dialogue just go by the conditions, like NumTimesTalkedTo(0) or !StateCheck(...) or those kinds of things? I really don't think i understand. Please help. Somebody, anybody.  :'(
« Last Edit: September 10, 2004, 06:19:05 PM by Awake »

guest

  • Guest
Re: State Weights - by Japheth
« Reply #4 on: September 18, 2004, 08:25:37 PM »
I think the poster is making it more complicated than it is.

I must say that I haven't done any dialog scripting, but you don't have to use weights.  I think weights are used to give a dialog more precedence over others.  Yes, the dialogs go by the conditions.  But what if conditions for two different dialogs are met at the same time?  Then the dialog with less weight will show.

For example:
==================
IF
 true()
blah blah 1

IF
 true()
blah blah 2
===================
Since both conditions for the dialogs are true, and only one dialog will show, the blah blah 1 dialog will show because it appears first.

example:
==================
IF WEIGHT #10
 true()
blah blah 1

IF WEIGHT #1
 true()
blah blah 2
===================
This time, since both conditions are true again, the blah blah 2 dialog will show because it has less weight (less weight = higher priority).

Hope this helps.

Offline Awake

  • Enigma
  • Planewalker
  • *****
  • Posts: 56
  • Gender: Male
  • The Raven
    • Black Wyrm Lair Forums
Re: State Weights - by Japheth
« Reply #5 on: September 18, 2004, 08:52:32 PM »
thank you. i understand it perfectly now. That was exactly what i needed

ScriptKiddie

  • Guest
Re: State Weights - by Japheth
« Reply #6 on: January 23, 2005, 09:55:59 AM »
I'm not sure I'm understanding yet. In the following dialog from Bentley (Friendly Arms Inn) I'm not sure I see how the last dialog path is ever accomplished. As I understood the above, it would first check WEIGHT #0 (Bad reputation), then WEIGHT #2 (50/50 chance), then WEIGHT #3 (Always true), before proceeding onto the unweighted option. But since it should always stop at WEIGHT #3, I don't see how that dialog ever happens.

Thanks.



IF WEIGHT #2 /* Triggers after states #: 2 even though they appear after this state */
~RandomNum(2,1)
~ THEN BEGIN 0 // from:
  SAY #1467 /* ~Iron is the lifeblood of this whole region and it's sure painful when it gets scarce.  So what can I do for ya?~ */
  IF ~~ THEN REPLY #15248 /* ~What do you have to sell?~ */ DO ~StartStore("friend",LastTalkedToBy())~ JOURNAL #6615 /* ~Bentley, the owner of the Friendly Arm inn, told us that the iron trade has slowed greatly over the past few weeks.~ */ EXIT
  IF ~~ THEN REPLY #15249 /* ~Nothing for me today.~ */ DO ~~ EXIT
END

IF WEIGHT #3 /* Triggers after states #: 2 even though they appear after this state */
~True()
~ THEN BEGIN 1 // from:
  SAY #1468 /* ~None too many travelers have been through lately, what with the supposed troubles down south.   So what can I do for ya?~ */
  IF ~~ THEN REPLY #15251 /* ~What do you have to sell me?~ */ DO ~StartStore("friend",LastTalkedToBy())~ JOURNAL #6616 /* ~Bentley told us that there has been some sort of trouble in the south.  Perhaps we should go to Nashkel?~ */ EXIT
  IF ~~ THEN REPLY #15252 /* ~Nothing today thank you.~ */ DO ~~ EXIT
END

IF WEIGHT #0 ~ReactionLT(LastTalkedToBy(),NEUTRAL_LOWER)
~ THEN BEGIN 2 // from:
  SAY #1469 /* ~Sorry, I'm right out of the cheap stuff.   So what can I do for ya?~ */
  IF ~~ THEN DO ~StartStore("friend",LastTalkedToBy())~ EXIT
END

IF ~~ THEN BEGIN 3 // from:
  SAY #1470 /* ~Things haven't been very busy as of late, with all the troubles in the south.  I've heard though, that the mines at Nashkel have been re-opened.  Some heroic folk dealt with whatever was plaguing the mine. So what can I do for ya?~ */
  IF ~~ THEN REPLY #15259 /* ~What do you have to sell me?~ */ DO ~StartStore("friend",LastTalkedToBy())~ EXIT
  IF ~~ THEN REPLY #15260 /* ~Nothing for today.~ */ EXIT
END


ScriptKiddie

  • Guest
Re: State Weights - by Japheth
« Reply #7 on: January 23, 2005, 10:05:52 AM »
Oh, and if I understood guest properly, one could have avoided using weights at all by simply placing the Bad Reputation check first?

Thanks again.

Offline Kismet

  • Devil's Minion #5
  • Global Moderator
  • Planewalker
  • *****
  • Posts: 653
  • Gender: Female
  • Veni; Vidi; Velcro.
    • Pocket Plane Group
Re: State Weights - by Japheth
« Reply #8 on: January 23, 2005, 10:15:39 AM »
Do you actually get state 3 in game?  I can't see how you could, WEIGHT not withstanding, since it has no state triggers and could never return true, unless it's called by another state that is.  Of course I haven't done any modding for BG1 so perhaps things work differently there.
Cailean - An archer NPC for the insatiably nosy!  Guaranteed more fun than shampooing cats!

Offline Ghreyfain

  • Moderator
  • Planewalker
  • *****
  • Posts: 4705
  • Gender: Male
    • Pocket Plane Group
Re: State Weights - by Japheth
« Reply #9 on: January 23, 2005, 10:19:37 AM »
Kismet's right.  A state without a trigger never appears as a top-level dialogue (i.e. you click them and that's what you get), it can only be seen as a reply to a PC reply, or otherwise being GOTO'ed. :)

IF ~~ replystate
  SAY ~Even though this state is at the top, it won't appear right off the bat.~
  IF ~~ THEN EXIT
END

IF ~True()~ FirstState
  SAY ~Yo.  The player just clicked me and this is the dialogue that will appear first.  After you hit enter, it'll GOTO the state named "replystate".~
  IF ~~ THEN GOTO replystate
END
Earn Money Sleeping.

ScriptKiddie

  • Guest
Re: State Weights - by Japheth
« Reply #10 on: January 23, 2005, 04:30:25 PM »
Thanks for the quick responses!

We just started playing again after a long time off. I don't recall ever hearing Bentley getting to State 3, and as I was reading the script, I couldn't figure out how it could play. I did a bunch of stuff trying to get it to play, and couldn't. Presumably, then Black Isle messed up the script?

So if I'm following the discussion, if BI had placed State#2 at the top, then all weighting would have been superflous? I exported, then WeiDU'd Bent2.cre and Frnd2.sto and the script seemed to operate the same way, but I'm a little afraid that there is a reason that BI used weights instead of just order of blocks in the script, and misunderstanding their rationale wil mess up the modding I'm dinking with.

Thanks!

Offline Ghreyfain

  • Moderator
  • Planewalker
  • *****
  • Posts: 4705
  • Gender: Male
    • Pocket Plane Group
Re: State Weights - by Japheth
« Reply #11 on: January 23, 2005, 11:49:35 PM »
They had different tools for editing dialogues than WeiDU, I recall David Gaider saying once upon a time.

Basically, it had four "levels" you could put your state into, and beyond that I imagine they would just play in the order you wrote them in.

So if they decided, after the fact, that they wanted State 2 to run before State 0 and 1, they'd just shuffle State 0 and 1 into the second weight level.  Or something.  Who knows.
Earn Money Sleeping.

 

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Name: Email:
Verification:
Type the letters shown in the picture
Listen to the letters / Request another image
Type the letters shown in the picture:
What color is grass?:
What is the seventh word in this sentence?:
What is five minus two (use the full word)?: