// container_opened
/*
Cursed items can not be removed from containers, so this
script cycles through the contents, removed any 'Cursed'
flags, and stores the cursed objects in a local array. This
array is then used by the 'On Inventory Disturbed' script
to restore the curse flag.
Add to container On Open script field.
*/
// 29sep13, RJH
const string CURSE_INV = "CursedInventory";
const string CURSE_CNT = "CursedInvCount";
void main()
{
// Cycle through the inventory
int nCount = GetLocalInt( OBJECT_SELF, CURSE_CNT );
object oInv = GetFirstItemInInventory();
while( GetIsObjectValid( oInv ) ) {
// Check whether item is cursed
int nCursed = GetItemCursedFlag( oInv );
if ( nCursed ) {
// Add item to array of cursed content
string sVarName = CURSE_INV + IntToString( ++nCount );
SetLocalObject( OBJECT_SELF, sVarName, oInv );
// Strip the cursed item flag
SetItemCursedFlag( oInv, FALSE );
}
// Get next item in inventory
oInv = GetNextItemInInventory();
}
// Store the updated array size
SetLocalInt( OBJECT_SELF, CURSE_CNT, nCount );
}
// container_disturbed
/*
Cursed items can not be removed from a container, so an
array of cursed items was stored in a local array when
the container was opened then the Cursed flags cleared.
When an item is removed, check if it is a member of the
cursed objects. If so, restore the Cursed flag and
clear the array entry.
Add to container's 'On Inventory Disturbed Script' field.
*/
// 29sep13, RJH
const string CURSE_INV = "CursedInventory";
const string CURSE_CNT = "CursedInvCount";
void main()
{
object oPC = GetFirstPC();
// Check if the script was fired by removing an object
int nType = GetInventoryDisturbType();
if ( nType == INVENTORY_DISTURB_TYPE_ADDED )
return;
// Get the item removed
object oItem = GetInventoryDisturbItem();
// Cycle through the array of cursed inventory
int nCount = GetLocalInt( OBJECT_SELF, CURSE_CNT );
int i;
for ( i = 1; i <= nCount; i++ ) {
// Retrieve the ith cursed object from the stored array
string sVarName = CURSE_INV + IntToString( i );
object oCursedInv = GetLocalObject( OBJECT_SELF, sVarName );
if ( GetIsObjectValid( oCursedInv ) ) {
if ( oItem == oCursedInv ) {
// Restore the cursed item flag
SetItemCursedFlag( oItem, TRUE );
// Remove from local array
SetLocalObject( OBJECT_SELF, sVarName, OBJECT_INVALID );
// We're done
return;
}
}
}
}
Mwahahahaha...
Modifié par rjshae, 23 octobre 2013 - 03:27 .





Retour en haut






