Jump to content

Photo

Similar Script Combine


  • Please log in to reply
1 reply to this topic

#1 Jared

Jared

    Deified

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

Posted 20 June 2018 - 06:31 PM

Hi, I was wondering if someone could combine some scripts for me. I currently have a script where Link pushes pushes a block, and pulls when he has a specific item (That is mapped to L) he can pull it when he holds the button.

 

However, I would also like this combined with a pickup script, where Link can also pick up rocks and such, by holding down the L button a pulling backwards (Like the games obviously)

 

This is the script, unless someone else thinks they can do better. :P https://www.purezc.n...e=scripts&id=32

 

Whoever, can do this, thank you. And the original push/pull script was written by Moosh. Some of it is combined already, as you can probably see:

ffc script PushPullBlock{
	void run(){
		int pushDir[176];
		int pushOnce[176];
		int pushCount[176];
		int vars[16] = {pushDir, pushOnce, pushCount, -1, -1};
		for(int i=0; i<176; i++){
			int cf = Screen->ComboF[i];
			if(cf==1){
				pushDir[i] = 0011b;
				pushOnce[i] = 2;
				Screen->ComboF[i] = 0;
			}
			else if(cf==2){
				pushDir[i] = 1111b;
				pushOnce[i] = 2;
				Screen->ComboF[i] = 0;
			}
			else if(cf==47){
				pushDir[i] = 1100b;
				pushOnce[i] = 2;
				Screen->ComboF[i] = 0;
			}
			else if(cf==48){
				pushDir[i] = 0001b;
				pushOnce[i] = 2;
				Screen->ComboF[i] = 0;
			}
			else if(cf==49){
				pushDir[i] = 0010b;
				pushOnce[i] = 2;
				Screen->ComboF[i] = 0;
			}
			else if(cf==50){
				pushDir[i] = 0100b;
				pushOnce[i] = 2;
				Screen->ComboF[i] = 0;
			}
			else if(cf==51){
				pushDir[i] = 1000b;
				pushOnce[i] = 2;
				Screen->ComboF[i] = 0;
			}
			else if(cf==52){
				pushDir[i] = 0011b;
				pushOnce[i] = 1;
				Screen->ComboF[i] = 0;
			}
			else if(cf==53){
				pushDir[i] = 1100b;
				pushOnce[i] = 1;
				Screen->ComboF[i] = 0;
			}
			else if(cf==54){
				pushDir[i] = 1111b;
				pushOnce[i] = 1;
				Screen->ComboF[i] = 0;
			}
			else if(cf==55){
				pushDir[i] = 0001b;
				pushOnce[i] = 1;
				Screen->ComboF[i] = 0;
			}
			else if(cf==56){
				pushDir[i] = 0010b;
				pushOnce[i] = 1;
				Screen->ComboF[i] = 0;
			}
			else if(cf==57){
				pushDir[i] = 0100b;
				pushOnce[i] = 1;
				Screen->ComboF[i] = 0;
			}
			else if(cf==58){
				pushDir[i] = 1000b;
				pushOnce[i] = 1;
				Screen->ComboF[i] = 0;
			}
			else if(cf==59){
				pushDir[i] = 0011b;
				pushOnce[i] = 0;
				Screen->ComboF[i] = 0;
			}
			else if(cf==60){
				pushDir[i] = 1100b;
				pushOnce[i] = 0;
				Screen->ComboF[i] = 0;
			}
			else if(cf==61){
				pushDir[i] = 1111b;
				pushOnce[i] = 0;
				Screen->ComboF[i] = 0;
			}
			else if(cf==62){
				pushDir[i] = 0001b;
				pushOnce[i] = 0;
				Screen->ComboF[i] = 0;
			}
			else if(cf==63){
				pushDir[i] = 0010b;
				pushOnce[i] = 0;
				Screen->ComboF[i] = 0;
			}
			else if(cf==64){
				pushDir[i] = 0100b;
				pushOnce[i] = 0;
				Screen->ComboF[i] = 0;
			}
			else if(cf==65){
				pushDir[i] = 1000b;
				pushOnce[i] = 0;
				Screen->ComboF[i] = 0;
			}
			else{
				pushOnce[i] = -1;
			}
		}
		while(true){
			PushPullBlock_Update(vars);
			Waitframe();
		}
	}
	void PushPullBlock_Update(int vars){
		int i;
		int pushDir = vars[0];
		int pushOnce = vars[1];
		int pushCount = vars[2];
		for(i=0; i<176; i++){
			if(pushOnce[i]>-1){
				int dirLink = AngleDir4(Angle(ComboX(i), ComboY(i), Link->X, Link->Y));
				if(dirLink==DIR_UP)
					Screen->ComboF[i] = 62;
				else if(dirLink==DIR_DOWN)
					Screen->ComboF[i] = 63;
				else if(dirLink==DIR_LEFT)
					Screen->ComboF[i] = 64;
				else if(dirLink==DIR_RIGHT)
					Screen->ComboF[i] = 65;
			}
		}
		int pushPos = PushPullBlock_ComboInFrontOfLink();
		if(pushPos>-1){
			if((Link->Dir==DIR_UP&&Link->InputUp) ||
				(Link->Dir==DIR_DOWN&&Link->InputDown) ||
				(Link->Dir==DIR_LEFT&&Link->InputLeft) ||
				(Link->Dir==DIR_RIGHT&&Link->InputRight)){
				if(pushDir[pushPos]&(1<<Link->Dir)&&PushPullBlock_CanMove(pushPos, Link->Dir)){
					
					pushCount[pushPos]++;
					if(pushCount[pushPos]>16){
						pushCount[pushPos] = 0;
						
						vars[3] = ComboX(pushPos);
						vars[4] = ComboY(pushPos);
						vars[5] = Link->Dir;
						vars[6] = 1;
						vars[8] = Screen->ComboD[pushPos];
						vars[9] = Screen->ComboC[pushPos];
						vars[10] = pushDir[pushPos];
						vars[11] = pushOnce[pushPos];
						
						Screen->ComboD[pushPos] = Screen->UnderCombo;
						Screen->ComboC[pushPos] = Screen->UnderCSet;
						Screen->ComboF[pushPos] = 0;
						pushDir[pushPos] = 0;
						pushOnce[pushPos] = -1;
						
						Game->PlaySound(SFX_PUSHBLOCK);
					}
				}
				else
					pushCount[i] = 0;
			}
			else if(Link->Item[I_LTM_PULL]&&Link->Misc[LINKMISC_PULLTIMER]>=16){
				if(pushDir[pushPos]&(1<<OppositeDir(Link->Dir))&&PushPullBlock_CanMove(pushPos, OppositeDir(Link->Dir))&&CanWalk(Link->X, Link->Y, OppositeDir(Link->Dir), 16, false)){

					pushCount[pushPos] = 0;
					
					vars[3] = ComboX(pushPos);
					vars[4] = ComboY(pushPos);
					vars[5] = OppositeDir(Link->Dir);
					vars[6] = 2;
					vars[8] = Screen->ComboD[pushPos];
					vars[9] = Screen->ComboC[pushPos];
					vars[10] = pushDir[pushPos];
					vars[11] = pushOnce[pushPos];
					
					Screen->ComboD[pushPos] = Screen->UnderCombo;
					Screen->ComboC[pushPos] = Screen->UnderCSet;
					Screen->ComboF[pushPos] = 0;
					pushDir[pushPos] = 0;
					pushOnce[pushPos] = -1;
					
					Game->PlaySound(SFX_PUSHBLOCK);
				}
			}
			else
				pushCount[i] = 0;
		}
		if(vars[3]>-1){
			if(vars[6]!=2&&!CanWalk(Link->X, Link->Y, vars[5], 1, false))
				vars[6] = 0;
			Link->Misc[LINKMISC_PULLTIMER] = -1;
			if(vars[5]==DIR_UP){
				vars[4]--;
				if(vars[6]){
					if(vars[6]==2)
						Link->Y = vars[4]-16;
					else
						Link->Y = vars[4]+8;
				}
			}
			else if(vars[5]==DIR_DOWN){
				vars[4]++;
				if(vars[6]){
					if(vars[6]==2)
						Link->Y = vars[4]+8;
					else
						Link->Y = vars[4]-16;
				}
			}
			else if(vars[5]==DIR_LEFT){
				vars[3]--;
				if(vars[6]){
					if(vars[6]==2)
						Link->X = vars[3]-16;
					else
						Link->X = vars[3]+16;
				}
			}
			else if(vars[5]==DIR_RIGHT){
				vars[3]++;
				if(vars[6]){
					if(vars[6]==2)
						Link->X = vars[3]+16;
					else
						Link->X = vars[3]-16;
				}
			}
			Screen->FastCombo(2, vars[3], vars[4], vars[8], vars[9], 128);
			NoAction();
			
			if(vars[3]%16==0&&vars[4]%16==0){
				Link->Misc[LINKMISC_PULLTIMER] = 1;
				
				i = ComboAt(vars[3]+8, vars[4]+8);
				Screen->ComboD[i] = vars[8];
				Screen->ComboC[i] = vars[9];
				pushDir[i] = vars[10];
				pushOnce[i] = vars[11];
				pushCount[i] = 0;
				if(vars[11]>0){
					if(vars[11]==2){
						Screen->TriggerSecrets();
						Game->PlaySound(SFX_SECRET);
					}
					pushDir[i] = 0;
				}
				
				vars[3] = -1;
				vars[4] = -1;
			}
		}
	}
	bool PushPullBlock_CanMove(int pos, int dir){
		if(pos<16)
			return false;
		else if(pos>159)
			return false;
		if(pos%16==0)
			return false;
		else if(pos%16==15)
			return false;
		
		if(dir==DIR_UP)
			pos -= 16;
		else if(dir==DIR_DOWN)
			pos += 16;
		else if(dir==DIR_LEFT)
			pos--;
		else if(dir==DIR_RIGHT)
			pos++;
		
		int x = ComboX(pos)+4;
		int y = ComboY(pos)+4;
		if(Screen->isSolid(x, y) || 
			Screen->isSolid(x+8, y) || 
			Screen->isSolid(x, y+8) || 
			Screen->isSolid(x+8, y+8)){
				
			return false;
		}
		
		if(ComboFI(pos, CF_NOBLOCKS))
			return false;
		
		return true;
	}
	int PushPullBlock_ComboInFrontOfLink(){
		if(!CanWalk(Link->X, Link->Y, Link->Dir, 1, false)){
			int x; int y;
			if(Link->Dir==DIR_UP){
				x = Link->X+8;
				y = Link->Y+7;
			}
			else if(Link->Dir==DIR_DOWN){
				x = Link->X+8;
				y = Link->Y+16;
			}
			else if(Link->Dir==DIR_LEFT){
				x = Link->X-1;
				y = Link->Y+12;
			}
			else if(Link->Dir==DIR_RIGHT){
				x = Link->X+16;
				y = Link->Y+12;
			}
			if(x>=0&&x<=255&&y>=0&&y<=175)
				return ComboAt(x, y);
		}
		return -1;
	}
}

