Jump to content

Photo

Secret makes item appear/fall from ceiling


  • Please log in to reply
8 replies to this topic

#1 Jared

Jared

    Deified

  • Members
  • Real Name:Jared
  • Pronouns:He / Him
  • Location:New Hampshire

Posted 04 February 2021 - 09:06 PM

Script request is right in the title. Thank you :)



#2 ywkls

ywkls

    Master

  • Members

Posted 04 February 2021 - 11:13 PM

Script request is right in the title. Thank you :)

 

I'm guessing that you don't want to use Enemies->Secret?

As long as this isn't Sideview, sounds like a simple script.

//D0- Item to give
//D1- Number from 0 to 7. You can have 8 of them onscreen
ffc script FallingItem{
   void run(int item_to_give){
      if(!Screen->State[ST_SPECIAL_ITEM]){
	  if(Screen->State[ST_SECRET])
		Quit();
      }
      else
          Quit();
      while(true){
		//Do you have the item to trigger the trade?
		if(Screen->State[ST_SECRET]){
			item TradeSeqItem;
			//Create the item and place it at Link's location.
			TradeSeqItem = Screen->CreateItem(item_to_give);
			TradeSeqItem->X = this->X;
			TradeSeqItem->Y = this->Y;
			TradeSeqItem->Z = 16;
			TradeSeqItem->Pickup |= IP_HOLDUP;
                        TradeSeqItem->Pickup |= IP_ST_SPECIALITEM;
                        break;
		}
         Waitframe(); 
      }
   } 
}

I haven't tested this, but it should generate an item which seems to fall from the ceiling at the coordinates off the ffc.


Edited by ywkls, 05 February 2021 - 10:18 PM.


#3 Mitchfork

Mitchfork

    no fun. not ever.

  • Members
  • Real Name:Mitch
  • Location:Alabama

Posted 05 February 2021 - 10:54 AM

Ywkls, seems like the perm variable isn't being set anywhere in the script?  I think it will also spawn every frame, even after you leave and re-enter the screen... which would definitely be interesting but probably not desired behavior. Here's another version.
 
EDIT: I've edited this slightly in response to Venrob's comment below.
EDIT 2: Fixed variable declaration issue that Jared found.
 
This script uses the Special Item of the room that you set it on, so set the Room Type to Special Item and set the item ID.  This is so that I can let the engine handle whether you've picked it up or not without coding anything special, and if you forget to pick it up it'll still spawn next time you enter the room.  I think this code will only work with permanent secrets as well, which is probably how you want to use it anyway but worth noting.
 
If you want the item to be held up, set the screen flag for "Hold Up Item".
 
You can adjust the line "item->Z" if it spawns too high or low... I think it'll be okay as is though.
 
ffc script secretItemDrop {
	void run() {
		if (Screen->State[ST_SPECIALITEM]) {
			Quit();
		}
		
		//get whether to hold up the item
		int holdup = ScreenFlag(SF_ITEMS,SFI_HOLDUP);
		
		while(true) {
			if(Screen->State[ST_SECRET]){
				item drop = CreateItemAt(Screen->RoomData,this->X,this->Y);
				drop->Z = 176; 					//this can be edited if it's too low
				if (holdup)	{
					drop->Pickup = IP_HOLDUP|IP_ST_SPECIALITEM;
				}
				else {
					drop->Pickup = IP_ST_SPECIALITEM;
				}
				Quit();
			}
			Waitframe();
		}
	}
}

Edited by Mitchfork, 05 February 2021 - 07:19 PM.

  • Jared likes this

#4 Emily

Emily

    Scripter / Dev

  • ZC Developers

Posted 05 February 2021 - 11:56 AM

A couple things.

You shouldn't use '0x802', you should use constants from std_constants (you can OR them together with bitwise; it's no slower than a literal number, and it's more readable)

What version is this needed for?

If 2.55, then a combodata script could be used to trigger this effect automatically when secrets are triggered, which would detect temporary as well as permanent secrets easily.

If 2.53, then detecting temporary secrets is a lot harder; you need to place the FFC over a combo that changes, and detect the change in combo ID.

 

When posting a script request in the future, Jared, always specify what version you are working in; both versions have drastically different scripting capabilities, so it's very important to know what you are using.


  • Jared likes this

#5 Mitchfork

Mitchfork

    no fun. not ever.

  • Members
  • Real Name:Mitch
  • Location:Alabama

Posted 05 February 2021 - 12:32 PM

Venrob, you're right on the flags.  I've edited my script to be more readable in that regard.

 

I also added support for the screen flag "Hold Up Item" so that you can toggle that as needed for the item being dropped.

 

Yeah, if this is using 2.55, you could do this by activating a secret combo that turns into a combo with a similar combodata script. 

 

Honestly though I have found that combodata scripts can be more trouble than they're worth... sometimes they're appropriate, but for example on this script it would require you setting up a combo with the appropriate graphics, setting up the secret combo, and placing the flag.  If you wanted to move it after playtesting (common for me) then you have to delete the old flag, place a new one, and change the combo graphics... and if you use it multiple places in the quest, you'd have to create different combos for all of those.  FFC's are nice because most of the time you don't even have to set up graphics at all and you can move them at-will.



#6 Jared

Jared

    Deified

  • Members
  • Real Name:Jared
  • Pronouns:He / Him
  • Location:New Hampshire

Posted 05 February 2021 - 06:25 PM

Thank you guys so much! And thank you Venrob, I do need to remember the version I am using.

 

When compiling, I get the error of three things not declared (variable item)



#7 Mitchfork

Mitchfork

    no fun. not ever.

  • Members
  • Real Name:Mitch
  • Location:Alabama

Posted 05 February 2021 - 06:53 PM

Yeah, I was missing a variable declaration and also using the name "item" which is bad since it is also used by a variable type... should be fixed now.


  • Jared likes this

#8 Emily

Emily

    Scripter / Dev

  • ZC Developers

Posted 05 February 2021 - 09:31 PM

On the combodata topic, you wouldn't need different graphics. I'd just make it an invisible combo, and place it on a layer.


  • Jared likes this

#9 ywkls

ywkls

    Master

  • Members

Posted 05 February 2021 - 10:21 PM

Ywkls, seems like the perm variable isn't being set anywhere in the script?  I think it will also spawn every frame, even after you leave and re-enter the screen... which would definitely be interesting but probably not desired behavior. 

Yeah I just noticed those errors. 

That's what happens when you copy/paste scripts.

 

 

 

This script uses the Special Item of the room that you set it on, so set the Room Type to Special Item and set the item ID.  This is so that I can let the engine handle whether you've picked it up or not without coding anything special, and if you forget to pick it up it'll still spawn next time you enter the room.  I think this code will only work with permanent secrets as well, which is probably how you want to use it anyway but worth noting.

I didn't think of that but it's a totally viable option.

Added to my code.

 

 

If you want the item to be held up, set the screen flag for "Hold Up Item".

I'm not sure if this works on items created by a script?

One fact which isn't obvious is that objects that can be slashed can have items hidden under them without scripts.

Simply use flag 10 and when the combo changes, it will spawn an item where the combo was.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users