Solved Sound Effect Buzz & Loop After Reaching Full MP

Question that is answered or resolved.

maxman

Well-known member
I wanna play a sound in ondrawscript after the player's MP becomes full. However, after I add playsample under the MP's max limit, there's this buzzing and strange sound that plays unless you consume MP. It sounds kinda distorting after the moment you fill full MP.

This is from the player's draw script.
C:
void main(){
    playerMP();
}
void playerMP()
{
    if(openborvariant("in_level")==1){
        int P1 = getplayerproperty(0, "entity");
        int P2 = getplayerproperty(1, "entity");
        int P3 = getplayerproperty(2, "entity");
        int MP;
        int maxMP;
        int HP;
        void fullMP = loadsample("data/sounds/fullmp.wav");
        void aniID;
        void effectvol = openborvariant("effectvol");
        void Diamond = getglobalvar("Diamond");
        if(!Diamond){
            Diamond = loadsprite("data/sprites/diamond.gif");
            setglobalvar("Diamond", Diamond);
        }
 
        if(P1 != NULL()){
            MP = getentityproperty(P1, "mp");
            maxMP = getentityproperty(P1, "maxmp");
            HP = getentityproperty(P1, "health");
            aniID = getentityproperty(P1, "animationid");
            drawstring(20, 190, 1, "MP:_"+MP);
            if(MP == maxMP){ // If MP is full
                drawsprite(Diamond, 97, 24, 5000); // Image starts to display
                playsample(fullMP, 0, effectvol, effectvol, 100, 0);
            }
            else if(MP < maxMP){ // If MP is less than its max MP
                setglobalvar("Diamond", NULL()); // Image disappears
            }
            if(HP <= 0){
                setglobalvar("Diamond", NULL());
            }
        }
   }

}
 
Solution
I wanna play a sound in ondrawscript after the player's MP becomes full. However, after I add playsample under the MP's max limit, there's this buzzing and strange sound that plays unless you consume MP. It sounds kinda distorting after the moment you fill full MP.
The ondrawscript runs continuously (like update scripts) and you can use this event in order to draw stuff to the screen.

1713841444452.png

To play a sample once, you will need to use a variable as a flag, like the example below. Otherwise the sample will continuously be played at the same rate as the ondrawscript event, causing this "distorted" sound.

C:
void main(){
    playerMP();
}
void playerMP()
{
    if(openborvariant("in_level")==1){
        int P1 =...
I wanna play a sound in ondrawscript after the player's MP becomes full. However, after I add playsample under the MP's max limit, there's this buzzing and strange sound that plays unless you consume MP. It sounds kinda distorting after the moment you fill full MP.
The ondrawscript runs continuously (like update scripts) and you can use this event in order to draw stuff to the screen.

1713841444452.png

To play a sample once, you will need to use a variable as a flag, like the example below. Otherwise the sample will continuously be played at the same rate as the ondrawscript event, causing this "distorted" sound.

C:
void main(){
    playerMP();
}
void playerMP()
{
    if(openborvariant("in_level")==1){
        int P1 = getplayerproperty(0, "entity");
        int P2 = getplayerproperty(1, "entity");
        int P3 = getplayerproperty(2, "entity");
        int MP;
        int maxMP;
        int HP;
        void fullMP = loadsample("data/sounds/fullmp.wav");
        void aniID;
        void effectvol = openborvariant("effectvol");
        void Diamond = getglobalvar("Diamond");
        if(!Diamond){
            Diamond = loadsprite("data/sprites/diamond.gif");
            setglobalvar("Diamond", Diamond);
        }
 
        if(P1 != NULL()){
            MP = getentityproperty(P1, "mp");
            maxMP = getentityproperty(P1, "maxmp");
            HP = getentityproperty(P1, "health");
            aniID = getentityproperty(P1, "animationid");
            drawstring(20, 190, 1, "MP:_"+MP);
            if(MP == maxMP){ // If MP is full
                drawsprite(Diamond, 97, 24, 5000); // Image starts to display

                //PLAY SAMPLE ONCE AND SET THE VARIABLE TO 1
                if(getlocalvar("p1MpMax") == NULL()){
                    playsample(fullMP, 0, effectvol, effectvol, 100, 0);
                    setlocalvar("p1MpMax", 1);
                }
            }
            else if(MP < maxMP) != NULL()){ // If MP is less than its max MP
                setglobalvar("Diamond", NULL()); // Image disappears
            
                //CLEAR THE SAMPLE VARIABLE
                if(getlocalvar("p1MpMax") != NULL()){
                    setlocalvar("p1MpMax", NULL());
                }
            }
            if(HP <= 0){
                setglobalvar("Diamond", NULL());
            }
        }
   }

}
 
Last edited:
Solution
Thank you so much, Kratus! Much appreciated! I didn't know you can use localvars like you do with globalvars and entityvars, but a certain type of localvar I know seems to be used for declaring some stuff like you see getlocalvar("self"), getlocalvar("frame"), getlocalvar("other"), "which", "platform", "player", etc.

I will make another help topic of what I want with the player's MP when it comes to full MP with sound. But it's in other conditions except for spawning and respawning. Otherwise, I will post it in this topic though the topic of the buzz sound is already solved here.
 
Back
Top Bottom