SP meter script (Tech Demo)

msmalik681

OpenBOR Developer
Staff member
This is a tech demo showing how to add a extra meter called SP (but it could be named anything) it will recover over time and you can execute basic cancel commands to use set amounts of sp see the script data/scripts/ondraw.c for more information.

Edit: Updated v3 with fix so there is no delay to the sp meter when first entering a stage or move stages.

1657453806263.png

Download: SP_Meter_v3.tar.xz
 
Last edited:
Was this line:
int time = openborvariant("elapled_time");

supposed to be int time = openborvariant("elapsed_time"); ?

Is it possible that I can change your code from mp to something else?
I would like to have typemp = 1 for MP bar for skills and
use your code to assign it to something else, something like SP for SP bar (for super skills).
Basically, I would like to have 2 bars: one for MP bar and another one for SP bar.
I hope it makes sense to you. I am sorry for being newbie.

Your Youtube tutorial videos really helped me alot, and I really appreciate for all your help and efforts!

Thank you very much for posting!
 
Last edited:
Thanks for pointing out the mistake it has been corrected.

Yes you can have as many bars as you want but you will have to find a way to visually show them on screen or just a suggestion your could make the player flash when their SP is full as your using a update script anyway. And it involves more advanced scripting knowledge to make them work.

here is a modified version to recover SP instead of MP:
C-like:
void main()
{
    void self = getlocalvar("self");
    int sp = getentityvar(self,"sp");
    int max = 100; //set the max to what you like
    int time = openborvariant("elapsed_time");
    int timer;

    if(!timer){ // this controls how quick the sp recovers
        timer = time + 100; //change 100 to control how fast or slow sp recovers
    }
    
    if(time > timer && sp < max){ //sp recovery control
        setentityvar(self,"sp",sp+1); //recover 1 sp
        timer = NULL();    //reset timer
    }
}

Now you need some kind of animation script to control checking if correct input was keyed then is SP is enough and finally to perform the attack and reset the SP.

We were all noobs at some point.
 
Thanks for pointing out the mistake it has been corrected.

Yes you can have as many bars as you want but you will have to find a way to visually show them on screen or just a suggestion your could make the player flash when their SP is full as your using a update script anyway. And it involves more advanced scripting knowledge to make them work.

here is a modified version to recover SP instead of MP:
C-like:
void main()
{
    void self = getlocalvar("self");
    int sp = getentityvar(self,"sp");
    int max = 100; //set the max to what you like
    int time = openborvariant("elapsed_time");
    int timer;

    if(!timer){ // this controls how quick the sp recovers
        timer = time + 100; //change 100 to control how fast or slow sp recovers
    }
   
    if(time > timer && sp < max){ //sp recovery control
        setentityvar(self,"sp",sp+1); //recover 1 sp
        timer = NULL();    //reset timer
    }
}

Now you need some kind of animation script to control checking if correct input was keyed then is SP is enough and finally to perform the attack and reset the SP.

We were all noobs at some point.
Thank you very much.
I have not had the time to test them out yet. I will report back after I test it.
By now I still don't know how to write animation script yet, but I will eventually!
Hopefully someone else has time to add animation script and test out your code before me.
 
@Bruce OK here is a basic animation changer based on key press I made for my double dragon mod. save it in your scripts folder as "scripts.c" and add to your player header the line "animationscript data/scripts/scripts.c"

C-like:
void key2ani(char ani, int sp, char key1, char key2)
{//msmalik681 change animation based on key press or combination
 //key inputs: "moveup" "movedown" "moveforward" "moveback" "attack" "attack2" "attack3" "attack4" "jump"
 //press: 3=holding 1=press 2=release default holding.

    void self = getlocalvar("self");
    int current_sp = getentityvar(self,"sp");
    int dir = getentityproperty(self, "direction");  //Get current facing direction
    if(key1=="moveforward"){key1 = dir==0?"moveleft":"moveright";}
    if(key1=="moveback"){key1 = dir==0?"moveright":"moveleft";}
    if(key2=="moveforward"){key2 = dir==0?"moveleft":"moveright";}
    if(key2=="moveback"){key2 = dir==0?"moveright":"moveleft";}

    if(key2){// check combination key press
        if ( playerkeys(getentityproperty(self,"playerindex"), 3, key1) && playerkeys(getentityproperty(self,"playerindex"), 3, key2) ) {
            if( sp && current_sp >= sp ){
            setentityvar(self,"sp",sp - current_sp);
            } else if ( sp && current_sp < sp ){ return 0; }
            changeentityproperty(self, "velocity", 0, 0, 0); //Stop moving!
            performattack (self, openborconstant("ani_" + ani)); //Change the animation.
        }
    } else {// check single key press
        if ( playerkeys(getentityproperty(self,"playerindex"), 3, key1) ) {
            if( sp && current_sp >= sp ){
            setentityvar(self,"sp",sp - current_sp);
            } else if ( sp && current_sp < sp ){ return 0; }
            changeentityproperty(self, "velocity", 0, 0, 0); //Stop moving!
            performattack (self, openborconstant("ani_" + ani)); //Change the animation.
        }
    }


}

