Jump to content

Photo

Learning to combine scripts


  • Please log in to reply
69 replies to this topic

#31 Cukeman

Cukeman

    "Tra la la, look for Sahasrahla. ... ... ..."

  • Banned
  • Location:Hyrule/USA

Posted 22 April 2016 - 02:02 AM

Okay, so the next thing I want to do is modify this script:

//D0: Item ID to give
//D1: Combo to check for
//D2: SFX upon receiving the item (leave at 0 to turn off)
//D3: Give the Item if Link's in the air? (leave at 0 for yes, 1 or higher otherwise)
//D4: SFX upon losing the item (leave at 0 to turn off)
 
ffc script ComboTileModifier
{
	
	void run(int itemid, int comboid, int SFXON, int inair, int SFXOFF)
	{
		
		while (true)
		{
			
			if (ComboD[ComboAt(Link->X + 8, Link->Y + 8)] == comboid && (inair < 1 || Link->Z <= 0)) //If on the combo
			{
				if (Link->Item[itemid] == false) //Check to see if he doesn't have the item currently. Prevents lag from giving an item every second.
				{
					if (SFXON > 0) Game->PlaySound(SFXON); //Play sound if applicable.
				        Link->Item[itemid] = true; //Give him the item.
				}
                                
                                Link->InputA = false;
                                Link->InputB = false;
			}
			
			else //If not on the combo
			{
				if (Link->Item[itemid] == true) //Check to see if he has the item currently. Prevents lag from losing an item every second.
				{
					if (SFXOFF > 0) Game->PlaySound(SFXOFF); //Play sound if applicable
					Link->Item[itemid] = false; //Lose the item.
				}
			}
			Waitframe();
		}
	}
}

I like how it gives and takes the item, but if Link has Shield 1, I want to change the item to "B" instead, Shield 2=Item "C", and Shield 3=Item "D".

 

Which would be something like this I guess:

if (Link->Item[37] == true)//Shield 3
{
CHANGE ITEM IN D0 to Item[157];
}

else
if (Link->Item[8] == true)//Shield 2
{
CHANGE ITEM IN D0 to Item[156];
}

else
if (Link->Item[93] == true)//Shield 1
{
CHANGE ITEM IN D0 to Item[155];
}


else
Link->Item[itemid] = true; //Give him the item.

I know that's not valid script, but if you could help me clean that up and determine where exactly it goes in the script that would be awesome. Sorry for my lack of knowledge D:


Edited by Cukeman, 22 April 2016 - 02:50 AM.


#32 Lejes

Lejes

    Seeker of Runes

  • Members
  • Location:Flying High Above Monsteropolis

Posted 22 April 2016 - 03:27 AM

//D0: Item ID to give
//D1: Combo to check for
//D2: SFX upon receiving the item (leave at 0 to turn off)
//D3: Give the Item if Link's in the air? (leave at 0 for yes, 1 or higher otherwise)
//D4: SFX upon losing the item (leave at 0 to turn off)
 
ffc script ComboTileModifier
{
	
	void run(int itemid, int comboid, int SFXON, int inair, int SFXOFF)
	{
		if (Link->Item[37] == true)//Shield 3
		{
			itemid = 157;
		}
		 
		else if (Link->Item[8] == true)//Shield 2
		{
			itemid = 156;
		}
		 
		else if (Link->Item[93] == true)//Shield 1
		{
			itemid = 155;
		}
		
		while (true)
		{
			
			if (ComboD[ComboAt(Link->X + 8, Link->Y + 8)] == comboid && (inair < 1 || Link->Z <= 0)) //If on the combo
			{
				if (Link->Item[itemid] == false) //Check to see if he doesn't have the item currently. Prevents lag from giving an item every second.
				{
					if (SFXON > 0) Game->PlaySound(SFXON); //Play sound if applicable.
				        Link->Item[itemid] = true; //Give him the item.
				}
                                
                                Link->InputA = false;
                                Link->InputB = false;
			}
			
			else //If not on the combo
			{
				if (Link->Item[itemid] == true) //Check to see if he has the item currently. Prevents lag from losing an item every second.
				{
					if (SFXOFF > 0) Game->PlaySound(SFXOFF); //Play sound if applicable
					Link->Item[itemid] = false; //Lose the item.
				}
			}
			Waitframe();
		}
	}
}
kerpow

