Jump to content


Photo

BG2: Creating Forced Encounters


11 replies to this topic

#1 Andyr

Andyr

    HELLO EVERYBODY

  • Gibberlings
  • 4534 posts
  • Gender:Male
  • Location:Oxford, UK

Posted 21 February 2004 - 08:40 AM

Note: Apparantly the scripting command I use here is only available in Bg2 - ToB


If you've played BG2, you'll probably remember the one-off encounter with everyone's (least?) favourite drow ranger Drizzt shortly after leaving the Underdark... Would you like to be able to force similar encounters in your mod? I wanted to, and I've figured out a method for doing, and here it is.

Firstly, the resources I used (which you'll probably have anyway) were:

WeiDU http://www.WeiDU.org
Near Infinity http://www.idi.ntnu.no/~joh/ni
The IESDP http://dragonlance.teambg.net/iesdp/
A calculator with a 'hex' function (thoughtfully provided by Windows :D)

I'll start by describing what I myself was trying to do. I was trying to add an encounter which would trigger once when the player had a certain NPC in their party and left the Umar Hills (AR1100), taking them to a custom area of my design (which I called A#book). I did not want it to be possible to return to A#book once you had been there.

The file WORLDMAP.WMP controls random encounter areas and probabilities. Open it up in Near Infinity, and click on the Edit tab. The bottom field should be called Map Entry 0- click on Edit again.

You should be looking at (well, in my copy of BG2 at least) 13 fields, then 24 named Area Entry x and 164 named Area Link x. The IESDP explains each worldmap area has an Area Entry, and each exit from the area has an Area Link. Looking in the Area Entry for AR1100 (number 7), I see this uses Area Link fields 57-66 (it shows which ones are exits North, South, East and West).

Go examine one of them, and look in the IESDP too. You'll notice that all the Area Link entries for AR1100 have None specified in the Random Encounter section: So firstly, we need to fix that. What I'm going to do is use WeiDU to change Random Encounter Area 1 for each area link to read A#book. The IESDP tells us this field is stored at offset 2c in the Area Link, so we add this to the offset of the start of the Area Link and use WRITE_ASCII to fill in our custom area. I did this for all area links from AR1100- I want to make sure the encounter is accessible from wherever you try to go. A couple of points to note:

1. You don't need the .ARE extension for the custom area when you WRITE_ASCII.
2. WeiDU doesn't seem to want to install if you use the number in hexadecimal, so convert your offset back to decimal.
3. The offset between each area link is D8, or 216, so you can simply add this value to work out the offset of the next area link you need to patch.
4. The worldmap file is saved in your save games too. So, to see the changes you make, you need to start a new game after patching WORLDMAP.WMP. I made the mistake of not doing so a few times and was most dismayed why it didn't appear to have worked.

My .TP2 code then looked like this. Note the comments (//text) are purely for my visual aid:

//Creating random encounters from Umar Hills (AR1100, Area links 57-76) to custom area A#book.
COPY_EXISTING ~Worldmap.WMP~ ~override/Worldmap.wmp~
WRITE_ASCII ~18556~ ~A#book~ //link 57
WRITE_ASCII ~18772~ ~A#book~ //link 58
WRITE_ASCII ~18988~ ~A#book~ //link 59
WRITE_ASCII ~19204~ ~A#book~ //link 60
WRITE_ASCII ~19gibberlings3.netgibberlings3.net420~ ~A#book~ //link 61
WRITE_ASCII ~19636~ ~A#book~ //link 62
WRITE_ASCII ~19852~ ~A#book~ //link 63
WRITE_ASCII ~20068~ ~A#book~ //link 64
WRITE_ASCII ~20284~ ~A#book~ //link 65
WRITE_ASCII ~20500~ ~A#book~ //link 66
WRITE_ASCII ~20716~ ~A#book~ //link 67
WRITE_ASCII ~20932~ ~A#book~ //link 68
WRITE_ASCII ~21148~ ~A#book~ //link 69
WRITE_ASCII ~21364~ ~A#book~ //link 70
WRITE_ASCII ~21580~ ~A#book~ //link 71
WRITE_ASCII ~21796~ ~A#book~ //link 72
WRITE_ASCII ~22012~ ~A#book~ //link 73
WRITE_ASCII ~22228~ ~A#book~ //link 74
WRITE_ASCII ~22444~ ~A#book~ //link 75
WRITE_ASCII ~22660~ ~A#book~ //link 76


Note that since there were originally no random encounters from AR1100 the probability of one was set to 0: This is good for us. You may need to set it to 0 yourself if you plan to use an area with existing random encounters, though.

So, now there is an encounter area to link to. You just need to use scripting to trigger it. As I said before, I wanted my encounter to happen the first time party left the Umar Hills with my NPC certain conditions, so I added the following to my NPC's override script. Note I've removed the conditions but left in a global variable to remind you you need to set one to make sure it only happens once!

IF
(Some Conditions)
Global("Set","GLOBAL",0)
THEN
RESPONSE #100
SetGlobal("Set","GLOBAL",1)
SetEncounterProbability("AR1100","AR0700",100)
SetEncounterProbability("AR1100","AR0400",100)
SetEncounterProbability("AR1100","AR0300",100)
SetEncounterProbability("AR1100","AR0500",100)
SetEncounterProbability("AR1100","AR0800",100)
SetEncounterProbability("AR1100","AR0900",100)
SetEncounterProbability("AR1100","AR1000",100)
SetEncounterProbability("AR1100","AR1400",100)
SetEncounterProbability("AR1100","AR1300",100)
SetEncounterProbability("AR1100","AR1200",100)
SetEncounterProbability("AR1100","AR0020",100)
SetEncounterProbability("AR1100","AR1404",100)
SetEncounterProbability("AR1100","AR1304",100)
SetEncounterProbability("AR1100","AR2000",100)
SetEncounterProbability("AR1100","AR1900",100)
SetEncounterProbability("AR1100","AR1700",100)
SetEncounterProbability("AR1100","AR2500",100)
SetEncounterProbability("AR1100","AR2600",100)
SetEncounterProbability("AR1100","AR1800",100)
SetEncounterProbability("AR1100","AR1600",100)
SetEncounterProbability("AR1100","AR2100",100)
SetEncounterProbability("AR1100","AR1500",100)
SetEncounterProbability("AR1100","AR2300",100)
SetEncounterProbability("AR1100","AR2800",100)
END


This sets the probability of encounters from AR1100 to basically anywhere else on the worldmap (as these areas are the other places with Area Entry entries in WORLDMAP.WMP) to 100. And since we've set the custom area A#book as the random encounter area, this is where they'll go. Simple! :D

Finally, you need to at some point set the probabilities of encounters back to 0 to ensure you don't keep revisiting the area. This is again simple:

IF
(Some other conditions)
Global("Set","GLOBAL",1)
THEN
RESPONSE #100
SetGlobal("Set","GLOBAL",2)
SetEncounterProbability("AR1100","AR0700",0)
SetEncounterProbability("AR1100","AR0400",0)
SetEncounterProbability("AR1100","AR0300",0)
SetEncounterProbability("AR1100","AR0500",0)
SetEncounterProbability("AR1100","AR0800",0)
SetEncounterProbability("AR1100","AR0900",0)
SetEncounterProbability("AR1100","AR1000",0)
SetEncounterProbability("AR1100","AR1400",0)
SetEncounterProbability("AR1100","AR1300",0)
SetEncounterProbability("AR1100","AR1200",0)
SetEncounterProbability("AR1100","AR0020",0)
SetEncounterProbability("AR1100","AR1404",0)
SetEncounterProbability("AR1100","AR1304",0)
SetEncounterProbability("AR1100","AR2000",0)
SetEncounterProbability("AR1100","AR1900",0)
SetEncounterProbability("AR1100","AR1700",0)
SetEncounterProbability("AR1100","AR2500",0)
SetEncounterProbability("AR1100","AR2600",0)
SetEncounterProbability("AR1100","AR1800",0)
SetEncounterProbability("AR1100","AR1600",0)
SetEncounterProbability("AR1100","AR2100",0)
SetEncounterProbability("AR1100","AR1500",0)
SetEncounterProbability("AR1100","AR2300",0)
SetEncounterProbability("AR1100","AR2800",0)
END


Thanks to SimDing0 and MaxTeamBG for helping me figure some of this stuff out. :D

Edited by Idobek, 12 April 2004 - 12:13 PM.

Since you're here, download G3 mods please...

Suggested plugs include "Click here so Compton doesn't ban me. http://www.pocketplane.net/ub"

The most reliable way to get hold of me is via email (button when viewing my profile).

#2 NiGHTMARE

NiGHTMARE
  • Modders
  • 2437 posts
  • Gender:Male
  • Location:Hampshire, UK

Posted 21 February 2004 - 09:23 AM

Very interesting and very useful :D

Is it possible to force a random enounter from another random encounter area? For example, in LoI I envision the player first meeting Drizzt, then afterwards being ambushed by the Sythillisians.

Edited by NiGHTMARE, 21 February 2004 - 09:37 AM.


#3 CamDawg

CamDawg

    Just returned from a triumphant carpet-bombing of Eden 7

  • Gibberling Poobah
  • 8867 posts
  • Gender:Not Telling

Posted 21 February 2004 - 09:33 AM

Absolutely. Delainy has three random encounters, split a few days apart from one another.

What makes a good man go neutral? Lust for gold? Power? Or were you just born with a heart full of neutrality?


#4 NiGHTMARE

NiGHTMARE
  • Modders
  • 2437 posts
  • Gender:Male
  • Location:Hampshire, UK

Posted 21 February 2004 - 09:38 AM

Excellent :D Though you'd have to be careful when doing this, otherwise you could end up in an infinite loop :D

#5 CamDawg

CamDawg

    Just returned from a triumphant carpet-bombing of Eden 7

  • Gibberling Poobah
  • 8867 posts
  • Gender:Not Telling

Posted 21 April 2005 - 09:39 AM

One thing I've been meaning to add to this discussion is the idea that I believe the engine "reads ahead" for additional information for random encounters. AR2601, Drizzt's random encounter area, is set at a 100% probability when traveling from the Underdark Exit to the City Gates. (Excluding the three wilderness areas, going anywhere from the Underdark Exit necessitates traveling this link due to the setup of the worldmap.) However, you only encounter Drizzt once, the first time you travel this link. Nothing ever reduces the random encounter probability down from 100%, so there must be another reason why you only visit AR2601 once.

My theory, consistent with my observations but in no way rigorously tested, is that the engine reads ahead to the random encounter area. If it evaluates the probability of an encounter to true, it checks the area script of the random encounter area. If it can find a script block with a true OnCreation() block, then an actual random encounter occurs. If no OnCreation() blocks are true, then no random encounter occurs--this is why you only have a set number of random encounters, even travelling around Athkatla, and why you only encounter Drizzt once.

What makes a good man go neutral? Lust for gold? Power? Or were you just born with a heart full of neutrality?


#6 Andyr

Andyr

    HELLO EVERYBODY

  • Gibberlings
  • 4534 posts
  • Gender:Male
  • Location:Oxford, UK

Posted 21 April 2005 - 10:07 AM

Sim thinks the encounter probability is 101%, which means "trigger only once" apparantly. :undecided:

Also, SC is going to add some better .WMP patching code when he has tested it.
Since you're here, download G3 mods please...

Suggested plugs include "Click here so Compton doesn't ban me. http://www.pocketplane.net/ub"

The most reliable way to get hold of me is via email (button when viewing my profile).

#7 SConrad

SConrad

    Spellhold Director

  • Fixpackers
  • 257 posts
  • Gender:Male
  • Location:Melbourne, Australia

Posted 21 April 2005 - 10:09 AM

We were talking about this in chat, and mr. Ding0 said:

(19:32:28) (SimDing0) You don't need to fuck around with SetEncounterProbability. If you set the encounter probability to 101, it occurs once, then never again.

EDIT: What's with all these double-posts today?

Edited by SConrad, 21 April 2005 - 10:10 AM.


#8 SConrad

SConrad

    Spellhold Director

  • Fixpackers
  • 257 posts
  • Gender:Male
  • Location:Melbourne, Australia

Posted 21 April 2005 - 10:21 AM

Okay, well. Just checked my coding, it works like a charm.

I can't be bothered to explain every little detail in it now, all the other tp2-ninjas will understand what I'm doing, and the rest can ask and I will answer. :undecided:

EDIT: Oh, yeah, I better put in the disclaimer I did somewhere else:

Note that I coded this before I actually realised that there is a "# of area entries" inside the .wmp, and I was too proud over my own code for keeping track on the number of area entries to change it. I did add an additional check, though. Also note that I added a check for the area from G3A. I dunno if there's any other mods adding areas to the worldmap which doesn't use AR****.are, but I'll add them if needed.

// Update the worldmap to make sure the random encounter in between Waukeen and Slums happens
COPY_EXISTING ~worldmap.wmp~ ~override~
  READ_LONG 0xc "map_off"
  SET "entry"       = ("%map_off%" + 0xb8)
  SET "outer_check" = 0
  SET "inner_check" = 0
  SET "num_ent"     = 0
  WHILE ("%outer_check%" = 0) BEGIN
    READ_ASCII ("%entry%" + 0x8) "area" (2)
    READ_ASCII ("%entry%" + 0x8) "spec_area" (6)
    WHILE (("%spec_area%" STRING_COMPARE_CASE "AR0700" = 0) AND ("%inner_check%" = 0)) BEGIN
      READ_SHORT ("%entry%" + 0x50)                   "nlink"
      READ_SHORT ("%entry%" + 0x50 + 0x8)             "wlink"
      READ_SHORT ("%entry%" + 0x50 + 0x8 + 0x8)       "slink"
      READ_SHORT ("%entry%" + 0x50 + 0x8 + 0x8 + 0x8) "elink"
      SET "inner_check" = 1
    END
    PATCH_IF (("%area%" STRING_COMPARE_CASE "AR" = 0) OR ("%area%" STRING_COMPARE_CASE "G3" = 0)) BEGIN
      SET "num_ent" = ("%num_ent%" + 1)
    END ELSE
    PATCH_IF ("%area%" STRING_COMPARE_CASE "AR" = 1) BEGIN
      SET "outer_check" = 1
    END
    SET "entry" = ("%entry%" + 0xf0)
  END
  SET "patching_done" = 0
  READ_LONG  0x30 "area_num"
  WHILE (("%patching_done%" = 0) AND ("%num_ent%" = "%area_num%")) BEGIN
    SET "1stlink" = (("%map_off%" + 0xb8) + ("%num_ent%" * 0xf0) + ("%nlink%" * 0xd8))
    SET "2ndlink" = (("%map_off%" + 0xb8) + ("%num_ent%" * 0xf0) + ("%wlink%" * 0xd8))
    SET "3rdlink" = (("%map_off%" + 0xb8) + ("%num_ent%" * 0xf0) + ("%slink%" * 0xd8))
    SET "4thlink" = (("%map_off%" + 0xb8) + ("%num_ent%" * 0xf0) + ("%elink%" * 0xd8))
    PATCH_IF ("1stlink" > 0) BEGIN
      WRITE_ASCII ("%1stlink%" + 0x2c) ~ARSC#0~
      WRITE_SHORT ("%1stlink%" + 0x54) 101
    END
    PATCH_IF ("2ndlink" > 0) BEGIN
      WRITE_ASCII ("%2ndlink%" + 0x2c) ~ARSC#0~
      WRITE_SHORT ("%2ndlink%" + 0x54) 101
    END
    PATCH_IF ("3rdlink" > 0) BEGIN
      WRITE_ASCII ("%3rdlink%" + 0x2c) ~ARSC#0~
      WRITE_SHORT ("%3rdlink%" + 0x54) 101
    END
    PATCH_IF ("4thlink" > 0) BEGIN
      WRITE_ASCII ("%4thlink%" + 0x2c) ~ARSC#0~
      WRITE_SHORT ("%4thlink%" + 0x54) 101
    END
    SET "patching_done" = 1
  END
BUT_ONLY_IF_IT_CHANGES

Edited by SConrad, 21 April 2005 - 10:22 AM.


#9 devSin

devSin
  • Fixpackers
  • 3017 posts
  • Gender:Male

Posted 11 January 2007 - 11:50 AM

Since spam bumped this post, I should point out that the engine handles random encounter probability by (continuously?) subtracting 100 from the encounter probability when the probability is greater than 100. The first time you encounter Drizzt, the random encounter fires and the probability is reduced to 1% (so technically, it should be possible to revisit the encounter area even in the default game).

#10 Bardess

Bardess

    C is the deadliest weapon of all

  • Members
  • 143 posts
  • Gender:Female
  • Location:Serbia, Europe

Posted 11 August 2007 - 09:37 AM

Edit: my installations are killing me. I've changed the "working" place, and the command is there now. ???

Edited by Bardess, 11 August 2007 - 11:47 PM.


#11 Bardess

Bardess

    C is the deadliest weapon of all

  • Members
  • 143 posts
  • Gender:Female
  • Location:Serbia, Europe

Posted 11 August 2007 - 11:48 PM

Thank you for the tutorial. I've yet to test if I did my encounter correctly.

#12 picollo

picollo
  • Members
  • 21 posts

Posted 21 August 2011 - 12:00 AM

I have some questions about Forced Encounters. And believe, that this is the best topic to post them.

1)Nightmare asked:

Is it possible to force a random enounter from another random encounter area?

But how technically is it possible?
encounters are controlled by Worldmap. And technically encounter-areas aren't placed on worldmap. So, we can't set encounter probability from encounter area to destination area.

2)There are four places for setting encounter areas. If I add for example three to one link, what determines, whitch area will be used to encounter?
I can set using weidu probability for each encounter. But can I in-game change probability for only one of thoose encounters?



Reply to this topic



  


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users