Aller au contenu

Photo

Staking items


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

#1
Fester Pot

Fester Pot
  • Members
  • 1 394 messages
Hey everyone!

The baseitems.2da file has miscsmall items (line #24 - it_smlmisc) as stackable=1. YET when I have the same item in my inventory that is considered a miscsmall item, they are individual icons in the inventory. How do I get them to become stackable?

When I view the item in the toolset, the Base Type Name is "Miscellaneous Small", so shouldn't the items stack based on the information in baseitems.2da? Yet they do not stack in-game.

Thanks,

FP!

#2
Fester Pot

Fester Pot
  • Members
  • 1 394 messages
Maybe I'm answering my own question but a confirmation would be great.

Stacking=1 in the baseitems.2da means that it takes up 1 square in the inventory per ONE ITEM.

Stacking=50 or Stacking=99 means that it takes up 1 square in the inventory UP TO 50 or 99 STACKS.

Yes?

FP!

Modifié par Fester Pot, 10 décembre 2010 - 08:34 .


#3
TheSpiritedLass

TheSpiritedLass
  • Members
  • 765 messages
Heya FP,



The "Stacking" column (between "BaseCost" and "ItemMultiplier") in the baseitems 2da file... Yes, if you increase that number you will be able to have stacks of Misc Small in game. So if you change that column for misc small to be 10, then you could have a 1x1 inventory grid size of 10 misc small items that have the same resref and icon. The highest I ever tried to set something was a stack size of 99. No idea if it can go higher. Usually I had it set to 10.



Hope that answers your question.



Lesson learned: Do not stack equipable gear.



Second Lesson Learned: Custom stacks can be exploited using barter. Meaning players can turn a single item into multiples. I had to undo custom stacking on my server because of this. *sighs* And WOW do I miss having it. This data is old, 1.69 could have fixed this issue for all I know.



-- Mistress

#4
Pstemarie

Pstemarie
  • Members
  • 2 745 messages
99 is the highest value for a stack size.

#5
Tyndrel

Tyndrel
  • Members
  • 185 messages
The highest I've built a stack was 999, there must be a limit but I have no idea at what point it will fall on your head!

#6
Fester Pot

Fester Pot
  • Members
  • 1 394 messages
Ok, great. Now I just have to test it to make sure when a stacked item is used, it only takes 1 item and not the entire stack. Might need help with that if it's the case.



Thanks!



FP!

#7
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
I see you have allready guessed the next problem. 

There are several thing to keep in mind when stacking items that have charges. The problems become easier to understand once your realize that items in a stack are really only one item.  This has negtive effects on two things:

ONE CHARGES
If you use a charge from an item in a stack,  The charges are reduced. This in effect reduces the charges of all the items in the stack.  Since the stack is one item and all items are using the same number.

TWO LOCAL VARS
Here again since it is only one item seperate VAR list are not kept for each indivisable item.  The Item Var list does not copy over to a stack an item is merged into.  when an item is split from a stack it will have the VAR list that the stack had.  This can cause some pretty big bugs/exploits if all  items, from a given blueprint, do not have the same constant VARS. 

There is no real fix for the Local vars.  This is just something that you will have to keep in mind anytime you start placing vars on any stackable item.  You are asking for bugs if you ever change them via scripting. 

As far as that stackable and charges go, The Idea is to split the item off the stack if it is ever used.  So if you have a stack of 10 item and use a charg fome one, You will end up with a stack of 9 tiems with fifty charges and 1 item with 9 charges.  The way I do this is with a tag based script. 

#include "x2_inc_switches"

// Private Function.
void SplitItemsOffStack(object oSplit,int nSize,itemproperty  iProp,object oPC )
{

  object oCopy=CopyItem(oSplit,oPC);
  SetItemStackSize(oCopy,nSize);
  AddItemProperty(DURATION_TYPE_PERMANENT ,iProp, oCopy);
  AddItemProperty(DURATION_TYPE_PERMANENT ,iProp, oSplit);
  SetItemStackSize(oSplit,1);
}

itemproperty GetItemProp (object oItem)
{
     itemproperty iProp = GetFirstItemProperty(oItem);
     while (GetIsItemPropertyValid(iProp))
     {
         if (GetItemPropertyType(iProp)==ITEM_PROPERTY_CAST_SPELL)  break;
         GetNextItemProperty(oItem);
     }
     return iProp;
}

void main()
{
    object oPC;
    object oItem;
    object oCopy;
    int nCharges;
    int nStack;
    int nMaxStack;
    int nChargesPerUse;
    itemproperty iProp;
    int nEvent = GetUserDefinedItemEventNumber();

    switch (nEvent)
    {
         case X2_ITEM_EVENT_ACTIVATE:
         oPC   = GetItemActivator();
         oItem = GetItemActivated();
         nStack = GetNumStackedItems(oItem);
         nCharges = GetItemCharges(oItem);



          if (nStack>1)
          {

               iProp = GetItemProp( oItem);
               nChargesPerUse = 7-GetItemPropertyCostTableValue(iProp);
               nMaxStack= StringToInt(Get2DAString("baseitems","Stacking",GetBaseItemType(oItem)));
               SetItemStackSize(oItem,nMaxStack);
               if(nCharges)
               {
                   RemoveItemProperty(oItem,iProp);
                   SetItemCharges(oItem,nCharges+nChargesPerUse);
                   DelayCommand(0.1,SplitItemsOffStack(oItem,nStack-1, iProp,oPC )  );
                   DelayCommand(0.2,SetItemCharges(oItem,nCharges));

               }
               else
               {
                   // This is for the case of more then one item in a stack that has only one charge.
                   // We will remove the iProp and add it back to keep the item useable.

                   nChargesPerUse = 7-GetItemPropertyCostTableValue(iProp);
                   nCharges = (nStack-1) *nChargesPerUse;

                   if (nCharges/50)
                   {

                       oCopy = CopyItem(oItem,oPC);
                       iProp = GetItemProp(oCopy);
                       DelayCommand(0.1, AddItemProperty(DURATION_TYPE_PERMANENT ,iProp, oCopy));
                       RemoveItemProperty(oCopy,iProp);
                       DelayCommand(0.1, SetItemStackSize(oCopy,nCharges/50));
                       SetItemCharges(oCopy,50);




                   }
                   if (nCharges%50)
                   {

                       oCopy = CopyItem(oItem,oPC);
                       iProp = GetItemProp(oCopy);
                       DelayCommand(0.1, AddItemProperty(DURATION_TYPE_PERMANENT ,iProp, oCopy));
                       RemoveItemProperty(oCopy,iProp);
                       SetItemCharges(oCopy,nCharges%50);
                       SetItemStackSize(oCopy,1);

                   }
               }
          }


          // Place Item inpact code here.
          break;
    }



 

  

Most of the code in the script is to handle the situation where where there is a stack of item with only one charge.  The iProp has to be removed and readded to the item to make the item able to take charges again.

Modifié par Lightfoot8, 11 décembre 2010 - 05:04 .


#8
Pstemarie

Pstemarie
  • Members
  • 2 745 messages

Tyndrel wrote...

The highest I've built a stack was 999, there must be a limit but I have no idea at what point it will fall on your head!


Really! My game install won't recognize a stack bigger than 99 - anything set higher seems to always default to that value. :crying:

#9
Tyndrel

Tyndrel
  • Members
  • 185 messages
I should have mentioned that the stack of 999 was arrows to overcome NwN's habit of equipping the most inappropriate arrows from the inventory when your existing ones run out. I assumed that all items would work the same, however, (and if this is teaching grannie to suck eggs I apologise) you do have to preserve the column spacing in the 2da, adding another number to the end won't do it.

#10
Pstemarie

Pstemarie
  • Members
  • 2 745 messages
Well, the mystery deepens - I tried upping the stack size on ammunition past 99 and it works. However, my other items are still capped at that 99 limit. Column spacing is preserved - so maybe its a quirk on my installation or a problem with the 2da...

#11
Fester Pot

Fester Pot
  • Members
  • 1 394 messages
Thanks all. Bumped the miscsmall to 10 and tweaked a script to only take one rather than the entire stack when taken by an NPC in a conversation. It's all good.

FP!

Modifié par Fester Pot, 11 décembre 2010 - 02:03 .


#12
AndarianTD

AndarianTD
  • Members
  • 704 messages

Lightfoot8 wrote...

There are several thing to keep in mind when stacking items that have charges. The problems become easier to understand once your realize that items in a stack are really only one item.  This has negtive effects on two things:

...

TWO LOCAL VARS
Here again since it is only one item seperate VAR list are not kept for each indivisable item... There is no real fix for the Local vars.  This is just something that you will have to keep in mind anytime you start placing vars on any stackable item.  You are asking for bugs if you ever change them via scripting.


Yes, I ran into precisely this problem when I added the food-based resting system in my modules. What I really wanted was for food to be stackable, and that was how I originally implemented it. But the design also involved tracking a "spoil time" variable on each item, counting down to zero with a decrement on each rest (with spoilage on reaching zero, unless it was being carried in a special food-preserving container). Those variables wouldn't hold on stackable items, though, so in the end I had to make each food item individual.

Modifié par AndarianTD, 11 décembre 2010 - 02:22 .


#13
Calvinthesneak

Calvinthesneak
  • Members
  • 656 messages
I seem to remember a creative work around with a database and a stack object. Basically a player got an item that converted all complete stacks into a token, and the token stored stuff on the database. The tokens had special powers that would convert token back to a full stack. I still remember some glitches with that even so.

#14
Pstemarie

Pstemarie
  • Members
  • 2 745 messages
Another way to "simulate" a stack - Andarian's food item comes to mind - is to use charges. In the case of the food, you could set up a timer that tracks spoilage and decrements the number of remaining charges when the spoilage condition is met. However, I'm sure this would have limitations as well.