Jump to content

Photo

Shield script not working!


  • Please log in to reply
1 reply to this topic

#1 Shadowblitz16

Shadowblitz16

    Illustrious

  • Members

Posted 24 January 2017 - 06:10 PM

ok so I got this script from the gb script set however it seems that I cannot activate my shield

 

I have set LTM_SHIELD_ON to the item when link is holding the button with the proper item

and I have set LTM_SHIELD_OFF to the item when link is not holding the button with the proper item

 

I have them both with LTM's and I also have a custom shield class which I have the id of in I_SHIELD

 

I have also attached the shield item script to the custom item class

 

link seems to equip the shield fine its just he can't use it

 

I have the custom itemset marked as a equipment item

and the LTM items are just for show

 

this is the script I am using

// game boy like shield

int using_shield;
bool shield_is_on;
int shield_counter;
int StoreInput;

// global function
// set the change link tiles item when Link has the shield on A or B
void Shield()
{
	if(GetEquipmentA()==I_SHIELD || GetEquipmentB()==I_SHIELD)
	{
		if(!Link->Item[LTM_SHIELD_OFF] && !Link->Item[LTM_SHIELD_ON]) Link->Item[LTM_SHIELD_OFF]=true;
			if(shield_is_on) ShieldON();
		else if(Link->Item[LTM_SHIELD_ON]) Link->Item[LTM_SHIELD_ON]=false;
	}
	else 
	{
		if(Link->Item[LTM_SHIELD_ON])
		{
			Link->Item[LTM_SHIELD_ON]=false;
		}
		if(Link->Item[LTM_SHIELD_OFF])
		{
			Link->Item[LTM_SHIELD_OFF]=false;
		}
		shield_is_on = false;
	}
}

void ShieldON(){
	if( (StoreInput==1 && !Link->InputA) || (StoreInput==2 && !Link->InputB) ) shield_is_on = false;
	if(!Link->Item[LTM_SHIELD_ON]) Link->Item[LTM_SHIELD_ON]=true;
	shield_counter++;
	PushBackEnemies(shield_counter);
}

void PushBackEnemies(int shield_counter){
	npc enemy;
	int shift;
	for(int n=1;n<=Screen->NumNPCs();n++)
	{
		enemy = Screen->LoadNPC(n);

		if(enemy->Misc[4] > 0) continue; // means the enemy cannot be pushed by shield
		if(enemy->Z > 0) continue;
		if(enemy->Damage <= 0) continue; // zero damage enemies are not affected

		if(Link->Dir==DIR_LEFT)
		{
			shift = -1;
			if( Abs(TouchedX()-CenterX(enemy)) <= 8 && Abs(CenterLinkY()-CenterY(enemy)) <= 8 )
			{
				// Abs(Link->Y-enemy->Y) <= 16 ){
				enemy->Stun = 20;
				if(CanWalk(enemy->X,enemy->Y,(5+shift)/2,2,true)) enemy->X += shift;
				else Link->X -= shift;
				if(shield_counter%2==0) 
				{
					Link->InputLeft = false;
					Link->X -= shift;
				}
			}
		}
		else if(Link->Dir==DIR_RIGHT)
		{
			shift = 1;
			if( Abs(TouchedX()-CenterX(enemy)) <= 8 && Abs(CenterLinkY()-CenterY(enemy)) <= 8 )
			{ 
				// Abs(Link->Y-enemy->Y) <= 16 ){
				enemy->Stun = 20;
				if(CanWalk(enemy->X,enemy->Y,(5+shift)/2,2,true)) enemy->X += shift;
				else Link->X -= shift;
				if(shield_counter%2==0) {
				Link->InputRight = false;
				Link->X -= shift;
				}
			}
		}
		else if(Link->Dir==DIR_UP)
		{
			shift = -1;
			if( Abs(TouchedY()-2-CenterY(enemy)) <= 8 && Abs(CenterLinkX()-CenterX(enemy)) <= 8 )
			{ // Abs(Link->X-enemy->X) <= 16 ){ // note: additional "-2" needed here!
				enemy->Stun = 20;
				if(CanWalk(enemy->X,enemy->Y,(1+shift)/2,2,true)) enemy->Y += shift;
				else Link->Y -= shift;
				if(shield_counter%2==0) 
				{
					Link->InputUp = false;
					Link->Y -= shift;
				}
			}
		}
		else if(Link->Dir==DIR_DOWN)
		{
			shift = 1;
			if( Abs(TouchedY()-CenterY(enemy)) <= 8 && Abs(CenterLinkX()-CenterX(enemy)) <= 8 )
			{ // Abs(Link->X-enemy->X) <= 16 ){
				enemy->Stun = 20;
				if(CanWalk(enemy->X,enemy->Y,(1+shift)/2,2,true)) enemy->Y += shift;
				else Link->Y -= shift;

				if(shield_counter%2==0)
				{
					Link->InputDown = false;
					Link->Y -= shift;
				}
			}
		}
	}
}

// item script
item script Shield
{
	void run()
	{
		shield_is_on = true;
		Game->PlaySound(SFX_SHIELD);
		if(Link->InputB && !Link->InputA) StoreInput = 2;
		else if(Link->InputA && !Link->InputB) StoreInput = 1;
	}
}


#2 Shadowblitz16

Shadowblitz16

    Illustrious

  • Members

Posted 28 January 2017 - 07:47 PM

bump




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users