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 VARSHere 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 .