example usage:

anim walk
loop 1
frame none
@cmd frame2ani "freespecial" 20 "attack2"
frame none

the above will switch to freespecial if you have at least 20sp if you press attack2.

anim walk
loop 0
frame none
@cmd frame2ani "follow2" 0 "moveforward" "attack"
frame none

the above code will switch to follow2 if you press forward and attack no sp required. remember to declare it on each frame you want to be able to cancel from.
 
Last edited:
there are many ways your could display it but I will just cover a very simple solution. take the below code and save it as "updated.c" in the scripts folder. also the above script had a issue I updated it.

C-like:
void main()
{
    if(OBV("in_level"))
    {
        void P1 = getplayerproperty(0,"entity");
        void P2 = getplayerproperty(1,"entity");
        void P3 = getplayerproperty(2,"entity");
        void P4 = getplayerproperty(3,"entity");
   
        if(P1) { drawstring(100, 100, 3, 999999993, "SP: + "getentityvar(P1,"sp")); }
        if(P2) { drawstring(200, 100, 3, 999999993, "SP: + "getentityvar(P2,"sp")); }
        if(P3) { drawstring(300, 100, 3, 999999993, "SP: + "getentityvar(P3,"sp")); }
        if(P4) { drawstring(400, 100, 3, 999999993, "SP: + "getentityvar(P4,"sp")); }
    }
}
 
Last edited:
What?! There's index 3 for holding in playerkeys? I didn't know that exists. When was that updated? You got it from the source code? Or is it an index flag similar to the animation flag?
 
@Bruce OK here is a basic animation changer based on key press I made for my double dragon mod. save it in your scripts folder as "scripts.c" and add to your player header the line "animationscript data/scripts/scripts.c"

C-like:
void key2ani(char ani, int sp, char key1, char key2)
{//msmalik681 change animation based on key press or combination
 //key inputs: "moveup" "movedown" "moveforward" "moveback" "attack" "attack2" "attack3" "attack4" "jump"
 //press: 3=holding 1=press 2=release default holding.

    void self = getlocalvar("self");
    int current_sp = getentityvar(self,"sp");
    int dir = getentityproperty(self, "direction");  //Get current facing direction
    if(key1=="moveforward"){key1 = dir==0?"moveleft":"moveright";}
    if(key1=="moveback"){key1 = dir==0?"moveright":"moveleft";}
    if(key2=="moveforward"){key2 = dir==0?"moveleft":"moveright";}
    if(key2=="moveback"){key2 = dir==0?"moveright":"moveleft";}

    if(key2){// check combination key press
        if ( playerkeys(getentityproperty(self,"playerindex"), 3, key1) && playerkeys(getentityproperty(self,"playerindex"), 3, key2) ) {
            if( sp && current_sp >= sp ){
            changeentityvar(self,"sp",sp-current_sp);
            } else if ( sp && current_sp < sp ){ return 0; }
            changeentityproperty(self, "velocity", 0, 0, 0); //Stop moving!
            performattack (self, openborconstant("ani_" + ani)); //Change the animation.
        }
    } else {// check single key press
        if ( playerkeys(getentityproperty(self,"playerindex"), 3, key1) ) {
            if( sp && current_sp >= sp ){
            setentityvar(self,"sp",sp-current_sp);
            } else if ( sp && current_sp < sp ){ return 0; }
            changeentityproperty(self, "velocity", 0, 0, 0); //Stop moving!
            performattack (self, openborconstant("ani_" + ani)); //Change the animation.
        }
    }


}

example usage:

anim walk
loop 1
frame none
@cmd frame2ani "freespecial" 20 "attack2"
frame none

