Jump to content

Photo

spawning the bush combo's leaves using a script


  • Please log in to reply
13 replies to this topic

#1 idontknow8

idontknow8

    Senior

  • Members

Posted 31 January 2017 - 08:41 PM

Is there a way to spawn the bush's leaves animation using a script?



#2 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 01 February 2017 - 01:03 AM

void GenerateSprite(int sprite, int x, int y){
    lweapon sprite = Screen->GreateLWeapon(LW_SPARKE);
    sprite->X = x;
    sprite->Y = y;
    sprite->CollDetection = false;
}


#3 judasrising

judasrising

    I play guitar

  • Members
  • Location:Sweden but born in Finland

Posted 02 February 2017 - 12:31 PM

void GenerateSprite(int sprite, int x, int y){
    lweapon sprite = Screen->GreateLWeapon(LW_SPARKE);
    sprite->X = x;
    sprite->Y = y;
    sprite->CollDetection = false;
}

I would like to use that piece of code for something i have in mind,

but i get compiler error in line 2 There is already variable name sprite defined in this scope

 

void GenerateSprite(int sprite, int x, int y){
    lweapon sprite = Screen->CreateLWeapon(LW_SPARKLE);
    sprite->X = x;
    sprite->Y = y;
    sprite->CollDetection = false;
}


#4 ywkls

ywkls

    Master

  • Members

Posted 02 February 2017 - 01:28 PM

 

I would like to use that piece of code for something i have in mind,

but i get compiler error in line 2 There is already variable name sprite defined in this scope

 

void GenerateSprite(int sprite, int x, int y){
    lweapon sprite = Screen->CreateLWeapon(LW_SPARKLE);
    sprite->X = x;
    sprite->Y = y;
    sprite->CollDetection = false;
}

 

The int in the void has the same value as the lweapon.

 

It'd probably be easiest to change it like this.

I also added a line, because it didn't actually generate a sprite in the original code.

void GenerateSprite(int Sprite, int x, int y){
    lweapon sprite = Screen->CreateLWeapon(LW_SPARKE);
    sprite->X = x;
    sprite->Y = y;
    sprite->CollDetection = false;
    sprite->UseSprite(Sprite);
}

Edited by ywkls, 02 February 2017 - 01:29 PM.


#5 Avaro

Avaro

    o_o

  • Members
  • Real Name:Robin
  • Location:Germany

Posted 03 February 2017 - 11:52 AM

You can recreate the bush leaves effect that easily? Why would a sparkle animate like bush leaves? I'll try this out sometime.

Also, in the code "sparkle" is mispelled.

Edited by Avataro, 03 February 2017 - 11:53 AM.


#6 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 03 February 2017 - 12:27 PM

You can recreate the bush leaves effect that easily? Why would a sparkle animate like bush leaves? I'll try this out sometime.

Also, in the code "sparkle" is mispelled.


Oops, it should be this:
 
void GenerateSprite(int sprite, int x, int y){
	lweapon l = Screen->CreateLWeapon(LW_SPARKLE);
	l->X = x; l->Y = y; l->UseSprite(sprite);
	l->CollDetection = false;
}

void GenerateSprite(int sprite, int x, int y, bool collision){
	lweapon l = Screen->CreateLWeapon(LW_SPARKLE);
	l->X = x; l->Y = y; l->UseSprite(sprite);
	l->CollDetection = collision;
}

void GenerateSprite(int sprite, int x, int y, int width, int height, bool collision){
	lweapon l = Screen->CreateLWeapon(LW_SPARKLE);
	l->X = x; l->Y = y; l->UseSprite(sprite);
	l->CollDetection = collision;
	l->TileWidth = width; l->TileHeight = height;
}

const int SPRITE_DEBUG_ENABLED = 1; //Se tto '0' to suppress errors. 

