Jump to content

Photo

WIP: Item Pickup/Drop Script


  • Please log in to reply
5 replies to this topic

#1 Kite

Kite

  • Members

Posted 19 February 2007 - 12:41 PM

This script is perfectly usable as it is (or it was for me). However, there are a few things I still need to work out with additional functions (this is going to be a script composed of multiple functions). It also isn't that user friendly at the moment.

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.
One of the questions I am likely to get is "why didn't you just make this a global script that worked for normally placed items?" The simple answer is: I'm lazy. Seriously... there are 255 item slots in ZQuest. If I were to make a script that perfectly kept track of the inventory in a way that would mimic this behavior, I'd have a gazillion else if statements. Additionally, not everyone will have the exact same items. There is no possible way for me to easily compensate for this... thus... I decided to follow this method with the ffc script instead.

Questions? Ideas for possible additions? Complaints? Yeah... some kind of feedback would be nice. icon_blah.gif

#2 Nimono

Nimono

    Ultra Miyoa Extraordinaire!

  • Members
  • Real Name:Matthew
  • Location:Static Void Kingdom

Posted 19 February 2007 - 12:58 PM

This'd be great for those quests like the original Metroid, where you could only have ONE Beam weapon at a time. Now, let me ask you this: Why couldn't you make this script so the first time you get an item from this, it just gives it to you instead of trying to take something away?

Oh yes, also, how would you allow multiple items to spawn from this one script?

#3 Kite

Kite

  • Members

Posted 19 February 2007 - 01:14 PM

QUOTE(Matthew @ Feb 19 2007, 12:58 PM) View Post

Why couldn't you make this script so the first time you get an item from this, it just gives it to you instead of trying to take something away?

Oh yes, also, how would you allow multiple items to spawn from this one script?

Uh... it does. If there is no item previously collected with this script, it will set the current item to the same item that is on the screen. This means it won't try to take anything away. In retrospect, I just realized that it only does this once. That shouldn't matter, still. Taking items is just a matter of setting it to false. The item itself always exists, thus there is no reason to crash.

The crash/freeze is related to how item selection works. Try putting one item in your inventory with cheats. Afterwards, remove it and add another item. Watch ZC freeze when you try to cycle items (despite having just one).

As far as spawning multiple items, I don't think this script would be specifically tailored to do that due to the Screen_Item pointer I make use of to manipulate the spawned item. You would have to make a duplicate script. If you are wanting a script that just spawns multiple items on screen, that would have to be a different script (which wouldn't be difficult to write).

#4 Nimono

Nimono

    Ultra Miyoa Extraordinaire!

  • Members
  • Real Name:Matthew
  • Location:Static Void Kingdom

Posted 19 February 2007 - 01:19 PM

QUOTE(Nick @ Feb 19 2007, 01:14 PM) View Post

Uh... it does. If there is no item previously collected with this script, it will set the current item to the same item that is on the screen. This means it won't try to take anything away. In retrospect, I just realized that it only does this once. That shouldn't matter, still. Taking items is just a matter of setting it to false. The item itself always exists, thus there is no reason to crash.

The crash/freeze is related to how item selection works. Try putting one item in your inventory with cheats. Afterwards, remove it and add another item. Watch ZC freeze when you try to cycle items (despite having just one).

As far as spawning multiple items, I don't think this script would be specifically tailored to do that due to the Screen_Item pointer I make use of to manipulate the spawned item. You would have to make a duplicate script. If you are wanting a script that just spawns multiple items on screen, that would have to be a different script (which wouldn't be difficult to write).

No, I mean, you can use the script to spawn different items, like, on one screen, it gives you the Bombs, but on another, it gives you the Hammer and takes Bombs.

#5 Kite

Kite

  • Members

Posted 19 February 2007 - 01:38 PM

Yes. That works. All you have to do is place items with the d0 value of this script. It's a ffc script, so you have to use it for each screen that has an item. The script handles everything else.

#6 Linkus

Linkus

    .

  • Members
  • Real Name:Adam

Posted 19 February 2007 - 02:30 PM

It just hit me; we're one step closer to a old-school Castlevania-based game.

Now, if only certain items were dropped by a certain enemies(NOT randomly)...


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users