Jump to content

Photo

SFX Script Request


  • Please log in to reply
29 replies to this topic

#1 Cukeman

Cukeman

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

  • Banned
  • Location:Hyrule/USA

Posted 01 August 2016 - 03:19 AM

It doesn't make a lot of sense for Link to make a "hurt" sound when certain enemies are dealing 0 HPs of damage. If possible, I would like to request a script that plays a different SFX when Link is hit by an enemy whose Damage is set to 0. Thank you for your help.

 

I would also like to request an item script that plays SFX D0 if you press the button for that item when your MP is at D1 or less.



#2 idontknow8

idontknow8

    Senior

  • Members

Posted 01 August 2016 - 03:31 AM

item script low_magic_warning{
     void run(int low_magic, int warning_sound){
             if(Link->MP <= low_magic){
                  Game->PlaySound(warning_sound);
      }
   }
}

D1 is the "low magic," the max amount of magic you can have and the warning will still happen

D2 is the "warning_sound", the sound effect that will play

 

Nice idea!  I may add this to various magic item scripts myself



#3 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 01 August 2016 - 07:14 AM

It doesn't make a lot of sense for Link to make a "hurt" sound when certain enemies are dealing 0 HPs of damage. If possible, I would like to request a script that plays a different SFX when Link is hit by an enemy whose Damage is set to 0. Thank you for your help.
 
I would also like to request an item script that plays SFX D0 if you press the button for that item when your MP is at D1 or less.


HurtEffects.zh, in my signature.

#4 Cukeman

Cukeman

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

  • Banned
  • Location:Hyrule/USA

Posted 01 August 2016 - 08:41 PM

item script low_magic_warning{
     void run(int low_magic, int warning_sound){
             if(Link->MP <= low_magic){
                  Game->PlaySound(warning_sound);
      }
   }
}

D1 is the "low magic," the max amount of magic you can have and the warning will still happen

D2 is the "warning_sound", the sound effect that will play

 

Nice idea!  I may add this to various magic item scripts myself

 

 

   I put this script on the Lens of Truth (Magic Cost: 2) in the Action Script slot, set D0 to 1 (1MP) and d1 to 80 (SFX 80), and I started Link out with 1MP (Link does not have double magic), then when I went to use the Lens, no sound played.

   I filled Link's Magic Meter, and SFX 80 played when the meter ran out, but when I pressed the button after that, no sound played.


Edited by Cukeman, 01 August 2016 - 08:42 PM.


#5 Cukeman

Cukeman

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

  • Banned
  • Location:Hyrule/USA

Posted 01 August 2016 - 09:12 PM

HurtEffects.zh, in my signature.

 

Looking through 1.1 this seems to be the relevant section of code:

// Call in global script init, and global script OnContinue, global script active; after SetHurtSFX().
//                                          ! This ensures the correct values are stored at game init. 
void StoreLinkHP(){ 
      LinkStats[CURRENT_HP] = Link->HP;
      LinkStats[LAST_HP] = Link->HP;
}

// Call every frame *before* Waitdraw().
//           ! Keeps LinkStats[] sync'd. 
void UpdateLinkHP(){ 
     if ( Link->HP != LinkStats[CURRENT_HP] ){
           LinkStats[CURRENT_HP] = Link->HP;
     }
}

// Call every frame *after* Waitdraw(), before LinkHurtSound();
//   	            ! Determines if Link was damaged this frame. 
void LinkIsDamaged(){ 
     if ( LinkStats[CURRENT_HP] < LinkStats[LAST_HP] ){
          LinkStats[LINK_HURT] = 1;
          LinkStats[LAST_HP] = LinkStats[CURRENT_HP];
     }
}

The third piece (line 17) says "Determines if Link was damaged this frame" so I would just put a playSFX line before the last two braces (between 21 and 22)?


Edited by Cukeman, 01 August 2016 - 09:13 PM.


#6 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 01 August 2016 - 10:43 PM

Looking through 1.1 this seems to be the relevant section of code:

// Call in global script init, and global script OnContinue, global script active; after SetHurtSFX().
//                                          ! This ensures the correct values are stored at game init. 
void StoreLinkHP(){ 
      LinkStats[CURRENT_HP] = Link->HP;
      LinkStats[LAST_HP] = Link->HP;
}

// Call every frame *before* Waitdraw().
//           ! Keeps LinkStats[] sync'd. 
void UpdateLinkHP(){ 
     if ( Link->HP != LinkStats[CURRENT_HP] ){
           LinkStats[CURRENT_HP] = Link->HP;
     }
}