//Generate a sprite, passing arrays for its params. 
//GenerateSprite(sprite_id, x, y, values[], flags[] where:
//	flags[]: 
//	[0] = collision, [1] = angular [2]= draw behind link
//	values[]: 
//	[0] width, [1] height, [2] hitXoffset [3] hitYhoffset [4]drawXoffset [5]drawYoffset
//	[6] cset, [7] jump, [8] Dir, [9] ASpeed [10] damage [11] step [12] flip
//	[13] hitHeight [14] hitWidth [15] hitZHeight

void GenerateSprite(int sprite, int x, int y, int values, bool flags){
	int params[16]; int q; int bflags[3];
	int ___s__err[]="Array size mismatch when calling GenerateSprite(sprite, x, y, values[], flags[])";
	//This ensures that if we pass a non-pointer, that we suppress the values
	//and that if our array size is a mismatch, we copy values over, and do not simply error out.
	if ( values == 0 ) { 
		for q = 0; q < 16; q++ ) params[q] = 0; 
		if ( SPRITE_DEBUG_ENABLED ) { TraceS(___s__err); } //Trace an error.  
	}
	    
	else { 
		int size = SizeOfArray(values); 
		if ( size <= 16 ) {
			for ( q = 0; q < size; q++ ) { params[q] = values[q]; }
			if ( SPRITE_DEBUG_ENABLED ) TraceS(___s__err); //Trace an error. 
		}
		else ( for q = 0; q < 16; q++ ) { params[q] = values[q]; }
	}

	//The same for the boolean flags. 
	if ( flags == false ) { //If the pointer is zero, or the user uses 'false' as an input.
		for ( q = 0; q < 3; q++ ) bflags[q] = false; 
	}
	else { 	//! 2.54 has a way to read the size of a boolean array, 2.50.x does not...thus...
		//Uncomment the next FIVE lines if using 2.54
		//int bsize = SizeOfArrayB(flags); 
		//if ( bsize <= 3 ) {
		//    for ( q = 0; q < bsize; q++ ) { bflags[q] = flags[q]; }
		//}
		//else ( for q = 0; q < 3; q++ ) { bflags[q] = flags[q]; }
        
		//COMMENT OUT the following LINE if you ARE using 2.54:
		for ( q = 0; q < 3; q++ ) bflags[q] = flags[q];
	}

	//Make the object:
	lweapon l = Screen->CreateLWeapon(LW_SPARKLE);
	l->X = x; l->Y = y; l->UseSprite(sprite);
	l->CollDetection = bflags[0]; l->Angular = bflags[1]; 
	l->Behind = bflags[2];
	l->TileWidth = params[0]; l->TileHeight = params[1];
	l->HitXOffset = params[2]; l->HitYOffset = params[3];
	l->DrawXOffset = params[4]; l->DrawYOffset = params[5];
	l->Cset = params[6]; l->Jump = params[7]; l->Dir = params[8]; 
	l->ASpeed = params[9]; l->Damage = params[10]; l->Step = params[11];
	l->Flip = params[12]; l->HitHeight = params[13]; l->HitWidth = params[14];
	l->HitZHeight = params[15];
}
My apologies. I included some related functions as a way of making up for the error: The last one is particularly fun... Enjoy. I hope that these do not have a similar fate to my last post, as I didn't parse them, but any errors would be mere typos.

@Avataro:

LW_SPARKLE lweapons have a lifespan equal to their frames. That is why they are useful for generic sprites.

Because LW_SPARKLE weapons have the same default properties as the sprite that they use, the 'weapon' has the same visual effect as the sprite of the bush clippings.

Edited by ZoriaRPG, 03 February 2017 - 12:36 PM.

  • Avaro likes this

#7 idontknow8

idontknow8

    Senior

  • Members

Posted 03 February 2017 - 06:06 PM

Oops, it should be this:
 

void GenerateSprite(int sprite, int x, int y){
	lweapon l = Screen->CreateLWeapon(LW_SPARKLE);
	l->X = x; l->Y = y; l->UseSprite(sprite);
	l->CollDetection = false;
}

