Two requests! Both are SFX-based and should be easy to do, but ZScript apparently doesn't like me - it keeps giving me nasty errors. T'any rate:
1) I want a SFX to play in a room and then loop itself instead of stopping after it plays once. I thought of placing it in a loop, but then it would restart at every frame: I want it to play, finish, then play again. Is this possible?
2) I got the 'NPC' script by Joe123 that I found somewhere around PureZC, and it works wonderfully. I, however, would like to add an argument related to SFX, so that when the message plays, the selected SFX also plays. Is this possible, or do I have to hard-code several versions of the script with different sound effects?...
Thanks in advance.
Sound Effect Madness
Started by
Dream Illusionist
, Apr 04 2009 10:06 AM
5 replies to this topic
#1
Posted 04 April 2009 - 10:06 AM
#2
Posted 04 April 2009 - 11:40 AM
1) I want a SFX to play in a room and then loop itself instead of stopping after it plays once. I thought of placing it in a loop, but then it would restart at every frame: I want it to play, finish, then play again. Is this possible?
Well, sort of. There's no way for a script to determine when a sound finishes playing; you just have to tell it how long to wait before playing it again.
This should work, but you'll have to figure out the timing for yourself:
CODE
import "std.zh"
ffc script LoopSound
{
void run(int sound, int length)
{
while(true)
{
Game->PlaySound(sound);
Waitframes(length);
}
}
}
ffc script LoopSound
{
void run(int sound, int length)
{
while(true)
{
Game->PlaySound(sound);
Waitframes(length);
}
}
}
QUOTE
2) I got the 'NPC' script by Joe123 that I found somewhere around PureZC, and it works wonderfully. I, however, would like to add an argument related to SFX, so that when the message plays, the selected SFX also plays. Is this possible, or do I have to hard-code several versions of the script with different sound effects?...
Shouldn't be hard, but I don't know exactly which script you're referring to.I expect you'd just need to add int sound to the arguments and call Game->PlaySound(sound) at the same time the message is displayed.
#3
Posted 04 April 2009 - 01:48 PM
For #2 you can put in a special backslash code in beginning of the string to play a sound. It doesn't even require adding anything to the script.
#4
Posted 04 April 2009 - 04:20 PM
QUOTE(Saffith)
Well, sort of. There's no way for a script to determine when a sound finishes playing; you just have to tell it how long to wait before playing it again.
This should work, but you'll have to figure out the timing for yourself:
-insert chunk of code here-
This should work, but you'll have to figure out the timing for yourself:
-insert chunk of code here-
Yeah, I had something like that as well, was just wondering if there was a way to know if it had already started playing... *shrugs*. Thanks anyway. =)
QUOTE(Saffith)
Shouldn't be hard, but I don't know exactly which script you're referring to.
I expect you'd just need to add int sound to the arguments and call Game->PlaySound(sound) at the same time the message is displayed.
I expect you'd just need to add int sound to the arguments and call Game->PlaySound(sound) at the same time the message is displayed.
But that was what I was doing and it wasn't worki--
--nevermind. Forgot a bloody semicolon. >>; Thanks.
QUOTE(Beefster)
For #2 you can put in a special backslash code in beginning of the string to play a sound. It doesn't even require adding anything to the script.
Yes, I was aware of that, thanks. Problem was with sentences that are said by several NPCs, and the NPCs are different (thus the sound effect would differ)
#5
Posted 04 April 2009 - 04:31 PM
Problem was with sentences that are said by several NPCs, and the NPCs are different (thus the sound effect would differ)
Save yourself the extra work, and just make multiple strings with the same text and different sounds. Yeah, it wastes strings, but wasteing strings is better than wasteing scripts.
If, however, you have an NPC that says lots of different things, and you don't want to put the sound effect code on EVERY string they say, then you'll need to hardcode a separate NPC script for that one character.
Edited by Cjc7988, 04 April 2009 - 04:32 PM.
#6
Posted 04 April 2009 - 05:19 PM
CODE
//NPCs, by Pkmnfrk
ffc script NPC{
void run(int m, int sfx, int changedirection, int distance){
int dx; int dy;
int ax; int ay;
int orig = this->Data;
if(distance == 0) distance = 40;
while(true){
dx = this->X-Link->X; ax = Abs(dx);
dy = this->Y-Link->Y; ay = Abs(dy);
if(changedirection != 0){
if(ax < distance && ay < distance){
if(ax <= ay){
if(dy >= 0) this->Data = orig;
else this->Data = orig+1;
}else{
if(dx >= 0) this->Data = orig+2;
else this->Data = orig+3;
}
}else this->Data = orig+(changedirection-1);
}
if(Link->InputA && ax < 24 && ay < 24 && Link->Z == 0){
Link->InputA = false;
if(sfx!=0) Game->PlaySound(sfx);
Screen->Message(m);
do Waitframe();
while(Link->InputA)
}
Waitframe();
}
}
}
ffc script NPC{
void run(int m, int sfx, int changedirection, int distance){
int dx; int dy;
int ax; int ay;
int orig = this->Data;
if(distance == 0) distance = 40;
while(true){
dx = this->X-Link->X; ax = Abs(dx);
dy = this->Y-Link->Y; ay = Abs(dy);
if(changedirection != 0){
if(ax < distance && ay < distance){
if(ax <= ay){
if(dy >= 0) this->Data = orig;
else this->Data = orig+1;
}else{
if(dx >= 0) this->Data = orig+2;
else this->Data = orig+3;
}
}else this->Data = orig+(changedirection-1);
}
if(Link->InputA && ax < 24 && ay < 24 && Link->Z == 0){
Link->InputA = false;
if(sfx!=0) Game->PlaySound(sfx);
Screen->Message(m);
do Waitframe();
while(Link->InputA)
}
Waitframe();
}
}
}
It's not my script, it's pkmnfrks.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users