// Call every frame *after* Waitdraw(), before LinkHurtSound();
//   	            ! Determines if Link was damaged this frame. 
void LinkIsDamaged(){ 
     if ( LinkStats[CURRENT_HP] < LinkStats[LAST_HP] ){
          LinkStats[LINK_HURT] = 1;
          LinkStats[LAST_HP] = LinkStats[CURRENT_HP];
     }
}
The third piece (line 17) says "Determines if Link was damaged this frame" so I would just put a playSFX line before the last two braces (between 21 and 22)?

No... There's no need to modify the functions: The header includes routines to play the sounds. If Link isn't actually hurt, you can configure it not to play anything. Look at the set-up details and the in-code documentation. If you need more instructions, I'll update the docs.
...

To cause items such as the Lens to play sounds when you try to use them without MP, you need to do calls in your global active script. Items with an editor-based MP cost won't run their script if Link tries to use them with no MP.

#7 Cukeman

Cukeman

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

  • Banned
  • Location:Hyrule/USA

Posted 01 August 2016 - 10:48 PM

No... There's no need to modify the functions: The header includes routines to play the sounds. If Link isn't actually hurt, you can configure it not to play anything. Look at the set-up details and the in-code documentation. If you need more instructions, I'll update the docs.


I was trying to play a "bounce/rebound" SFX instead of an "ouch" SFX if the enemy did 0 damage, kind of like the bumpers in ALttP.

EDIT: Wait, was the idea to replace the silent sound with the bounce sound?
 

To cause items such as the Lens to play sounds when you try to use them without MP, you need to do calls in your global active script. Items with an editor-based MP cost won't run their script if Link tries to use them with no MP.


Ah, that's why it didn't work.


Edited by Cukeman, 01 August 2016 - 10:50 PM.


#8 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 02 August 2016 - 02:13 AM

I was trying to play a "bounce/rebound" SFX instead of an "ouch" SFX if the enemy did 0 damage, kind of like the bumpers in ALttP.
EDIT: Wait, was the idea to replace the silent sound with the bounce sound?
 

Ah, that's why it didn't work.


You can use the header as-is, and add:


const int SFX_LINK_ZERO_DAMAGE = 100;

void ZeroDamageLink(int sound){
    int q; npc n; eweapon e; bool hit;
    for ( q = Screen->NumNPCs(); q > 0; q-- ) {
        n = Screen->LoadNPC(q);
        if ( LinkCollision(n) ) hit = true;
    }
    for ( q = Screen->NumEWeapons(); q > 0; q-- ) {
        e = Screen->LoadEWeapon(q);
        if ( LinkCollision(e) ) hit = true;
    }
    if ( hit && !LinkStats[LINK_HURT] ) Game->PlaySound(sound);
}
Call it one instructon before Waitdraw() as ZeroDamageLink(SFX_LINK_ZERO_DAMAGE) .

#9 Cukeman

Cukeman

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

  • Banned
  • Location:Hyrule/USA

Posted 03 August 2016 - 03:12 AM

I'm curious, if there's no knockback, does link walk through the enemies or are they "solid"? i.e. If Link's not knocked back does he stay in place?


Edited by Cukeman, 03 August 2016 - 03:13 AM.


#10 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 03 August 2016 - 09:37 AM

I'm curious, if there's no knockback, does link walk through the enemies or are they "solid"? i.e. If Link's not knocked back does he stay in place?

You could try it and see. :)

Spoiler


Was my explanation of the sound functions sufficient?

...here, also, is a function for causing the lens to play an errors sound:


//Call in the main while loop of the global active script.
void LensNoMagic(int cost, int sound){
    bool used; cost = cost / Game->Generic[GEN_MAGICDRAINRATE];
    if  ( GetEquipmentA() == I_LENS && (Link->PressA || Link->InputA ) ) used = true;
    if ( !used ) { if ( GetEquipmentB() == I_LENS && (Link->PressB || Link->InputB ) ) used = true; }
    if ( used && Link->MP < cost ) Game->PlaySound(sound);
}


Edited by ZoriaRPG, 03 August 2016 - 10:02 AM.


#11 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 03 August 2016 - 09:55 AM

You can make similar functions, by duplicating this one, changing the identifier from 'LensNoMagic' to something else, and changing the item IDs from I_LENS to something else.

Hmm... better still:


//Call in the main while loop of the global active script.
// Generic version, that allows you to specify the item, and the counter that it uses.
void NotEnoughError(int item_ID, int cost, int counter,  int sound){
    bool used; 
    if ( counter == CR_MAGIC ) cost = cost / Game->Generic[GEN_MAGICDRAINRATE];
    if  ( GetEquipmentA() == item_ID && (Link->PressA || Link->InputA ) ) used = true;
    if ( !used ) { if ( GetEquipmentB() == item_ID && (Link->PressB || Link->InputB ) ) used = true; }
    if ( used && Game->Counter[counter] < cost ) Game->PlaySound(sound);
}


