Author Topic: Inserting (another) item into an area (tp2 patching)...  (Read 2567 times)

Offline jastey

  • Global Moderator
  • Planewalker
  • *****
  • Posts: 1524
  • Gender: Female
Inserting (another) item into an area (tp2 patching)...
« on: October 01, 2010, 04:49:13 PM »
How would I insert here another item "UBSCARIN" right next to the item "UBFEBODY", does anyone know how to patch the area and could write the code for me without his head exploding? I think I don't even understand what is done here, do I see it correctly that the existing item "%tutu_var%MISC80" is being replaced?

Code: [Select]
COPY_EXISTING ~%ESewers%.ARE~ ~override~
PATCH_IF (SOURCE_SIZE > 0xd4) BEGIN
  READ_LONG 0x70 contOff  // Offset to containers
  READ_LONG 0x78 itmOff   // Offset to item list
  FOR (READ_SHORT 0x74 numCont; numCont; numCont -= 0x1) BEGIN
    READ_ASCII contOff contName (11)   // Container name
    READ_SHORT contOff + 0x20 contXloc // Container X location
    READ_SHORT contOff + 0x22 contYloc // Container Y location
    // Check by name and location, in case name is modified by FotD
    PATCH_IF (!("%contName%" STRING_COMPARE_CASE "CONTAINER 1") ||
              ((contXloc == 827) && (contYloc == 1509))) BEGIN
      READ_LONG contOff + 0x40 itmIdx // Index of first item in list
      myItmOff = itmOff + (itmIdx * 0x14)
      FOR (READ_LONG contOff + 0x44 itmCnt; itmCnt; itmCnt -= 0x1) BEGIN
        READ_ASCII myItmOff itmRef // Item resource reference
        PATCH_IF !("%itmRef%" STRING_COMPARE_CASE "%tutu_var%MISC80") BEGIN
          WRITE_ASCII myItmOff UBFEBODY
        END
        myItmOff += 0x14
      END
    END ELSE
    PATCH_IF (!("%contName%" STRING_COMPARE_CASE "CONTAINER 4") ||
              ((contXloc == 398) && (contYloc == 1414))) BEGIN
      READ_LONG contOff + 0x40 itmIdx // Index of first item in list
      READ_LONG contOff + 0x44 itmCnt // Number of items
      READ_SHORT 0x76 numItm  // Total number of items
      myItmOff = itmOff + (itmIdx * 0x14)
      PATCH_RANDOM_SEED myItmOff << (numItm / itmCnt)
      bodyCount = 0x0
      // Make sure there's more than one body before deciding which to replace
      FOR (i = itmCnt; i; i -= 0x1) BEGIN
        READ_ASCII myItmOff itmRef // Item resource reference
        PATCH_IF !("%itmRef%" STRING_COMPARE_CASE "%tutu_var%MISC80") BEGIN
          bodyCount += 0x1 // Count those bodies!
        END
        myItmOff += 0x14
      END
      PATCH_IF (bodyCount) BEGIN
        PATCH_IF (bodyCount > 1) BEGIN
          theBody = RANDOM(1 bodyCount) // Random body replacement
        END ELSE theBody = 0x1
        myItmOff = itmOff + (itmIdx * 0x14)
        bodyCount = 0x1
        FOR (i = itmCnt; i; i -= 0x1) BEGIN
          READ_ASCII myItmOff itmRef // Item resource reference
          PATCH_IF !("%itmRef%" STRING_COMPARE_CASE "%tutu_var%MISC80") BEGIN
            PATCH_IF (bodyCount == theBody) BEGIN
              WRITE_EVALUATED_ASCII myItmOff ~%tutu_var%MISC79~ #8 // Female body
            END
            bodyCount += 0x1
          END
          myItmOff += 0x14
        END
      END
    END
    contOff += 0xc0
  END
END
BUT_ONLY_IF_IT_CHANGES

Offline Mike1072

  • Planewalker
  • *****
  • Posts: 298
  • Gender: Male
Re: Inserting (another) item into an area (tp2 patching)...
« Reply #1 on: October 01, 2010, 06:52:44 PM »
It looks like that code swaps all male bodies (~%tutu_var%misc80~) in Container 1 with UBFEBODY.  (There's only one male body in the container by default.)  The code also randomly swaps one of the (2) male bodies in Container 4 with a female body (~%tutu_var%misc79~).

To answer your question, you could take the easy way out and swap another item in Container 1 (~%tutu_var%ring19~) with your item, or use entirely different code to actually add a new item.

Offline Miloch

  • Barbarian
  • Planewalker
  • *****
  • Posts: 1032
  • Gender: Male
Re: Inserting (another) item into an area (tp2 patching)...
« Reply #2 on: October 01, 2010, 10:33:54 PM »
There are two ways to do this: via script or via tp2 patch. They are both fairly simple. The advantage of scripting is that it will work even if the player has already visited the area. The advantage of patching it is it's more intuitive to the modder (you will see the item in the area container in an editor, whereas you won't if added via script).

For scripting it, see here for an example. For patching it, see the ADD_AREA_ITEM function in the WeiDU documentation.

Offline jastey

  • Global Moderator
  • Planewalker
  • *****
  • Posts: 1524
  • Gender: Female
Re: Inserting (another) item into an area (tp2 patching)...
« Reply #3 on: October 02, 2010, 01:26:57 AM »
Thanks for your answers.
Miloch: The script doesn't really work for vanilla BG1 (w/o TotSC), as the item lands on the floor in front of the container, not inside the container.

 

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)?: