Jump to content

Photo

Sword Script not working...


  • Please log in to reply
12 replies to this topic

#1 Blue Link 2007

Blue Link 2007

    Doyen(ne)

  • Members

Posted 19 November 2007 - 02:27 PM

Awhile back, if anybody could remember, I asked for a script that would randomly use different sound effects with use of the sword. I used the following code, but it doesn't work. Can anybody help me?

CODE
import "std.zh"
item script SFX
{
    void run()
    {
        int RandomNum = Floor(Rand(1) * 4);
        if (RandomNum == 0.0)
        {
            Game->PlaySound(30);
        }
        else if (RandomNum == 1.0)
        {
            Game->PlaySound(60);
        }
        else if (RandomNum == 2.0)
        {
            Game->PlaySound(61);
        }
        else if (RandomNum == 3.0)
        {
            Game->PlaySound(62);
        }
    }
}


#2 Joe123

Joe123

    Retired

  • Members

Posted 19 November 2007 - 02:44 PM

CODE
import "std.zh"
item script SFX{
    void run(){
        int x = Rand(5);
        if(x > 4){x = 4;}
        if(x <= 4 && x > 3){Game->PlaySound(70);}
        if(x <= 3 && x > 2){Game->PlaySound(71);}
        if(x <= 2 && x > 1){Game->PlaySound(72);}
        if(x <= 1 && x > 0){Game->PlaySound(73);}
    }
}


You'll probably want to set the sword's normal SFX to 0.
The four SFX slots that it uses are 70-73. Change them by changing those four numbers in the script.

It should work fine. However I haven't tested it.
I think it'll play the SFX in 70 more often than the other three (should be roughly 2/5 times that one, and 1/5 the others). If you want it to be strictly regular, I'll do that.

Edited by Joe123, 19 November 2007 - 02:45 PM.


#3 Blue Link 2007

Blue Link 2007

    Doyen(ne)

  • Members

Posted 19 November 2007 - 10:45 PM

It is working, but now I have a new problem. When I use the sword, it always uses the original sound effect, and sometimes a random one. How do I fix that?

#4 Gleeok

Gleeok

    It's dangerous to dough alone, bake this.

  • Members
  • Real Name:Pillsbury
  • Location:Magical Land of Dough

Posted 20 November 2007 - 12:59 AM

QUOTE(Joe123 @ Nov 19 2007, 01:44 PM) View Post

CODE
import "std.zh"
item script SFX{
    void run(){
        int x = Rand(5);
        if(x > 4){x = 4;}
        if(x <= 4 && x > 3){Game->PlaySound(70);}
        if(x <= 3 && x > 2){Game->PlaySound(71);}
        if(x <= 2 && x > 1){Game->PlaySound(72);}
        if(x <= 1 && x > 0){Game->PlaySound(73);}
    }
}




Doesn't Rand always return a whole number?
Why the cantrip?

CODE
import "std.zh"
item script SFX{
    void run(){
        int x = Rand(4);
        if(x = 3 ){Game->PlaySound(70);}
        if(x = 2 ){Game->PlaySound(71);}
        if(x = 1 ){Game->PlaySound(72);}
        if(x = 0){Game->PlaySound(73);}
    }
}


..I don't see why this version wouldn't be completely randomized.


#5 Fox

Fox

    Will the Hero rise again?

  • Members
  • Real Name:Scott
  • Location:Southern California

Posted 20 November 2007 - 01:57 AM

QUOTE(Gleeok @ Nov 19 2007, 09:59 PM) View Post

Doesn't Rand always return a whole number?
Why the cantrip?

CODE
import "std.zh"
item script SFX{
    void run(){
        int x = Rand(4);
        if(x = 3 ){Game->PlaySound(70);}
        if(x = 2 ){Game->PlaySound(71);}
        if(x = 1 ){Game->PlaySound(72);}
        if(x = 0){Game->PlaySound(73);}
    }
}


..I don't see why this version wouldn't be completely randomized.


I was thinking the same thing. Doesn't rand(n) give you a random integer from 0 to n-1 inclusive?
And it looks like you're playing all sounds, Gleeok. You need to check if x == n rather than x = n. I haven't used ZScript, but based on its structure, it looks an awful lot like C, so I'm assuming I'm right on this one.

#6 Joe123

Joe123

    Retired

  • Members

Posted 20 November 2007 - 03:04 AM

I thought it was a decimal. Hmm.

What you need to do Blue Link is
QUOTE(Joe123 @ Nov 19 2007, 07:44 PM) View Post
set the sword's normal SFX to 0.

By that I mean the one in the item editor.

And that's just a typo that Gleeok's got Fox, ZQuest can't parse the file if you try to set integers within the requirements for an if clause, you have to put == or it just won't compile.

CODE
import "std.zh"
item script SFX{
    void run(){
        int x = Rand(4);
        if(x == 3 ){Game->PlaySound(70);}
        if(x == 2 ){Game->PlaySound(71);}
        if(x == 1 ){Game->PlaySound(72);}
        if(x == 0){Game->PlaySound(73);}
    }
}


That one should work best then.

Edited by Joe123, 20 November 2007 - 03:05 AM.


#7 Fox

Fox

    Will the Hero rise again?

  • Members
  • Real Name:Scott
  • Location:Southern California

Posted 20 November 2007 - 04:16 AM

QUOTE(Joe123 @ Nov 20 2007, 12:04 AM) View Post

I thought it was a decimal. Hmm.

What you need to do Blue Link is

By that I mean the one in the item editor.

And that's just a typo that Gleeok's got Fox, ZQuest can't parse the file if you try to set integers within the requirements for an if clause, you have to put == or it just won't compile.

CODE
import "std.zh"
item script SFX{
    void run(){
        int x = Rand(4);
        if(x == 3 ){Game->PlaySound(70);}
        if(x == 2 ){Game->PlaySound(71);}
        if(x == 1 ){Game->PlaySound(72);}
        if(x == 0){Game->PlaySound(73);}
    }
}


That one should work best then.


I figured it was just a typo. Just messing with him. =P
Didn't know that integer arguments in if statements return errors though. That's kind of odd. Don't the conditions inside the if statements reduce to boolean integers anyway?

Also, rand definitely returns integers. I just checked the documentation to be sure. It's the very first defined function:
http://armageddongam...ead.php?t=93851

#8 Blue Link 2007

Blue Link 2007

    Doyen(ne)

  • Members

Posted 20 November 2007 - 03:40 PM

I tried setting the sfx to zero, but then it sometimes plays that. What I think it is doing is randomly choosing between 70-73, and playing the swords normal sound effect at the same time. Is there any way you can get it to shut out the normal sound effect?

#9 Joe123

Joe123

    Retired

  • Members

Posted 20 November 2007 - 04:10 PM

yes...
I've explained it twice...

Go to the item editor.
Select the Sword for which you have this script attached.
There's a box that says 'SFX' or something near to it, it's either in the first tab or the fourth tab.
Put '0' in that box

#10 Blue Link 2007

Blue Link 2007

    Doyen(ne)

  • Members

Posted 20 November 2007 - 04:32 PM

I did put a zero in the box. When I did that, it started randomly not playing any sound when I used the sword.

#11 Joe123

Joe123

    Retired

  • Members

Posted 20 November 2007 - 04:38 PM

Hrm. Interesting.
There is a flaw in the script then.

Which apparently there shouldn't be.
With the random number function, it generates a random number either 0,1,2 or 3, then checks which one it is and plays a different sound effect for each one.

I can't think why that wouldn't work without testing it.
Which I may do, because it's an interesting idea to implement, but it won't be for a bit.

#12 Gleeok

Gleeok

    It's dangerous to dough alone, bake this.

  • Members
  • Real Name:Pillsbury
  • Location:Magical Land of Dough

Posted 21 November 2007 - 12:10 AM

If the sfx action tab plays sfx when you set it to 0, then it's a bug. Remove the script from the sword, you should hear no sfx.

#13 Joe123

Joe123

    Retired

  • Members

Posted 21 November 2007 - 10:27 AM

OK, I've just tested this and it works fine. I'm not getting any problems with it not playing a SFX or anything at all, so I don't really know what your problem is.
You do have the sound effects set to the correct slots in the script, right?

EDIT: Oh, come to think of it, I do have the sound effect from the sword still playing, but I don't see why that should create a problem. I have the sword playing a slashing SFX, and the script making Link shout, like in Minish Cap.

Edited by Joe123, 21 November 2007 - 10:29 AM.



1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users