Solved A script to stop mprate while the char is running

Question that is answered or resolved.

16-bit Fighter

Active member
By helping myself thanks to a script @Kratus gave me I'm trying to do a new one. But OB shuts down once the character selection is supposed to appear.

The log tells me:
Code:
Script function 'changeentityproperty' returned an exception, check the manual for details.Script function 'changeentityproperty' returned an exception, check the manual for details.
and
Code:
There's an exception while executing script 'ondrawscript' data/chars/andy'/Andy'.txt

Here is my script :
Code:
void main()
{//Change mprate if running and according to the number or enemies and number of MP
    void self     = getlocalvar("self");
    void ani    = getentityproperty(self, "animationID"); //GET CURRENT ANIMATION
    int mp        = getentityproperty(self, "mp"); //GET CURRENT MP
    int recover    = getentityproperty(self, "mprate"); //GET MP RECOVER
    int ecount    = openborvariant("count_enemies"); //Get how many enemies are active
    int pcount    = openborvariant("count_players"); //Get how many players are active
    
    if(getlocalvar("defaultMprate"+self) == NULL()){ //VARIABLE "DEFAULT MPRATE" IS NULL?? FIRST CHARACTER SPAWN IN THE GAME??
        setlocalvar("defaultMprate"+self, recover); //CREATE A VARIABLE AND SAVE DEFAULT MPRATE
    }
    if (ecount < pcount && mp > 100) { // COUNT OF ENEMIES IS MORE THAN THIS OF PLAYERS AND MP IS MORE THAN 100??
        changeentityproperty(self, "mprate", 0); // STOP MPRATE
    }       
    if(ani == openborconstant("ANI_RUN")){ //IS IN RUNNING ANIMATION??
    if(mp > 0){ //CHECK IF MP IS ZERO TO PAUSE SCRIPT EXECUTION WITH NO MP
        changeentityproperty(self, "mprate", 0); // STOP MPRATE
        }
        }else{ //IS NOT IN RUNNING ANIMATION??
        changeentityproperty(self, "mprate", getlocalvar("defaultMprate"+self)); //DEFAULT MPRATE
    }
}
 
Solution
By helping myself thanks to a script @Kratus gave me I'm trying to do a new one. But OB shuts down once the character selection is supposed to appear.

The log tells me:
Code:
Script function 'changeentityproperty' returned an exception, check the manual for details.Script function 'changeentityproperty' returned an exception, check the manual for details.
and
Code:
There's an exception while executing script 'ondrawscript' data/chars/andy'/Andy'.txt