bool CanWalkNoEdge(int x, int y, int dir, int step, bool full_tile) {
    int c=8;
    int xx = x+15;
    int yy = y+15;
    if(full_tile) c=0;
    if(dir==0) return !(Screen->isSolid(x,y+c-step)||Screen->isSolid(x+8,y+c-step)||Screen->isSolid(xx,y+c-step));
    else if(dir==1) return !(Screen->isSolid(x,yy+step)||Screen->isSolid(x+8,yy+step)||Screen->isSolid(xx,yy+step));
    else if(dir==2) return !(Screen->isSolid(x-step,y+c)||Screen->isSolid(x-step,y+c+7)||Screen->isSolid(x-step,yy));
    else if(dir==3) return !(Screen->isSolid(xx+step,y+c)||Screen->isSolid(xx+step,y+c+7)||Screen->isSolid(xx+step,yy));
    return false; //invalid direction
}

//Item ID used by the two Link Tile Modifier items
const int I_LTM_PUSH = 144;
const int I_LTM_PULL = 145;

const int I_PUSHPULLBRACELET = 107; //Item ID of the bracelet item

const int LINKMISC_PULLTIMER = 0; //Link->Misc used for keeping track of pulling

void PushPull_Init(){
	Link->Item[I_LTM_PUSH] = false;
	Link->Item[I_LTM_PULL] = false;
	
	Link->Misc[LINKMISC_PULLTIMER] = 0;
}

