Aller au contenu

Photo

Container scripts for handling cursed items


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

#1
rjshae

rjshae
  • Members
  • 4 507 messages
If a container has any inventory with the Cursed flag set, the player is unable to remove the cursed item. The following scripts provide a work-around for this feature. On opening the container, the first script adds any cursed items into a local array then removes the Cursed flag. When the container is disturbed and an item removed, the second script checks whether the item is in the local array of cursed objects. If it is, the Cursed flag is set to true and the array element is set to invalid.

// 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... :devil:

Modifié par rjshae, 23 octobre 2013 - 03:27 .


#2
Dann-J

Dann-J
  • Members
  • 3 161 messages
I find it easier to give cursed items unique tags, then used tag-based OnAcquire scripts to set the cursed flag. If you give the items all the same tags you can use the one script. Different template values in the blueprints still allow you to spawn items individually, even if they have the same tags.

It becomes more difficult if you want to check for the presence of the item in a conversation though - unless you rewrite the GC_ script to use item template instead of item tag. And for keys you've pretty much got to give them unique tags, so they'll always require separate onAcquire scripts.

Modifié par DannJ, 30 septembre 2013 - 12:53 .


#3
rjshae

rjshae
  • Members
  • 4 507 messages
Aye, I know there's better ways to manage cursed items. But unfortunately they require scripting skills, which not every toolset user is willing to master.

Perhaps what we need is a modular cursed item system that will take care of the messy details for you and let you tune the cursed item behavior with just a few variables? For example, suppose you want an item to appear like a nice magic item for a few battles, then transform into the cursed item... thereby making save scumming more difficult. Just set some variables on the item saying when it should transform and into what.

#4
-Semper-

-Semper-
  • Members
  • 2 259 messages
nice work. thx for posting ;)

#5
Dann-J

Dann-J
  • Members
  • 3 161 messages

rjshae wrote...

 For example, suppose you want an item to appear like a nice magic item for a few battles, then transform into the cursed item... thereby making save scumming more difficult. Just set some variables on the item saying when it should transform and into what.


There's a bottle 'club' in SoZ that has a tag-based OnHit script that has a small probability of breaking the bottle, which destroys it and replaces it with a broken bottle 'dagger'.

Imagine a weapon that grows depending on how many times it has hit enemies. It could start off as a dagger, grow to a longsword at some point, and eventually into a greatsword. The tag-based OnHit script could keep count of each hit, and transform the weapon when a threshold is reached. Another OnActivated script could allow you to release the energy as some sort of spell or effect, dropping the weapon back in size again. The only limits to tag-based scripting are your imagination.

It's a pity that you can't hide the 'OnHit Cast Spell:Unique Power' item property when you examine the item though. Although the player won't know what the custom OnHit script will do (unless it's mentioned in the item description), they at least expect *something* to happen at some point.