void GenerateSprite(int sprite, int x, int y, bool collision){
	lweapon l = Screen->CreateLWeapon(LW_SPARKLE);
	l->X = x; l->Y = y; l->UseSprite(sprite);
	l->CollDetection = collision;
}

void GenerateSprite(int sprite, int x, int y, int width, int height, bool collision){
	lweapon l = Screen->CreateLWeapon(LW_SPARKLE);
	l->X = x; l->Y = y; l->UseSprite(sprite);
	l->CollDetection = collision;
	l->TileWidth = width; l->TileHeight = height;
}

const int SPRITE_DEBUG_ENABLED = 1; //Se tto '0' to suppress errors. 

//Generate a sprite, passing arrays for its params. 
//GenerateSprite(sprite_id, x, y, values[], flags[] where:
//	flags[]: 
//	[0] = collision, [1] = angular [2]= draw behind link
//	values[]: 
//	[0] width, [1] height, [2] hitXoffset [3] hitYhoffset [4]drawXoffset [5]drawYoffset
//	[6] cset, [7] jump, [8] Dir, [9] ASpeed [10] damage [11] step [12] flip
//	[13] hitHeight [14] hitWidth [15] hitZHeight

void GenerateSprite(int sprite, int x, int y, int values, bool flags){
	int params[16]; int q; int bflags[3];
	int ___s__err[]="Array size mismatch when calling GenerateSprite(sprite, x, y, values[], flags[])";
	//This ensures that if we pass a non-pointer, that we suppress the values
	//and that if our array size is a mismatch, we copy values over, and do not simply error out.
	if ( values == 0 ) { 
		for q = 0; q < 16; q++ ) params[q] = 0; 
		if ( SPRITE_DEBUG_ENABLED ) { TraceS(___s__err); } //Trace an error.  
	}
	    
	else { 
		int size = SizeOfArray(values); 
		if ( size <= 16 ) {
			for ( q = 0; q < size; q++ ) { params[q] = values[q]; }
			if ( SPRITE_DEBUG_ENABLED ) TraceS(___s__err); //Trace an error. 
		}
		else ( for q = 0; q < 16; q++ ) { params[q] = values[q]; }
	}

	//The same for the boolean flags. 
	if ( flags == false ) { //If the pointer is zero, or the user uses 'false' as an input.
		for ( q = 0; q < 3; q++ ) bflags[q] = false; 
	}
	else { 	//! 2.54 has a way to read the size of a boolean array, 2.50.x does not...thus...
		//Uncomment the next FIVE lines if using 2.54
		//int bsize = SizeOfArrayB(flags); 
		//if ( bsize <= 3 ) {
		//    for ( q = 0; q < bsize; q++ ) { bflags[q] = flags[q]; }
		//}
		//else ( for q = 0; q < 3; q++ ) { bflags[q] = flags[q]; }
        
		//COMMENT OUT the following LINE if you ARE using 2.54:
		for ( q = 0; q < 3; q++ ) bflags[q] = flags[q];
	}

	//Make the object:
	lweapon l = Screen->CreateLWeapon(LW_SPARKLE);
	l->X = x; l->Y = y; l->UseSprite(sprite);
	l->CollDetection = bflags[0]; l->Angular = bflags[1]; 
	l->Behind = bflags[2];
	l->TileWidth = params[0]; l->TileHeight = params[1];
	l->HitXOffset = params[2]; l->HitYOffset = params[3];
	l->DrawXOffset = params[4]; l->DrawYOffset = params[5];
	l->Cset = params[6]; l->Jump = params[7]; l->Dir = params[8]; 
	l->ASpeed = params[9]; l->Damage = params[10]; l->Step = params[11];
	l->Flip = params[12]; l->HitHeight = params[13]; l->HitWidth = params[14];
	l->HitZHeight = params[15];
}
My apologies. I included some related functions as a way of making up for the error: The last one is particularly fun... Enjoy. I hope that these do not have a similar fate to my last post, as I didn't parse them, but any errors would be mere typos.

@Avataro:

LW_SPARKLE lweapons have a lifespan equal to their frames. That is why they are useful for generic sprites.

Because LW_SPARKLE weapons have the same default properties as the sprite that they use, the 'weapon' has the same visual effect as the sprite of the bush clippings.

 

 

I was wondering the same thing about the LW_SPARKLE...

 

Now i'm even more confused as to where to put all this in the script and how to actually make the leaves appear under the condition that I want.  I'm guessing all this goes in the global script but then I need to add an "if" statement in my ffc script?

 

Basically the condition is if the lweapon of another custom scripted-weapon collides with a bush combo, it should generate change said bush combo to the next combo in the combo table (which I've already successfully done) AND spawn the bush leaves.



#8 ywkls

ywkls

    Master

  • Members

Posted 03 February 2017 - 06:26 PM

I was wondering the same thing about the LW_SPARKLE...

 

Now i'm even more confused as to where to put all this in the script and how to actually make the leaves appear under the condition that I want.  I'm guessing all this goes in the global script but then I need to add an "if" statement in my ffc script?

 

Basically the condition is if the lweapon of another custom scripted-weapon collides with a bush combo, it should generate change said bush combo to the next combo in the combo table (which I've already successfully done) AND spawn the bush leaves.

 

Those functions can be put anywhere in your script file, as long as it outside of any ffc, item or global scripts. This allows them to be used by any of those at your discretion.

 

Once you do that, you can add a line in your ffc script (either right before or immediately after the part where the combo changes) that calls that function as sets the values of its arguments.

 

I'd recommend before, so you can use the X and Y position of the combo you're changing (in the case, ComboX and ComboY) to position the sprite you're generating.



#9 idontknow8

idontknow8

    Senior

  • Members

Posted 03 February 2017 - 06:32 PM

 

Once you do that, you can add a line in your ffc script (either right before or immediately after the part where the combo changes) that calls that function as sets the values of its arguments.

 

How do I do that?  (Sorry, still very much a novice scripter)



#10 ywkls

ywkls

    Master

  • Members

Posted 03 February 2017 - 06:41 PM

How do I do that?  (Sorry, still very much a novice scripter)

How do you do what exactly? Spawn the sprite at the right location? It would help if I could see the particular script that you're using to change the combo. I can give you an example of how I'd do it, though. Unfortunately, the easiest way for me to explain would probably seem very complex to you. So, debugging your code might be simpler.



#11 idontknow8

idontknow8

    Senior

  • Members

Posted 03 February 2017 - 07:38 PM

I meant how do I add a line that calls a function to the script you had above?  Here's my script.  Being so novice, I tend to script in very long, convoluted ways so "debugging my script" might actually be easier said than done :P

item script Boomer_Ring_Item{
    void run(){
        int scriptName[]="Boomer_Ring";
        int scriptNum=Game->GetFFCScript(scriptName);
        if(CountFFCsRunning(scriptNum) < 2){
            RunFFCScript(scriptNum, NULL);
		}
	}
}

ffc script Boomer_Ring{
	void run(){
	int timer;
	int chance = Rand(100);
	int itemdrop;
	if(chance <= 19){
	itemdrop = 0;}
	if(chance >= 20 && chance <= 34){
	itemdrop = 2;}
	if(chance > 34){
	itemdrop = -1;}
	Link->Action = LA_ATTACKING;
    	lweapon boomer_ring = NextToLink(LW_SCRIPT10, 0);
	this->X = boomer_ring->X;
	this->Y = boomer_ring->Y;
	boomer_ring->Dir = Link->Dir;
	boomer_ring->Step = 235;
	boomer_ring->Damage = 3;
	boomer_ring->UseSprite(144);
	while(timer < 23){
	this->X = boomer_ring->X;
	this->Y = boomer_ring->Y;
	boomer_ring->DeadState = WDS_ALIVE;
	timer = timer + 1;
	Waitframe();
	if(Screen->ComboT[ComboAt(boomer_ring->X + 8, boomer_ring->Y + 8)] == 139){
	Screen->ComboD[ComboAt(boomer_ring->X+8, boomer_ring->Y+8)] = Screen->ComboD[ComboAt(boomer_ring->X+8, boomer_ring->Y+8)] + 1;
        item i=Screen->CreateItem(itemdrop);
	i->X = boomer_ring->X;
	i->Y = boomer_ring->Y;
	Game->PlaySound(41);
	}
	if(LinkCollision(boomer_ring) || boomer_ring->X <= 8 || boomer_ring->X >= 232 || boomer_ring->Y <= 8 || boomer_ring->Y >= 152){
		break;
		Waitframe();
		}
	}
	while(true){
	this->Vx = (Link->X - this->X)/15;
	this->Vy = (Link->Y - this->Y)/15;
	boomer_ring->DeadState = WDS_ALIVE;
	boomer_ring->Step = 0;
	boomer_ring->X = this->X;
	boomer_ring->Y = this->Y;
		if(Screen->ComboT[ComboAt(boomer_ring->X + 8, boomer_ring->Y + 8)] == 139){
		Screen->ComboD[ComboAt(boomer_ring->X+8, boomer_ring->Y+8)] = Screen->ComboD[ComboAt(boomer_ring->X+8, boomer_ring->Y+8)] + 1;
      		item i=Screen->CreateItem(itemdrop);
		i->X = boomer_ring->X;
		i->Y = boomer_ring->Y;
		Game->PlaySound(41);
		Waitframe();
		}
		if(LinkCollision(boomer_ring)){
		break;
		Waitframe();
		}
	Waitframe();
	}
	this->Vx = 0;
	this->Vy = 0;
	boomer_ring->UseSprite(105);
	boomer_ring->DeadState = 0;
	Waitframe();
	this->Script = 0;
	}
}

So essentially this is two scripts, one Item Script that initiates another, a FFC Script.  The latter creates a "Boomer_Ring" item that leaves Link in the direction he's facing & after a short distance, returns to him (like a boomerang) but does NOT pick up any items or stun enemies.  It DOES however damage enemies & "cut" bushes, even spawning items from them.  Right now it just doesn't spawn the leaves, just has the bush combo change combo instantly.

 

In particular, after lines 36 & 55, I want to have the leaves appear.


Edited by idontknow8, 03 February 2017 - 07:43 PM.


#12 ywkls

ywkls

    Master

  • Members

Posted 03 February 2017 - 10:03 PM

I meant how do I add a line that calls a function to the script you had above?  Here's my script.  Being so novice, I tend to script in very long, convoluted ways so "debugging my script" might actually be easier said than done :P

It's always easier to work from a known point (an existing script) than to make one up from scratch. One of the reasons I didn't want to post anything before is that the way I'd do it involves my lweapons header; since that lets me create them in the manner I wish quickly and easily; attaching ffc scripts if I so desire,

 

Debugged Code


 


There are countless other ways to do this, but that seems like the one you're after.

 

Edit: I should also note that this ffc script will run forever on whatever screen it is generated unless there are too many ffcs or it hits Link.


Edited by ywkls, 03 February 2017 - 10:04 PM.


#13 idontknow8

idontknow8

    Senior

  • Members

Posted 04 February 2017 - 02:02 AM

Hmm… the leaves appear but far away from the bush.  It also generates the same leave animation when slashed & appears a bit buggy too (not in line with the bush)



#14 ywkls

ywkls

    Master

  • Members

Posted 24 February 2017 - 08:24 PM

Hmm… the leaves appear but far away from the bush.  It also generates the same leave animation when slashed & appears a bit buggy too (not in line with the bush)

Sorry for not replying for a while, but I may have either forgotten about this thread; got distracted or hoped someone else could help out.

 

At this point, I'd say that your best bet is to set up a test quest (not necessarily whatever you're working on) where that someone can see how you've got it organized and figure out what it wrong, then either provide advice on how to fix it or send you back the corrected copy.

 

Otherwise, i'm not certain how to assist.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users