Jump to content

Photo

GB Shield Edit

edit

  • Please log in to reply
7 replies to this topic

#1 Jared

Jared

    Deified

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

Posted 31 August 2017 - 09:05 PM

I'm using this script in my quest. It works flawlessly for multiple shields. However, I would like it edited slightly so that when Link takes the shield off the A or B button, it disappears from his sprite. Like the actual GB games, so to speak.

 

Thank you very much to whoever can do this. :)


  • Naru likes this

#2 Saffith

Saffith

    IPv7 user

  • ZC Developers

Posted 31 August 2017 - 09:31 PM

I think this'll do it. You'll need to set up a tile mod item for each shield and edit the new constants accordingly. I put in three shields' worth, and it's easy to add more.
 
//import "std.zh"

// Item IDs
const int I_GBSHIELD1 = 1; // The item with the gbshield script
const int I_GBSHIELD1_MOD = 1; // The tile mod item
const int I_GBSHIELD2 = 1;
const int I_GBSHIELD2_MOD = 1;
const int I_GBSHIELD3 = 1;
const int I_GBSHIELD3_MOD = 1;

const int SFX_GBSHIELD = 17; //Shield active SFX

int shieldItem; //Shield item to give (set by item script, reset each frame)
bool shieldButton; //False = B, True = A

global script gbshield_global{
	void run(){
		//Initializations
		bool shieldOn;

		while(true){
			int eqA=GetEquipmentA();
			int eqB=GetEquipmentB();
			if(eqA==I_GBSHIELD1 || eqB==I_GBSHIELD1)
				SetShieldModItems(true, false, false);
			else if(eqA==I_GBSHIELD2 || eqB==I_GBSHIELD2)
				SetShieldModItems(false, true, false);
			else if(eqA==I_GBSHIELD3 || eqB==I_GBSHIELD3)
				SetShieldModItems(false, false, true);
			else
				SetShieldModItems(false, false, false);
			
			if( !shieldOn && shieldItem ){ //Enable shield when using dummy
				shieldOn=true; //Set shield state to on
				Link->Item[shieldItem]=true; //Give the shield
				Game->PlaySound(SFX_GBSHIELD); //Play the sound
			}
			else if( ( (shieldButton && !Link->InputA)||(!shieldButton && !Link->InputB)) //When button is released
					&& shieldOn){ //And shield is still on
				Link->Item[shieldItem]=false; //Remove shield
				shieldItem = 0; //Reset shield item variable
				shieldOn = false; //Set shield state to off
			}

			Waitframe(); //Needed at bottom of while(true) loop
		} // end while
	} //end void run
}

void SetShieldModItems(bool l1, bool l2, bool l3)
{
	if(Link->Item[I_GBSHIELD1_MOD]!=l1)
		Link->Item[I_GBSHIELD1_MOD]=l1;
	if(Link->Item[I_GBSHIELD2_MOD]!=l2)
		Link->Item[I_GBSHIELD2_MOD]=l2;
	if(Link->Item[I_GBSHIELD3_MOD]!=l3)
		Link->Item[I_GBSHIELD3_MOD]=l3;
}

//D0: "Real" shield item to give
item script gbshield{
	void run ( int shield ){
		shieldItem = shield;
		if ( Link->PressB ) shieldButton = false;
		else if ( Link->PressA ) shieldButton = true;
	}
}

  • Jared likes this

#3 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 31 August 2017 - 09:59 PM

Would it not be simpler to store the ID of the item with the highest level in its item class (the shields class), as the item to restore; and to set all shield class items false? That way, you are clearing all shields when the shield is not active, and enabling the best shield in inventory, when it is active; or you could enable an individual shield out of a selection too.

#4 Jared

Jared

    Deified

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

Posted 01 September 2017 - 04:10 PM

Thank you very much Saffith. However, now when Link has the shield it's always held up (And working, as I tested with Octoroks) and when I press the shield button Link's sprite twitches and he goes back to holding it actively again. Did I set something up wrong? Link holds it by his side when I take it off of A or B.



#5 Saffith

Saffith

    IPv7 user

  • ZC Developers

Posted 01 September 2017 - 04:50 PM

Hm... I think I didn't explain it adequately, but also there's a detail I overlooked. Try it this way:
For each shield, set up two shield-type items. One should be level 1, have block and reflect flags of 0, and have the tile mod set to show Link holding the shield at his side. The other should be at least level 2, have normal block and reflect flags, and have the tile mod set to show the shield in front of Link. Use the first set for the I_GBSHIELD*_MOD constants and the second for the item script arguments.

#6 Jared

Jared

    Deified

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

Posted 01 September 2017 - 06:05 PM

I actually already had two for each, and now I have three. I did what you told me, but now the Link sprites are all messed up, and it's still acting the same. He's holding it up forever, and it won't go back down at all. I wonder if I set something up wrong.



#7 Saffith

Saffith

    IPv7 user

  • ZC Developers

Posted 01 September 2017 - 10:19 PM

I did test it; it ought to work. Here's a demo: https://www.dropbox....ldTest.qst?dl=0
If you can't get it going, I'll take a look if you don't mind sending it to me.
  • Jared likes this

#8 Jared

Jared

    Deified

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

Posted 02 September 2017 - 11:34 AM

That is so bizarre. I'll send you my quest. Thank you, Saffith. :)





Also tagged with one or more of these keywords: edit

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users