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;
}
}