void PushPull_Update(){
	if(!CanWalkNoEdge(Link->X, Link->Y, Link->Dir, 1, false)){
		if(Link->Action!=LA_NONE&&Link->Action!=LA_WALKING){
			if(Link->Item[I_LTM_PUSH])
				Link->Item[I_LTM_PUSH] = false;
			if(Link->Item[I_LTM_PULL])
				Link->Item[I_LTM_PULL] = false;
		}
		else if((Link->InputL&&Link->Item[I_PUSHPULLBRACELET])||UsingItem(I_PUSHPULLBRACELET)){
			if(Link->InputUp&&Link->InputDown){
				Link->InputUp = false;
				Link->InputDown = false;
			}
			if(Link->InputLeft&&Link->InputRight){
				Link->InputLeft = false;
				Link->InputRight = false;
			}
			if(!Link->Item[I_LTM_PUSH])
				Link->Item[I_LTM_PUSH] = true;
			if((Link->Dir==DIR_UP&&Link->InputDown) ||
				(Link->Dir==DIR_DOWN&&Link->InputUp) ||
				(Link->Dir==DIR_LEFT&&Link->InputRight) ||
				(Link->Dir==DIR_RIGHT&&Link->InputLeft)){
				
				if(Link->Misc[LINKMISC_PULLTIMER]<16)
					Link->Misc[LINKMISC_PULLTIMER]++;
				if(!Link->Item[I_LTM_PULL])
					Link->Item[I_LTM_PULL] = true;
			}
			else if(Link->Item[I_LTM_PULL])
				Link->Item[I_LTM_PULL] = false;
			NoAction();
		}
		else if((Link->Dir==DIR_UP&&Link->InputUp) ||
			(Link->Dir==DIR_DOWN&&Link->InputDown) ||
			(Link->Dir==DIR_LEFT&&Link->InputLeft) ||
			(Link->Dir==DIR_RIGHT&&Link->InputRight)){
			
			Link->Misc[LINKMISC_PULLTIMER] = 1;
			
			if(!Link->Item[I_LTM_PUSH])
				Link->Item[I_LTM_PUSH] = true;
			if(Link->Item[I_LTM_PULL])
				Link->Item[I_LTM_PULL] = false;
		}
		else{
			if(Link->Misc[LINKMISC_PULLTIMER]>0)
				Link->Misc[LINKMISC_PULLTIMER]--;
			else if(Link->Item[I_LTM_PUSH] || Link->Item[I_LTM_PULL]){
				Link->Item[I_LTM_PUSH] = false;
				Link->Item[I_LTM_PULL] = false;
			}
		}
	}
	else if(Link->Misc[LINKMISC_PULLTIMER]!=-1&&(Link->Item[I_LTM_PUSH] || Link->Item[I_LTM_PULL])){
		Link->Item[I_LTM_PUSH] = false;
		Link->Item[I_LTM_PULL] = false;
	}
}

