Aller au contenu

Photo

Persistant Chest Script Item Duplication Problem


  • Veuillez vous connecter pour répondre
8 réponses à ce sujet

#1
FallenExarch

FallenExarch
  • Members
  • 5 messages
I have a set of persistant storage scripts for mine and my friends module that we have been using, but when you place a bag of some type into a chest using these scripts, it duplicates everything inside the bag.

Now I know its possible to stop this, and for the item duplication to be prevented some how, becos others have done it, I just dont know how as I am not a scriptor. Does anyone know how to solce this issue?

Here is one thing you may find interresting that I noticed while playing around with these scripts and testing.  I took these scripts and placed them on a chest, then put that chest inside a brand new area of some kind.  Then I took Vordons Hero Creator, and put the same chest with the same scripts, and placed it near the beginning starting point in vordons hero creator and tested both chests with a bag filled with items.  In the new area, when a bag was placed into the chest, it duplicated every item inside the bag stored inside that chest.   Oddly enough, when i placed a similar bag with the same items into a chest with these same scripts, into the chest that I added to the Vordons Hero Creator mod, no items were duplicated at all.  Something, some code of some kind in vordons hero creator, prevents item duplication when a bag/container is stored inside a persistant chest storage containter, but as I am not a scriptor ........ I dont know what to look for to be able to spot it so I can add it to these scripts properlly to be able to solve this item duplication issue.  And I would love to find it and then give credit to whoever has the answer and post this on the NWN2 vault for others to benefit from.

here are the 3 scripts:

----------------------------------------------------------------------------------------
chest_close to be put on the On Closed line;

void main()
{
 int i=1;
 object item=GetFirstItemInInventory(OBJECT_SELF);
 while (GetIsObjectValid(item))
 {
  if (GetLocalInt(item,"added"))
  {
   string index="item"+IntToString(i)+GetTag(OBJECT_SELF);
   StoreCampaignObject("chest_persistence",index,item,OBJECT_SELF);
   DestroyObject(item);
   i++;
  }
  item=GetNextItemInInventory(OBJECT_SELF);
 }
}

-----------------------------------------------------------------------------------
chest_disturbed to be put on the On Disturbed line;

void main()
{
object item=GetInventoryDisturbItem();
int type=GetInventoryDisturbType();
if (type==INVENTORY_DISTURB_TYPE_ADDED)
SetLocalInt(item,"added",1);
else
DeleteLocalInt(item,"added");
}

-----------------------------------------------------------------------------------
chest_open to be put on ther On Open line;

void main()
{
 int i=1;
 object item;
 do
 {
  string index="item"+IntToString(i)+GetTag(OBJECT_SELF);
  item=RetrieveCampaignObject("chest_persistence",index,
   GetLocation(OBJECT_SELF),OBJECT_SELF,OBJECT_SELF);
  SetLocalInt(item,"added",1);
  DeleteCampaignVariable("chest_persistence",index,OBJECT_SELF);
  i++;
 }
 while (GetIsObjectValid(item));
}

-----------------------------------------------------------------------------------

Please if you have any suggestions or answer any of you have, help would be appreciated

FE

Modifié par FallenExarch, 09 novembre 2010 - 06:26 .


#2
painofdungeoneternal

painofdungeoneternal
  • Members
  • 1 799 messages
Just looking at this very quickly, but i will point out something you might want to look at which i found when i was doing some AI work.

The outer loop when it hits the bag, the next item will be what is inside the bag, which makes it a little hard to see. You need to check for containers and when one is found step to next item in the container and in actual inventory, or check to make sure they are in inventory. 

as reference look at this code... specifically at the lines that have
oItem = GetNextItemInInventory(oCharacter);
oSubItem = GetNextItemInInventory(oContainer);

object SCGetBestHealingKit( object oCharacter = OBJECT_SELF )
{
    //DEBUGGING// if (DEBUGGING >= 10) { CSLDebug(  "SCGetBestHealingKit Start", GetFirstPC() ); }
    
    object oKit;
    int iRunningValue;
    int iItemValue, iStackSize;
    
    object oItem = GetFirstItemInInventory( oCharacter );
    while(GetIsObjectValid(oItem))
    {
        //DEBUGGING// igDebugLoopCounter += 1;
        // skip past any items in a container
        if (GetHasInventory(oItem))
        {
            object oContainer = oItem;
            object oSubItem = GetFirstItemInInventory(oContainer);
            oItem = GetNextItemInInventory(oCharacter);
            while (GetIsObjectValid(oSubItem))
            {
                //DEBUGGING// igDebugLoopCounter += 1;
                oItem = GetNextItemInInventory(oCharacter);
                oSubItem = GetNextItemInInventory(oContainer);
            }
            continue;
        }
		switch (GetBaseItemType(oItem))
		{
			case BASE_ITEM_HEALERSKIT:
			{
				iItemValue = GetGoldPieceValue(oItem);
				iStackSize = GetNumStackedItems(oItem);
				// Stacked kits be worth what they should be separately.
				iItemValue = iItemValue/iStackSize;
				if(iItemValue > iRunningValue)
				{
					iRunningValue = iItemValue;
					oKit = oItem;
				}
				break;
			}
/*			case BASE_ITEM_POTIONS:
			case BASE_ITEM_SPELLSCROLL:
			case BASE_ITEM_GRENADE:
//				if (GetItemHasItemProperty(oItem, ITEM_PROPERTY_CAST_SPELL))
				{
					SetItemCharges(oItem, 1);
				}
				break; */
		}			
        oItem = GetNextItemInInventory( oCharacter );
    }
    return oKit;
}