Edited by ZoriaRPG, 03 August 2016 - 10:00 AM.


#12 Cukeman

Cukeman

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

  • Banned
  • Location:Hyrule/USA

Posted 03 August 2016 - 04:17 PM

Spoiler


At first I wondered "Why cancel knockback if you can pass through them?" (since you can turn off hitboxes), but then I realized that this is a way to hit enemies that act as if they have no hitbox, correct? That sounds useful for the enemy I'm currently working on.
 

Was my explanation of the sound functions sufficient?

 
That script is up next on my to do list. Plus I've been debating whether 0 damage enemies should make a rebound/bounce sound or no sound at all. I've also been debating whether 0HP enemies should knock Link back or not.

 

As for the out of magic SFX, let's see if I understand this:

int cost = 1
int sound = 80

LensNoMagic( );

//Call in the main while loop of the global active script.
void LensNoMagic(int cost, int sound){
    bool used; cost = cost / Game->Generic[GEN_MAGICDRAINRATE];
    if  ( GetEquipmentA() == I_LENS && (Link->PressA || Link->InputA ) ) used = true;
    if ( !used ) { if ( GetEquipmentB() == I_LENS && (Link->PressB || Link->InputB ) ) used = true; }
    if ( used && Link->MP < cost ) Game->PlaySound(sound);
}

And for a second item (not sure about this)

int DFcost = 31
int sound = 80

DinsFireNoMagic( );

//Call in the main while loop of the global active script.
void DinsFireNoMagic(int DFcost, int sound){
    bool used; DFcost = DFcost / Game->Generic[GEN_MAGICDRAINRATE];
    if  ( GetEquipmentA() == I_DINSFIRE && (Link->PressA || Link->InputA ) ) used = true;
    if ( !used ) { if ( GetEquipmentB() == I_DINSFIRE && (Link->PressB || Link->InputB ) ) used = true; }
    if ( used && Link->MP < DFcost ) Game->PlaySound(sound);
}

I know you posted this:

 

 

You can make similar functions, by duplicating this one, changing the identifier from 'LensNoMagic' to something else, and changing the item IDs from I_LENS to something else.

Hmm... better still:
 

//Call in the main while loop of the global active script.
// Generic version, that allows you to specify the item, and the counter that it uses.
void NotEnoughError(int item_ID, int cost, int counter, int sound){
bool used;
if ( counter == CR_MAGIC ) cost = cost / Game->Generic[GEN_MAGICDRAINRATE];
if ( GetEquipmentA() == item_ID && (Link->PressA || Link->InputA ) ) used = true;
if ( !used ) { if ( GetEquipmentB() == item_ID && (Link->PressB || Link->InputB ) ) used = true; }
if ( used && Game->Counter[counter] < cost ) Game->PlaySound(sound);
}

 

 

but I don't understand how to set up additional items and costs



#13 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 04 August 2016 - 01:01 AM

At first I wondered "Why cancel knockback if you can pass through them?" (since you can turn off hitboxes), but then I realized that this is a way to hit enemies that act as if they have no hitbox, correct? That sounds useful for the enemy I'm currently working on.
 
 
That script is up next on my to do list. Plus I've been debating whether 0 damage enemies should make a rebound/bounce sound or no sound at all. I've also been debating whether 0HP enemies should knock Link back or not.


That was sort of the point of the header. I wanted to stop enemies that have 0-damage from causing Link to be knocked back, or make sounds.
 

As for the out of magic SFX, let's see if I understand this:

int cost = 1
int sound = 80

LensNoMagic( );

//Call in the main while loop of the global active script.
void LensNoMagic(int cost, int sound){
    bool used; cost = cost / Game->Generic[GEN_MAGICDRAINRATE];
    if  ( GetEquipmentA() == I_LENS && (Link->PressA || Link->InputA ) ) used = true;
    if ( !used ) { if ( GetEquipmentB() == I_LENS && (Link->PressB || Link->InputB ) ) used = true; }
    if ( used && Link->MP < cost ) Game->PlaySound(sound);
}
And for a second item (not sure about this)
int DFcost = 31
int sound = 80

DinsFireNoMagic( );

//Call in the main while loop of the global active script.
void DinsFireNoMagic(int DFcost, int sound){
    bool used; DFcost = DFcost / Game->Generic[GEN_MAGICDRAINRATE];
    if  ( GetEquipmentA() == I_DINSFIRE && (Link->PressA || Link->InputA ) ) used = true;
    if ( !used ) { if ( GetEquipmentB() == I_DINSFIRE && (Link->PressB || Link->InputB ) ) used = true; }
    if ( used && Link->MP < DFcost ) Game->PlaySound(sound);
}
I know you posted this:
 

 
 
but I don't understand how to set up additional items and costs


No, you don't declare vars like that. You pass the values that you want into the functions when you call them:
 
