ok, With the modified formula : FloatToInt(-375.0 + sqrt(2262000 + 8.0*nGPValue) / 4);
the progression is now:
bit0 = 2
bit1 = 1508
bit2 = 4532
bit3 = 10628
bit4 = 23012
bit5 = 48548
bit6 = 102692
bit7 = 223268
bit8 = 513572
bit9 = 1290788
And Keep in mind that the bits are 0 based, Your first placable ResRef should be: ResRefPrefix + "0" not ResRefPrefix + "1";
Corrections made to the script:
-Added a Filter to stop Total Chest Values of 3631652gp or more from filtering into the 10th bit and removing lower set bits.
-Added Code to catch the value of gold added to the chest.
-Added code to Value unidentified items at there full cost, not there unidentified value.
-Added an underline in the Created Placable Tags to advoid possiable Hash collision.
Here is the adjusted code. My testing showed it all working.
EDIT: Location of placables is still right on top of the old one in my code.
/////////////////////////////////////////////////
const string ResRefPrefix = "???" ;
int GetPlacableFlags( object oChest = OBJECT_SELF)
{
int nGPValue,bID;
object oItem = GetFirstItemInInventory( oChest );
while (GetIsObjectValid(oItem))
{
bID = GetIdentified(oItem);
SetIdentified(oItem,TRUE);
nGPValue += GetGoldPieceValue(oItem);
if ( GetBaseItemType(oItem) == BASE_ITEM_GOLD)
nGPValue += GetItemStackSize(oItem);
SetIdentified(oItem,bID);
oItem = GetNextItemInInventory (oChest);
}
int seReturn = FloatToInt(-375.0 + sqrt(2262000 + 8.0*nGPValue) / 4);
if ( seReturn > 0x3ff) seReturn = 0x3ff;
return seReturn;
// FloatToInt(log(nGPValue*2.0)/log(2.0));
}
int GetCurrentdrawnPLCSet( object oChest = OBJECT_SELF)
{
return GetLocalInt( oChest,"PLC_Drawn_set");
}
void StoreCurrentdrawnPLCSet( int nDrawnSet, object oChest = OBJECT_SELF )
{
SetLocalInt( oChest,"PLC_Drawn_set",nDrawnSet);
}
void DestroyPLCsInSet(int nSet, object oChest =OBJECT_SELF)
{
string sTagPreFix = ObjectToString(oChest);
while(nSet)
{
int nFlag = nSet & -nSet;
nSet ^= nFlag;
DestroyObject( GetObjectByTag(sTagPreFix + "_" + IntToString(nFlag)));
//SpeakString( "Destroying Placable with tag :" + sTagPreFix+ "_" + IntToString(nFlag));
}
}
void DrawPLCsInSet(int nSet, object oChest =OBJECT_SELF )
{
string sTagPreFix = ObjectToString(oChest);
string sResRef, sTag;
while(nSet)
{
int nFlag = nSet & -nSet;
nSet ^= nFlag;
sTag = sTagPreFix + "_" + IntToString(nFlag);
nFlag = FloatToInt( log(nFlag*1.0)/log(2.0));
sResRef = ResRefPrefix +IntToString(nFlag);
location lLoc = GetLocation(oChest);
CreateObject( OBJECT_TYPE_PLACEABLE, sResRef, lLoc, FALSE, sTag );
//SpeakString("Creating placable :" + sResRef + " Tag :" +sTag);
}
}
void UpdateTresurePlacables(object oTresureContainer = OBJECT_SELF)
{
int nOldSet = GetCurrentdrawnPLCSet(oTresureContainer);
int nNewSet = GetPlacableFlags(oTresureContainer);
int nChange = nOldSet ^ nNewSet;
if ( nChange )
{
StoreCurrentdrawnPLCSet( nNewSet, oTresureContainer);
DestroyPLCsInSet(nChange & nOldSet ,oTresureContainer );
DrawPLCsInSet (nChange & nNewSet ,oTresureContainer );
}
}
void main()
{
UpdateTresurePlacables();
}
Modifié par Lightfoot8, 01 janvier 2013 - 08:19 .