You might want to flag the items with a variable ( random integer  as a value would be good for example, which is determined on start of loop soas to ignore things from the given pass only ) which flags ones you have moved prior to deleting them, the delete object does not happen until after the script stops, if you tagged them with a flag it would prevent it copying over more than once after it's been marked to be destroyed. ( You probably want to look at scarfaces persistent banking system from NWN1, the entire area is prone to item duplication )

Modifié par painofdungeoneternal, 09 novembre 2010 - 07:29 .


#3
FallenExarch

FallenExarch
  • Members
  • 5 messages
ok, if your saying look at a container seperately, that still doesnt explain how to stop it from item duplicating everything inside the bag once the bag is placed inside the chest. If you were to do what I did, and download the latest version of Vordons Hero Creator, and open it in toolset, place a chest, using those 3 scripts, you would find it would not item duplicate anything inside a bag. However using these scripts by themsleves in a new area, you will find any time you place a similar chest with the same items in a bag inside the chest, litterally every item in that bag gets duplicated each time the chest is closed and re-opened again. so the question is ........ what line of code in vordons hero creator is blocking those scripts from item duplicating? and can it be used in these 3 scripts, adding it in some how, to solve the item duplication problem? and if so? how do you do that?

Modifié par FallenExarch, 09 novembre 2010 - 11:36 .


#4
painofdungeoneternal

painofdungeoneternal
  • Members
  • 1 799 messages
I did say i was looking at it quickly.



If it looks at it separately it would not duplicate, since it would skip those other items instead of copying them twice like your posted code is doing now. Since i don't see it checking if the item is a container in your code, i'd suspect that is part of the issue. As for your question, i am just giving a little help, hopefully someone else can give you more help, who can spend the time downloading vordans and looking at why it works better than your version does.



If all else fails i'd really take a look at something like scarfaces persistent banking system instead of a trainer module, it likely would be easier since that is designed just for doing what you want to add. At the very least you should compare how it works to what you have.

#5
FallenExarch

FallenExarch
  • Members
  • 5 messages
OK, perhaps I wasnt clear. Vordons Hero Creator does not have a persistant chest in it at all. All I did was downloaded the Vordons Hero Creator, and then added these 3 scripts myself, then placed a chest while opening it in the toolset, put the 3 scripts each in thier appropriate lines of the chest properties and then loaded it, in single player mode, and tested the chest to see what would happen. I was very surpeised to find the item duplication problem didnt happen with Vordons module, and was solved, but no matter what you do with any other module the item duplication still occurs each time the chest is closed and re-opened. Now what is in Vordons scripts that prevents my 3 scripts from item duplicating I dont have a clue since im not a scriptor to be able to spot and recognize it. Ive tried emailing Vordon with no answer as of yet. I would love to know, and know how to add that code into these 3 scripts to be able to solve the item duplication problem.
and Sadly, Scarfaces does not solve the issue at all either, as I downloaded and tested it. all it does is delete the bag and everything inside it, but does give you a warning message asking you to remove it. You still cant store a bag with items in the chest, and in fact you loose everything in the bag. When I tested this while adding these scripts myself into Vordons Hero Creator ..... it solved the issue completely. No item duplicating. Stored the bag safely, and the next time you open the module again, the bag is still there with all its contents and no item duplication occurs.

How is it doing it? LOL I dont have a clue cos as I said I am not a scriptor and dont know which line of code is solving the issue, I wish I knew and was hoping someone here would be able to figure it out so we could share it with the rest of the NWN2 community :)

FE

Modifié par FallenExarch, 10 novembre 2010 - 12:16 .


#6
painofdungeoneternal

painofdungeoneternal
  • Members
  • 1 799 messages
I would imagine it's doing it because your scripts are copying all the items in inventory, which not only includes bags but also the items in the bags, which is why you have to have an if/then and advance the items in inventory and the items in the subitems inventory at the same time.



You don't need advice on what is wrong, you need someone to write the script for you - either that or you need to learn how to script yourself.



Scarface stopped dealing with containers because they were prone to a lot of major issues, it's not a lack of a feature, it's understanding how the engine works and wanting to sidestep major bugs and exploits.

#7
FallenExarch

FallenExarch
  • Members
  • 5 messages
well something in Vordons Hero Creator, some place, totally fixes this issue of item duplication with these 3 scripts, no bugs, I just wish I knew what it was so I could add it to these as well.

Modifié par FallenExarch, 10 novembre 2010 - 02:06 .


#8
Olblach

Olblach
  • Members
  • 175 messages
It stores each item then it stores the bag with each item in it, hence the dup. The best is to transfer the items to a creature and store the creature. it's also less stress on the database. You can create the creature in another area so it will be invisible to the player.
There are a few good banking systems on the vault you can try them out.

Modifié par Olblach, 10 novembre 2010 - 12:03 .


#9
FallenExarch

FallenExarch
  • Members
  • 5 messages
ok, we dont need a persistant banking script. we need just a persistant chest script that does not duplicate items when a bag is stored inside a chest. I know this is possible. Lostdreamz who ran World of Desire years ago coded this and fixed it successfully ((although attempts to contact her has failed)). Some how Vordons Hero Creator has something in it that prevents item duplication, although the guy who created Vordons Hero Creator has looked through it and has no idea what it is. I know its possible and ive heard there are some out there who have fixed this problem, but are unwilling to share with the community the answer to this bug.

I was hoping someone on these forums either knew of a fix, code wise. so far nothing posted here so far has helped, as it doesnt direct how to code or fix the code to prevent the item duplication.

Modifié par FallenExarch, 02 décembre 2010 - 07:28 .