LensNoMagic(2, 16);
//Plays sound 16 if Link doesn't have 2MP when he uses the lens.

DinsFireNoMagic(64, 9);
//Plays sound 9 if Link doesn't have 64 MP when he uses Din's Fire

NotEnoughError(I_ARROW, 1, CR_ARROWS, 15);
//Plays sound 15 if Link trues to shoot an arrow and has none.
Set the 'cost' param to equal whatever the cost of using the item is, in the item editor.

'NotEnoughError' is generic, and you can call it many times, for different items:
 
const int SFX_ERROR_ITEM = 15;

global script foo{
    void run() {
        while(true){
            Waitdraw();
            NotEnoughError(I_ARROW, 1, CR_ARROWS, SFX_ERROR_ITEM);
            NotEnoughError(I_LENS, 1, CR_MAGIC, SFX_ERROR_ITEM);
            NotEnoughError(I_DINSFIRE, 64, CR_MAGIC, SFX_ERROR_ITEM);
            NotEnoughError(I_WAND, 2, CR_MAGIC, SFX_ERROR_ITEM);
            NotEnoughError(I_CUSTOM, 10, CR_SCRIPT2, 67); //Plays a different sound.
            Waitframe();
        }
    }
}


Edited by ZoriaRPG, 04 August 2016 - 01:08 AM.


#14 Cukeman

Cukeman

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

  • Banned
  • Location:Hyrule/USA

Posted 04 August 2016 - 01:09 PM

Okay, so I set up this script:

const int SFX_ERROR_ITEM = 80;//Used for NotEnoughError script


//globalsection
            Waitdraw();
            NotEnoughError(I_LENS, 2, CR_MAGIC, SFX_ERROR_ITEM);
//endglobal



void NotEnoughError(int item_ID, int cost, int counter,  int sound){
    bool used; 
    if ( counter == CR_MAGIC ) cost = cost / Game->Generic[GEN_MAGICDRAINRATE];
    if  ( GetEquipmentA() == item_ID && (Link->PressA || Link->InputA ) ) used = true;
    if ( !used ) { if ( GetEquipmentB() == item_ID && (Link->PressB || Link->InputB ) ) used = true; }
    if ( used && Game->Counter[counter] < cost ) Game->PlaySound(sound);
}

The Lens Magic Cost is 2 in the Item Editor.

When Link has 1 MP the SFX doesn't play, it only plays when he has 0MP.

I did try this: "NotEnoughError(I_LENS, 1, CR_MAGIC, SFX_ERROR_ITEM);", but it didn't work, so I put it back to 2.

Also, the SFX plays continuously as long as I hold the button down, which sounds... unpleasant (it's hard to press the button quickly enough to only hear the sound once).

 

Also, when I get the 1/2 Magic upgrade, "THIS#" will change, won't it?

NotEnoughError(I_(ITEM), "THIS#", CR_MAGIC, SFX_ERROR_ITEM);


Edited by Cukeman, 04 August 2016 - 05:16 PM.


#15 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 05 August 2016 - 10:46 AM

Okay, so I set up this script:

const int SFX_ERROR_ITEM = 80;//Used for NotEnoughError script


//globalsection
            Waitdraw();
            NotEnoughError(I_LENS, 2, CR_MAGIC, SFX_ERROR_ITEM);
//endglobal



void NotEnoughError(int item_ID, int cost, int counter,  int sound){
    bool used; 
    if ( counter == CR_MAGIC ) cost = cost / Game->Generic[GEN_MAGICDRAINRATE];
    if  ( GetEquipmentA() == item_ID && (Link->PressA || Link->InputA ) ) used = true;
    if ( !used ) { if ( GetEquipmentB() == item_ID && (Link->PressB || Link->InputB ) ) used = true; }
    if ( used && Game->Counter[counter] < cost ) Game->PlaySound(sound);
}
The Lens Magic Cost is 2 in the Item Editor.
When Link has 1 MP the SFX doesn't play, it only plays when he has 0MP.
I did try this: "NotEnoughError(I_LENS, 1, CR_MAGIC, SFX_ERROR_ITEM);", but it didn't work, so I put it back to 2.
Also, the SFX plays continuously as long as I hold the button down, which sounds... unpleasant (it's hard to press the button quickly enough to only hear the sound once).
 
Also, when I get the 1/2 Magic upgrade, "THIS#" will change, won't it?
NotEnoughError(I_(ITEM), "THIS#", CR_MAGIC, SFX_ERROR_ITEM);


The cos will scale with half-magic. That's why you see cost = cost * Game->Generic[GEN_MAGICDRAINRATE].

Fixing the sound repeating is something else: Remove the Link->InputA and Link->InputB inclusions, and rely entirely on Link->Press, and it should be good.


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users