Due to a ZC bug, you must have at least one PERMANENT selectable item in your inventory before collecting items spawned with this script. Additionally, this item must never be removed. Doing otherwise may result in a crash! So a true quest with one item slot is a bit out of the way.
[codebox]// --------------------------------------
// SCRIPT: Pickup/Drop Item
// --------------------------------------
// DESCRIPTION
// This script will force the player to discard an item when picking up another one.
// Essentially, it means the player will only be able to keep their current inventory and then one extra item,
// so long as collectable items are spawned with this script.
// It works by recording the item ID of the previously collected item. When the item that is created by this script
// is collected, the previously recorded item is removed and the new item ID is recorded.
// --------------------------------------
// USER ARGUMENTS
// D0 (item_id) The id of the item.
// --------------------------------------
// #####This is the main code that ZQuest will execute#####
ffc script single_item {
int SI_current = 0; // Initialize the item ID recorder.
void run(int item_id) { // Start run function
item Screen_Item = Screen->CreateItem(item_id); // Create the item.
Screen_Item->X = this->X; // Move the item to the location of the FFC.
Screen_Item->Y = this->Y;
if (SI_current == 0)// Check if current item is set.
{
SI_current = item_id; // If not, set it to the current item on the screen.
}//!End if statement check for current item being 0
while(true){// Begin internal while loop
if (Link->Item[item_id] && SI_current != item_id)// If Link collected the item and not a duplicate
{
Link->InputL = true; // Force the player to cycle items once.
Waitframe();// Pause for a frame
Link->Item[SI_current] = false; // Remove the previous item.
Link->InputR = true; // Force the player to cycle items again. Seems useless, but consider multiple items.
SI_current = item_id; // Set the new item id to SI_current.
}//!End if statement check for item collection.
Waitframe(); // Makes the script wait a frame before looping again. It's necessary to have this.
}//! End of internal while loop
} //! End of run function
}//! End of ffc script[/codebox]
So... how does one use this script? What does it do, for that matter?
Essentially, this script will spawn the specified item (D0) on the screen at the location of the FFC. As such, it would be a good idea to make this FFC invisible. Anyway... there is another component to this script. Items you pickup with this script are stored as a global variable. When you pickup a second item with this script, the previous item you collected will be removed from your inventory and replaced with the new item.
In other words, any item picked up with this script can only be used until you get another item with the same script.
Possible Future Plans:
- OPTION: Creating an instance of the previous item on the screen as an option, much like Four Swords Adventures.
- Creating a function that will remove all collected items from the inventory. This would be useful for the end of an area, like FSA and Super Mario 64.
- OPTION: Making the item appear after secrets are triggered.
- OPTION: Making the item appear after enemies are killed.
- OPTION: Item never respawns.
Questions? Ideas for possible additions? Complaints? Yeah... some kind of feedback would be nice.