Here is my script :
Code:
void main()
{//Change mprate if running and according to the number or enemies and number of MP
    void self     = getlocalvar("self");
    void ani    = getentityproperty(self, "animationID"); //GET CURRENT ANIMATION
    int mp        =...
By helping myself thanks to a script @Kratus gave me I'm trying to do a new one. But OB shuts down once the character selection is supposed to appear.

The log tells me:
Code:
Script function 'changeentityproperty' returned an exception, check the manual for details.Script function 'changeentityproperty' returned an exception, check the manual for details.
and
Code:
There's an exception while executing script 'ondrawscript' data/chars/andy'/Andy'.txt

Here is my script :
Code:
void main()
{//Change mprate if running and according to the number or enemies and number of MP
    void self     = getlocalvar("self");
    void ani    = getentityproperty(self, "animationID"); //GET CURRENT ANIMATION
    int mp        = getentityproperty(self, "mp"); //GET CURRENT MP
    int recover    = getentityproperty(self, "mprate"); //GET MP RECOVER
    int ecount    = openborvariant("count_enemies"); //Get how many enemies are active
    int pcount    = openborvariant("count_players"); //Get how many players are active
  
    if(getlocalvar("defaultMprate"+self) == NULL()){ //VARIABLE "DEFAULT MPRATE" IS NULL?? FIRST CHARACTER SPAWN IN THE GAME??
        setlocalvar("defaultMprate"+self, recover); //CREATE A VARIABLE AND SAVE DEFAULT MPRATE
    }
    if (ecount < pcount && mp > 100) { // COUNT OF ENEMIES IS MORE THAN THIS OF PLAYERS AND MP IS MORE THAN 100??
        changeentityproperty(self, "mprate", 0); // STOP MPRATE
    }     
    if(ani == openborconstant("ANI_RUN")){ //IS IN RUNNING ANIMATION??
    if(mp > 0){ //CHECK IF MP IS ZERO TO PAUSE SCRIPT EXECUTION WITH NO MP
        changeentityproperty(self, "mprate", 0); // STOP MPRATE
        }
        }else{ //IS NOT IN RUNNING ANIMATION??
        changeentityproperty(self, "mprate", getlocalvar("defaultMprate"+self)); //DEFAULT MPRATE
    }
}
@16-bit Fighter

According to what I saw on the engine source code, the "mprate" property is not a changeable value, you can only get it.
Instead, to change the "mprate" in a character you must use the "mpset" property, like this:

C:
changeentityproperty(self, "mpset", mp, mpstable, mpstableval, mprate, mpdroprate, chargerate);

1679431056270.png

In addition, the select screen deactivates most default character's routines and I suggest checking if the character is in-level before running this script.

C:
if(openborvariant("in_level"))
{
    doSomething();
}
 
Last edited:
Solution
I almost manage what I want to do. Here is the script:

Code:
void main()
{//Change mprate if running and according to the number or enemies and number of MP
    void self     = getlocalvar("self");
    void ani    = getentityproperty(self, "animationID"); //GET CURRENT ANIMATION
    int maxMp    = getentityproperty(self, "maxmp"); //GET MAXIMUM MP
    int mp        = getentityproperty(self, "mp"); //GET CURRENT MP
    int recover    = getentityproperty(self, "mprate"); //GET MP RECOVER
    int ecount    = openborvariant("count_enemies"); //Get how many enemies are active
    int pcount    = openborvariant("count_players"); //Get how many players are active
    
    if (ecount < pcount && mp > 100) { // COUNT OF ENEMIES IS LESS THAN THIS OF PLAYERS AND MP IS MORE THAN 100??
        changeentityproperty(self, "mpset", maxMp, 0, mp, 0, 0, 0); // STOP MPRATE
    }       
    if(ani == openborconstant("ANI_RUN")
    || ani == openborconstant("ANI_JUMP")
    || ani == openborconstant("ANI_RUNJUMP")
    || ani == openborconstant("ANI_JUMPATTACK")
    || ani == openborconstant("ANI_JUMPATTACK2")
    || ani == openborconstant("ANI_JUMPFORWARD")
    || ani == openborconstant("ANI_SLIDE")
    ){ //IS IN RUNNING OR JUMPING ANIMATIONS ??
    if(mp > 0){ //CHECK IF MP IS ZERO TO PAUSE SCRIPT EXECUTION WITH NO MP
        changeentityproperty(self, "mpset", maxMp, 0, mp, 0, 0, 0); // STOP MPRATE
        }
        }else{ //IS NOT IN RUNNING ANIMATION??
        changeentityproperty(self, "mpset", 960, 1, 960, 20, 0, 0);
    }
}

Here is the part that doesn't work in the script above:

Code:
if (ecount < pcount && mp > 100) { // COUNT OF ENEMIES IS LESS THAN THIS OF PLAYERS AND MP IS MORE THAN 100??

        changeentityproperty(self, "mpset", maxMp, 0, mp, 0, 0, 0); // STOP MPRATE

    }

PS: I wanted to put in color some part of the code in this post but I don't know how to do in code mode.
 
I almost manage what I want to do. Here is the script:

Code:
void main()
{//Change mprate if running and according to the number or enemies and number of MP
    void self     = getlocalvar("self");
    void ani    = getentityproperty(self, "animationID"); //GET CURRENT ANIMATION
    int maxMp    = getentityproperty(self, "maxmp"); //GET MAXIMUM MP
    int mp        = getentityproperty(self, "mp"); //GET CURRENT MP
    int recover    = getentityproperty(self, "mprate"); //GET MP RECOVER
    int ecount    = openborvariant("count_enemies"); //Get how many enemies are active
    int pcount    = openborvariant("count_players"); //Get how many players are active
   
    if (ecount < pcount && mp > 100) { // COUNT OF ENEMIES IS LESS THAN THIS OF PLAYERS AND MP IS MORE THAN 100??
        changeentityproperty(self, "mpset", maxMp, 0, mp, 0, 0, 0); // STOP MPRATE
    }      
    if(ani == openborconstant("ANI_RUN")
    || ani == openborconstant("ANI_JUMP")
    || ani == openborconstant("ANI_RUNJUMP")
    || ani == openborconstant("ANI_JUMPATTACK")
    || ani == openborconstant("ANI_JUMPATTACK2")
    || ani == openborconstant("ANI_JUMPFORWARD")
    || ani == openborconstant("ANI_SLIDE")
    ){ //IS IN RUNNING OR JUMPING ANIMATIONS ??
    if(mp > 0){ //CHECK IF MP IS ZERO TO PAUSE SCRIPT EXECUTION WITH NO MP
        changeentityproperty(self, "mpset", maxMp, 0, mp, 0, 0, 0); // STOP MPRATE
        }
        }else{ //IS NOT IN RUNNING ANIMATION??
        changeentityproperty(self, "mpset", 960, 1, 960, 20, 0, 0);
    }
}

Here is the part that doesn't work in the script above:

Code:
if (ecount < pcount && mp > 100) { // COUNT OF ENEMIES IS LESS THAN THIS OF PLAYERS AND MP IS MORE THAN 100??

        changeentityproperty(self, "mpset", maxMp, 0, mp, 0, 0, 0); // STOP MPRATE

    }

PS: I wanted to put in color some part of the code in this post but I don't know how to do in code mode.
@16-bit Fighter

According to what I understood about the desired effect you only need to put a "else" to create two conditions. In addition, you can use NULL() in the mpset function to avoid changing properties you don't want to.

C:
void main()
{//Change mprate if running and according to the number or enemies and number of MP
    void self    = getlocalvar("self");
    void ani    = getentityproperty(self, "animationID"); //GET CURRENT ANIMATION
    int maxMp    = getentityproperty(self, "maxmp"); //GET MAXIMUM MP
    int mp        = getentityproperty(self, "mp"); //GET CURRENT MP
    int recover    = getentityproperty(self, "mprate"); //GET MP RECOVER
    int ecount    = openborvariant("count_enemies"); //Get how many enemies are active
    int pcount    = openborvariant("count_players"); //Get how many players are active
    
    //PRIORITIZE THIS FIRST CONDITION, BUT IF IT'S NO MET PROCEED TO THE SECONDARY CONDITION!!
    if (ecount < pcount && mp > 100) { // COUNT OF ENEMIES IS LESS THAN THIS OF PLAYERS AND MP IS MORE THAN 100??
        changeentityproperty(self, "mpset", NULL(), NULL(), NULL(), 0, NULL(), NULL()); // STOP MPRATE
    }
    else //SECONDARY CONDITION
    {
        if(ani == openborconstant("ANI_RUN")
        || ani == openborconstant("ANI_JUMP")
        || ani == openborconstant("ANI_RUNJUMP")
        || ani == openborconstant("ANI_JUMPATTACK")
        || ani == openborconstant("ANI_JUMPATTACK2")
        || ani == openborconstant("ANI_JUMPFORWARD")
        || ani == openborconstant("ANI_SLIDE")
        ){ //IS IN RUNNING OR JUMPING ANIMATIONS ??
        if(mp > 0){ //CHECK IF MP IS ZERO TO PAUSE SCRIPT EXECUTION WITH NO MP
            changeentityproperty(self, "mpset", NULL(), NULL(), NULL(), 0, NULL(), NULL()); // STOP MPRATE
            }
            }else{ //IS NOT IN RUNNING ANIMATION??
            changeentityproperty(self, "mpset", 960, 1, 960, 20, NULL(), NULL());
        }
    }
}

To use the C language format when posting a code you need to follow these steps:

1679953441217.png

1679953510156.png
 
Big thanks Kratus, the script works fine now!

To use the C language format when posting a code you need to follow these steps:
It automatically colors specific things but if I want to color by myself to make people focus on a part of the code I want, it doesn't work because "[COLOR=rgb(number, number, number)]blabla[/COLOR]" appears in C code format.
 
Last edited:
Big thanks Kratus, the script works fine now!


It automatically colors specific things but if I want to color by myself to make people focus on a part of the code I want, it doesn't work because "[COLOR=rgb(number, number, number)]blabla[/COLOR]" appears in C code format.

Use Rich BB. It won't give you auto coloring like a language specific code tag, but it allows you to use all the normal forum text. This is all well documented by both me and the forum software itself.

DC
 
Back
Top Bottom