I’ve come across a really strange bug when working on my latest module. Here’s the scenario:
The player and the party gets imprisoned and get stripped of all their items. The items are moved to a special crate. When they manage to free themselves from imprisonment you find the crate with all the items. So far, so good. If you take the PC and take all the inventory from the crate back, everything works as it should. However, if you use one of the companions to pick up the items, the items show up in her inventory, but some of the items also show up in the PC’s inventory. It’s really bonkers. The items that do show up in the PC’s inventory are all items made by myself. However, some items that I’ve also made doesn’t get duplicated like that. None of the stock items that are in the game that you had in the inventory before doesn’t get bugged like this. What could I have done wrong?
The item strip script is one that is a modification of a script that travus has helped me with here on the forums for my previous module. Could that script somehow have something to do with making things behave weirdly? Have I done something wrong?
/*
Script by andgalf with excerpts from a script by travus.
*/
const string sROSTER_EMELIE = "emelie"; // note: this needs to be the *roster* string-id
const string sROSTER_JANINE = "janine"; // note: this needs to be the *roster* string-id
void UnequipAll(object oFM)
{
object o;
int n;
for (n = INVENTORY_SLOT_HEAD; n < INVENTORY_SLOT_CWEAPON_L; n++)
{
o = GetItemInSlot(n, oFM);
if (!GetItemCursedFlag(o)) AssignCommand(oFM, ActionUnequipItem(o));
}
}
void MoveItemsToChest(object oFM)
{
object oContainer = GetObjectByTag("prisoncrate");
object oItem = GetFirstItemInInventory(oFM);
while (GetIsObjectValid(oItem))
{
if (!GetItemCursedFlag(oItem))
{
AssignCommand(oFM, ActionGiveItem(oItem, oContainer));
}
oItem = GetNextItemInInventory(oFM);
}
}
void main()
{
object oPC = GetFirstPC();
object oEmelie = GetObjectFromRosterName(sROSTER_EMELIE);
object oJanine = GetObjectFromRosterName(sROSTER_JANINE);
UnequipAll(oPC);
UnequipAll(oEmelie);
UnequipAll(oJanine);
DelayCommand(0.4f, MoveItemsToChest(oPC));
DelayCommand(0.5f, MoveItemsToChest(oEmelie));
DelayCommand(0.6f, MoveItemsToChest(oJanine));
}
Another really odd thing that I noticed happen, and this I think could be related, is that I have several crates looking the same, however I renamed the tag of this particular crate to “prisoncrate”, but outside the prison the other crates had all the inventory items too. That shouldn’t be possible since they have another tag. To come to grips with this weird thing, I renamed the tag of all the other crates and made it so they don’t have inventory and are static.
Anyway, does anyone have any clue as to what could be going on, because I surely don’t understand it.
I’ve now renamed the tag of all those items and put them back into the game. I will do a test run now and see if anything’s changed.
EDIT: So, what happened this time was that now everything that the PC had in his inventory before the stripping, even stock items, (except for the weapons and ammo he had equipped) was duplicated on the PC when the companion picked up everything. The things that weren’t duplicated were the armor of the companions, their weapons and ammo and his weapons and ammo. I don’t know what to make of this.
Most of this inventory, but not quite all, is picked up from another crate with another tag at the beginning of the module. If the companion picks up the stuff then, the items are not duplicated, so something seems to be happening with the stripping and placing in this new crate.
There is no problem with those script, the problem is probably with the script you use when getting the object back from the chest. And my guess is that it’s tied to :
object oPC = GetFirstPC(); By default it’s object oPC = GetFirstPC(TRUE); which mean it s always the player character that is returned.
object oPC = GetFirstPC(FALSE); returns the controlled character.
with FALSE you can have oEmilie, or Janine or the main PC you call here oPC. with TRUE you can only have the main PC.
My guess is that you probably call the main PC twice in that script.
What script is used there you mean? I just pick the items up. There is no script running there except for some hardcode running the game. I don’t understand.
EDIT: Could it be that you mean, if I use GetFirstPC(FALSE); in this script here, the script in my previous post, then things will work when I pick stuff up with the companion? I could certainly try that.
EDIT2: I tried with changing it to GetFirstPC(FALSE); but sadly that didn’t change anything.
Then my guess is that in your bugged run you do all the sequences with oEmilie or oJanine
When you run your script oEmilie and oJanine are called twice. and oPC isn t called.
An other possibility is “latency”, the full inventory transfert is stopped before it’s ended because you forced the character to do an other action before the current actions are finished.
You can use CopyItem and DestroyObject instead of “actions”, those 2 function are instant, or you can set a cutsceneMode for stopping the player from acting a few second.
That doesn’t make sense. All the items are stripped fine and put into the container, the thing that the script does.
The problem is after, when I pick up the items from the container with one of the companions. If I pick them up by Loot all, almost all of them get duplicated.
Huh, it gets weirder…I just started from a savegame just before picking up the stuff with one of the companions, and this time the items didn’t get duplicated. What’s going on here…
EDIT: Loading with a save from a bit further back, problem reappears. So odd…
andgalf. Here’s a test you could do if the item strip comes from a conversation.
Use the generic ga_give_inventory for each of the party and strip them into the same crate. If that works without an issue it’s your script if it has an issue then it’s somewhere else.
EDIT: Lol, it didn’t quite work since there are two cursed items that should remain on one of the characters, otherwise they can’t get out of prison. I’ll see if I can do something about that.
The only problem i see with the scripts you linked is the use of “actions”, an actions queue can be disturbed, interupting the whole sequence, and stoping them “half-way”.
@Tsongo - So I tried with ga_give_inventory and then had to do a modified version of ga_give_item to give back two items to one of the companions, but sadly the bug still appeared when picking up the items from the crate.
Yeah, but since the script seems to work, I mean, all the items are stripped and transfered to the crate without issues everytime, there must be something else going on. Right before this, I have a robot opening the door to the cell, and then the characters can run out, find the crate and then flee. I’m wondering if that script somehow in some weird way messes with things. Because when loading my savegame that I saved AFTER the robot opens the door, then when the characters run to the crate and I pick up the items with the companion, everything seems to work. It still seems odd that this could even be connected but…
Mmm, I’m beginning to think it’s the other script that’s the culprit here…
What do you mean by: change tags everywhere?
Sad thing is, if I do a new crate and all that, I’ll have to play from the beginning. Luckily it’s only about 10 minutes play or so, so maybe I could live with that.
Ok, so now I’m beginning to spoil the story of my module here, but I guess there’s nothing else to it anymore.
EDIT: I removed this next part since it, in the end, didn’t have to do with the bug.
I ran this by the console, so the robot script in my previous post was never activated. Got out of prison. Tried with the companion again and the bug appeared as before.
What? Eh…It just stops the actions of the robot, not anyone elses. AND if that was indeed the problem, then everything would have been fine when I ran the console script, where this script with the ClearPendingActions was never activated, but the bug STILL appeared even without that.
Sometimes I just hate NWN2…
EDIT: Ok, so the next step is perhaps to just create a new totally unique crate and place it in that room and bake the room and play from the beginning, and hope for the best…I don’t know…
andgalf… If when you loaded a save game just before picking up the items and it worked is there any way to run over a trigger that resets things. I’m no scripter, as you all know, but maybe running out of the cell hitting a trigger that compiles, saves or clears things will do the same as loading a save.
Remake the crate, stick an autosave trigger outside the cell, rapidly click your way through the mod from the beginning and see what happens.