Aller au contenu

Photo

Limitations to CreateItemOnObject? [solved]


5 réponses à ce sujet

#1
BillHoyt

BillHoyt
  • Members
  • 109 messages
This question is going to sound rather silly, but I'm kind of at my wits' end here.

I have a 0-cost merchant called store_jenna that I stock with treasure items from numerous quests rather than giving them directly to the PC. The first time the PC speaks with Jenna (the proprietor), they can upgrade her store by paying her to become their permanent archivist. I run a script (included below) which adds a bunch of books to her inventory, some of which are gifts, some of which increase skills, most of which are junk. This first script (called first_restock) works swimmingly. It is run from Jenna's dialogue.

// -----------------------------------------------------------------------------
// first_restock script
// Owner: Bill Hoyt
// -----------------------------------------------------------------------------
/*
  This script will upgrade Jenna's Bookstore (first time)
*/
//------------------------------------------------------------------------------

#include "utility_h"
#include "wrappers_h"
#include "plot_h"
#include "plt_store_restock"

// ---------- Script Starts Here ----------
void main()
{
    // Take 20 gold from PC
    object oPC = GetHero();
    UT_MoneyTakeFromObject(oPC,0,0,20);

    object  oStore = GetObjectByTag("store_jenna");

    CreateItemOnObject  (R"book_breathing.uti",oStore, 1);
    CreateItemOnObject  (R"book_dogma.uti",oStore, 1);
    CreateItemOnObject  (R"book_hist_circle.uti",oStore, 1);
    CreateItemOnObject  (R"book_stone.uti",oStore, 1);
    CreateItemOnObject  (R"diary_sanga.uti",oStore, 1);
    CreateItemOnObject  (R"tome_fade.uti",oStore, 1);
    CreateItemOnObject  (R"tome_flame.uti",oStore, 1);
    CreateItemOnObject  (R"tome_menace.uti",oStore, 1);
    CreateItemOnObject  (R"tome_undead.uti",oStore, 1);
    CreateItemOnObject  (R"book_execution.uti",oStore, 1);
    CreateItemOnObject  (R"book_methods.uti",oStore, 1);
    CreateItemOnObject  (R"book_music.uti",oStore, 1);
    CreateItemOnObject  (R"tome_lapidary.uti",oStore, 1);
    CreateItemOnObject  (R"tome_frostbacks.uti",oStore, 1);
    WR_SetPlotFlag("store_restock", FIRST_RESTOCK, TRUE);

}
// ---------- Script Ends Here ----------

Jenna has an assistant named Brother Maynard, for whom the PC can retrieve an item. As payment for the quest, I would like to add more books to store_jenna. However, even though the script (second_restock, run from Brother Maynard's dialogue) is running, the books never appear in store_jenna.

// -----------------------------------------------------------------------------
// second_restock script
// Owner: Bill Hoyt
// -----------------------------------------------------------------------------
/*
  This script will upgrade Jenna's Bookstore (second time)
*/
//------------------------------------------------------------------------------

#include "utility_h"
#include "wrappers_h"
#include "plot_h"
#include "plt_store_restock"

// ---------- Script Starts Here ----------
void main()
{
    object  oStore = GetObjectByTag("store_jenna");
    CreateItemOnObject  (R"book_elf_music.uti",oStore, 1);
    CreateItemOnObject  (R"book_unchain.uti",oStore, 1);
    CreateItemOnObject  (R"tome_dwarf_children.uti",oStore, 1);
    CreateItemOnObject  (R"tome_dentistry.uti",oStore, 1);
    CreateItemOnObject  (R"tome_rime.uti",oStore, 1);
    WR_SetPlotFlag("store_restock", SECOND_RESTOCK, TRUE);

    object oMaynard = GetObjectByTag("brother_maynard");
    DisplayFloatyMessage(oMaynard,"Books Added");
}
// ---------- Script Ends Here ----------

I would tend to think there is something wrong with the script, but I originally tried to re-stock Jenna's store multiple times through her dialogue but could never make it work twice.  So I deleted all that, then created the Brother Maynard re-stock from scratch, and that seems not to work a second time (to get this quest, you must have already completed first_restock).

So is there an iteration limit on external store updates? On how many times you can CreatItemOnObject? Or is there something in the script that I'm missing?  Any insight would be greatly appreciated.

Modifié par BillHoyt, 07 mai 2010 - 02:57 .


#2
FanfanVilperdue

FanfanVilperdue
  • Members
  • 18 messages
Very strange indeed, they should work both or not at all! I've no idea why it doesn't work... I use CreateItemOnObject repeatedly on creatures and it works fine, but I've not used it with merchants.

Have you tried for instance :
object oBookElfMusic = CreateItemOnObject  (R"book_elf_music.uti",oStore, 1);
if (IsObjectValid(oBookElfMusic))
{
    DisplayStatusMessage("Managed to create item");
    // Run other tests here if necessary : GetItemStackSize(oBookElfMusic)... 
} else
{
    DisplayStatusMessage("WARNING: unable to create item");
}
Maybe it can help for diagnosis... or not :unsure:.

Good luck!

#3
BillHoyt

BillHoyt
  • Members
  • 109 messages
Scratch that (I knew it was a dumb question). I don't yet know what the problem is, but I know what it's not. If I run the "working" script from Brother Maynard's dialogue, it works fine, so it's either a problem with the second script or (more likely) the items in it. Ah, well, if anyone needs a working script to add items to a store, you can have mine, only slightly used.

Edit: it turned out to be an export problem.  I had already exported the level with dependent resources and assumed that would suffice.  But when I selected one of the items and exported "all items of type" suddenly two of the five appeared.  So I added all of them to store_jenna's original inventory, exported that, and tested.  Behold, not only were they in the store, but I could also get another copy from second_restock.  So I took them back out of store_jenna, exported it again, and all is well with the world.

Thanks, FanfanVilperdue, I'll keep that code on hand for next time.

Modifié par BillHoyt, 05 mai 2010 - 09:23 .


#4
CID-78

CID-78
  • Members
  • 1 124 messages
Someone forgot to teach you, reusability, and the use of loops. you could solve the same problem with one much smaller script, that could restock any store with any item. the list(s) could be stored as either a item with inventory or in a .2da

#5
DavidSims

DavidSims
  • BioWare Employees
  • 196 messages
Export with dependant resources only exports resources that the toolset knows are dependant, such as creatures placed in the level, conversations atatched to those creatures, plots used in those conversations, scripts atatched to those plots and so on down the line. If you are only referencing an item in script, the toolset has no way of knowing the item appears in the level, therefore it's not considered a dependant resource. To be safe, I almost always export without dependant resources, and export whole folders when I want to cover everything.

#6
QuickQuipt

QuickQuipt
  • Members
  • 7 messages
I made this mistake too. Thanks for the post.