the above will switch to freespecial if you have at least 20sp if you press attack2.

anim walk
loop 0
frame none
@cmd frame2ani "follow2" 0 "moveforward" "attack"
frame none

the above code will switch to follow2 if you press forward and attack no sp required. remember to declare it on each frame you want to be able to cancel from.
Wow, you are amazing and have a good heart helping others.
We really need more people like you.
I'm doing this is for my hobby during freetime because I love learning to program game stuff.

So if I want to use the freespecial22 with 20 SP. I can write something like this:

anim walk
loop 1
frame none
frame none
frame none
@cmd frame4ani "freespecial22" 20 "d f attack2"
frame none

When I press d, f + attack2, it would perform freespecial22 by using 20sp. Will this work?

Again, thank you so much for your help!
 
This is a simple cancel system it only supports single button or direction and button so you could do.

If you hold forward and press attack2:
@cmd frame2ani "freespecial22" 20 "moveforward" "attack2"

If you hold down and press attack:
@cmd frame2ani "freespecial22" 20 "movedown" "attack2"

If you hold up and press attack:
@cmd frame2ani "freespecial22" 20 "moveup" "attack2"

if you want a full excellent scripted cancel system check out the daimo cancel system by piccolo. But adding sp support might not be so easy.

You think im good well . . . . I aint that good lol.

 
This is a simple cancel system it only supports single button or direction and button so you could do.

If you hold forward and press attack2:
@cmd frame2ani "freespecial22" 20 "moveforward" "attack2"

If you hold down and press attack:
@cmd frame2ani "freespecial22" 20 "movedown" "attack2"

If you hold up and press attack:
@cmd frame2ani "freespecial22" 20 "moveup" "attack2"

if you want a full excellent scripted cancel system check out the daimo cancel system by piccolo. But adding sp support might not be so easy.

You think im good well . . . . I aint that good lol.

This is all I needed anyway. Well, I am pretty sure you are a lot better than me.
You have the passion and like to help the others that's what counts.
I'll report back with bugs if there is any or something new later.
Thank you and goodnight
 
I am getting error messages:

Property name 'sp' is not supported by function getentityproperty.

and

Script error: data/scripts/updated.c, line 49: Invalid function call or expression 'getentityvar' (in production 'postfix_expr2')

if(P1) { drawstring(100, 100, 3, 999999993, "SP: "getentityvar(P1,"sp")); }

Script error: data/scripts/updated.c, line 49: Unknown error ';' (in production 'stmt_list')

if(P1) { drawstring(100, 100, 3, 999999993, "SP: "getentityvar(P1,"sp")); }

.........................


********** An Error Occurred **********
* Shutting Down *

Failed to parse script file: 'data/scripts/updated.c'!


Do I need to declare the "sp" somewhere?
and I have no clue why I am also getting error message for drawstring. The code seems to me.

Thank you
 

I haven't really followed this thread much so I don't know a lot about the overall script. That said, I can see the string is not concatenated correctly. Try this instead (note the added +):

C:
if(P1)
{
     drawstring(100, 100, 3, 999999993, "SP: " + getentityvar(P1,"sp"));
}

HTH,
DC
 
I've found one issue:
C:
changeentityvar(self,"sp",sp-current_sp);

It should be:
C:
setentityvar(self,"sp",sp-current_sp);

But it's not related to the crash... :rolleyes:
So let's analyze elsewhere:
Property name 'sp' is not supported by function getentityproperty.

Did you declare getentityproperty(self,"sp") somewhere in your script?
 
@Bruce this was a rushed script and I did not test it so there was bound to be some errors tried updating the scripts above hope they work this time.
 
thank you very much
Were you be able to get it to work?
I am modifying the existing game, but none of these scripts has worked for me yet and I haven't had to the time to check to see what is causing the problems.
I think there must be some kind of conflicts between these scripts and the ones in the existing game that I am modifying.
Since I am still newbie, it will take a while to figure it out.
Thanks
 
Were you be able to get it to work?
I am modifying the existing game, but none of these scripts has worked for me yet and I haven't had to the time to check to see what is causing the problems.
I think there must be some kind of conflicts between these scripts and the ones in the existing game that I am modifying.
Since I am still newbie, it will take a while to figure it out.
Thanks
Hello, I am currently using "guardpoints" as the SP function, and I have used the above script without success before. Feel sorry
 
Back
Top Bottom