void LinkHurtSounds_Update(int hurtSFX){
	if(hurtSFX[0]==0){ //Link isn't in hurt frames
		if(Link->Action==LA_GOTHURTLAND||Link->Action==LA_GOTHURTWATER){
			int size = SizeOfArray(hurtSFX)-1;
			Game->PlaySound(hurtSFX[Rand(size)+1]); //Play a random sound from the array
			hurtSFX[0] = 1; //Mark Link as in hurt frames
		}
	}
	else{ //Link is in hurt frames
		if(Link->Action!=LA_GOTHURTLAND&&Link->Action!=LA_GOTHURTWATER){
			hurtSFX[0] = 0; //Mark Link as not in hurt frames
		}
	}
}

//SFX for Link getting hurt. You can add more of these and add them to the hurtSFX[] array for more options
const int SFX_LINKHURT1 = 66;
const int SFX_LINKHURT2 = 67;
const int SFX_LINKHURT3 = 68;
const int SFX_LINKHURT4 = 69;

global script PushPull{
	void run(){
		//The first number in this array should be 0. The rest are the SFX options.
		int hurtSFX[] = {0, SFX_LINKHURT1, SFX_LINKHURT2, SFX_LINKHURT3, SFX_LINKHURT4};
		PushPull_Init();
		while(true){
			PushPull_Update();
			LinkHurtSounds_Update(hurtSFX);
			Waitframe();
		}
	}
}

Edited by Jared, 20 June 2018 - 06:32 PM.


#2 Moosh

Moosh

    Tiny Little Questmaker

  • ZC Developers

Posted 21 June 2018 - 04:37 AM

VU5tOSF.png

 

Oh boy! The hot mess just got a whole lot messier. I mashed Zepinho's script and mine together in whatever ways I could, but this is not a script that I recommend anybody aside from Jared to use and modify. If more features keep getting tacked on this thing like a big ball of mud at some point somebody is going to go postal. :P

 

Hopefully at some point in the future I'll get around to making a better power bracelet script. 

 

Scrollbar pls go

 

Setup for the global should be the same as Zepinho's script. All traces of my global script for the block pulling FFC are gone now.


  • Avaro, Jared and coolgamer012345 like this


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users