The shield IDs are all hard coded now, but this script does have three more D# arguments free, if you want to tie the shield IDs to those.
  • Cukeman likes this

#33 Cukeman

Cukeman

    "Tra la la, look for Sahasrahla. ... ... ..."

  • Banned
  • Location:Hyrule/USA

Posted 22 April 2016 - 04:17 AM

variable comboD is undeclared

first line after "while (true)"

 

No need to set more arguments, I don't mind editing the numbers in the code.



#34 Avaro

Avaro

    o_o

  • Members
  • Real Name:Robin
  • Location:Germany

Posted 22 April 2016 - 04:35 AM

It should be "Screen->ComboD".


  • Cukeman likes this

#35 Cukeman

Cukeman

    "Tra la la, look for Sahasrahla. ... ... ..."

  • Banned
  • Location:Hyrule/USA

Posted 22 April 2016 - 04:50 AM

Wonderful! Thanks you two! Why did the previous version compile and work before I added the "Screen->" part though?


Edited by Cukeman, 22 April 2016 - 04:57 AM.


#36 Lejes

Lejes

    Seeker of Runes

  • Members
  • Location:Flying High Above Monsteropolis

Posted 22 April 2016 - 06:01 AM

It didn't. You must have reverted the fix or copied the wrong thing at some point.

#37 Cukeman

Cukeman

    "Tra la la, look for Sahasrahla. ... ... ..."

  • Banned
  • Location:Hyrule/USA

Posted 22 April 2016 - 06:11 AM

D'oh! I copy pasted it from the old thread instead of my modified script file.  :doh:



#38 Cukeman

Cukeman

    "Tra la la, look for Sahasrahla. ... ... ..."

  • Banned
  • Location:Hyrule/USA

Posted 30 April 2016 - 02:40 PM

 

There I fixed it (maybe).

ffc script CreateEndlessHPEnemy{
void run(int enemyID, int enemyX, int enemyY, int trigger_secrets){
npc enemy = CreateNPCAt(enemyID, enemyX, enemyY);
        enemy->HP = 32767;
        while (true)
        {
            if (enemy->HP < 32767 && trigger_secrets != 0){
                Screen->TriggerSecrets();
                Game->PlaySound(SFX_SECRET);
                trigger_secrets = 0;
            }
            enemy->HP = 32767;
            Waitframe();
        }
}
}

 

So, the reason this enemy isn't getting knocked back is because it's set to "Other" type in the Enemy Editor?

I don't want it to be knocked back, I'm just trying to make sure it won't happen.



#39 Lejes

Lejes

    Seeker of Runes

  • Members
  • Location:Flying High Above Monsteropolis

Posted 30 April 2016 - 03:11 PM

Yes. Other type enemies don't get knocked back.
  • Cukeman likes this

#40 Cukeman

Cukeman

    "Tra la la, look for Sahasrahla. ... ... ..."

  • Banned
  • Location:Hyrule/USA

Posted 04 May 2016 - 10:01 AM

So, I'm trying to edit this script:

ffc script StepMessage{
    void run(int m){
        while(CenterLinkX()<this->X || CenterLinkX()>this->X+this->TileWidth*16 || CenterLinkY()<this->Y || CenterLinkY()>this->Y+this->TileHeight*16) Waitframe();
        Screen->Message(m);
    }
}

Instead of Link triggering a message when he steps on the FFC, I want the enemy to change its ID when it steps on the FFC.

 

My attempt:

ffc script ChangeEnemyFFC{
    void run(int enemyID){
        while(CenterenemyX()<this->X || CenterenemyX()>this->X+this->TileWidth*16 || CenterenemyY()<this->Y || CenterenemyY()>this->Y+this->TileHeight*16) Waitframe();
        enemy->enemyID(enemyID);
    }
}

- Will it work?

- Will it change only the enemy/enemies stepping on the combo (and not the other onscreen enemies)?

- Or do I have to remove the enemy and create a new one? ( Remove(enemy) and CreateNPC )

 

EDIT: Also, I only want this to affect enemies that walk onto this combo (not Zoras that may appear at this combo)

 

EDIT 2: Will it work every time an enemy steps on it (desired), or just once?


Edited by Cukeman, 04 May 2016 - 10:20 AM.


#41 grayswandir

grayswandir

    semi-genius

  • Members

Posted 04 May 2016 - 02:21 PM

Enemy ID is one of the things you can't change. You'd have to make a new enemy, and then copy over all the values from the original, and then delete it.

 

Of course, depending on what you're doing, you might not have to change the enemy id. It might be easier to just have the same id, but change the graphics to something different (if they're both walkers, for instance).

 

Also, that script isn't setup at all for dealing with enemies. You have the right idea, kinda, by replacing Link with Enemy. But the main difference between Link and enemies is that there's only 1 Link, but there can be many enemies, so you have to test for each one. The original script also only executes once. Do you want the tile to be a one-time thing, or something permanent?

 

Here's the basic code structure you'd need:

// This, combined with the waitframe at the end, makes the code execute once per frame.
while (true) {
  // This loop will go through once for each enemy on the screen.
  for (int i = 1; i <= Screen->NumNPCs(); ++i) {
     npc enemy = Screen->LoadNPC(i);
     // Instead of Waitframe here, you'll want continue. That'll make it move to the next "i" - which is the next enemy on the screen.
     if (CenterX(enemy) < this->X || CenterX(enemy) > this->X + this->TileWidth * 16 || CenterY(enemy) < this->Y || CenterY(enemy) > this->Y + this->TileHeight * 16) continue;
    // Now we test to make sure that the enemy has the ID we want.
    if (enemyID != enemy->ID) continue;
     // Here you do whatever you wanted to do to that enemy.
    // ...
  }
  Waitframe();
}

  • Avaro likes this

#42 Cukeman

Cukeman

    "Tra la la, look for Sahasrahla. ... ... ..."

  • Banned
  • Location:Hyrule/USA

Posted 04 May 2016 - 05:24 PM

I... don't believe I'd need to copy over any of the enemy's values. I'd have a walking enemy, who would be deleted when he steps on the ffc, and then I'd create a Zora enemy who would, by default, appear in any of the water combos.

 

I would want the ffc to always change the enemy, not just once.



#43 grayswandir

grayswandir

    semi-genius

  • Members

Posted 04 May 2016 - 05:30 PM

So it's less "changing" the enemy and more killing it and making a completely different one. That sounds pretty easy, except I have no idea if you can spawn Zoras through scripting ... I've never tried it before.



#44 Cukeman

Cukeman

    "Tra la la, look for Sahasrahla. ... ... ..."

  • Banned
  • Location:Hyrule/USA

Posted 27 May 2016 - 01:33 AM

So it's less "changing" the enemy and more killing it and making a completely different one. That sounds pretty easy, except I have no idea if you can spawn Zoras through scripting ... I've never tried it before.

 

Well, I know you can spawn them like normal enemies, and even use enemy placement flags, so I imagine it's possible.


Edited by Cukeman, 27 May 2016 - 02:04 AM.


#45 Lejes

Lejes

    Seeker of Runes

  • Members
  • Location:Flying High Above Monsteropolis

Posted 27 May 2016 - 02:25 AM

You can spawn Zora's via script, no problem. It doesn't even matter where you place them, they're hardcoded to only appear in water. If you spawn one in a screen without water, it'll never show its face.
  • Cukeman likes this


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users