Scripted healing

AkuShadow

Member
I have a script that restores MP:
@script
void self = getlocalvar("self"); //get the self var
void power = getentityproperty(self,"mp"); // get target's current mp
changeentityproperty(self, "mp", power+10);
@end_script

Is there a way I can make this script also restore HP at a slower rate?
I am learning through trial and error so please explain as if I know nothing.
 
This script instantly changes HP because it's an animation script – it happens during a single frame of the animation.

If you want it to work periodically, you need to change the script and its type.

Save this as "healing.c" inside the scripts folder and callit from your character's header

script data/scripts/healing.c

C-like:
void main(){
   void self = getlocalvar("self"); //Get calling entity.
   void health = getentityproperty(self,"health"); //get health
   int time = openborvariant("elapsed_time");// get time

   if ( time % 600 == 0 && getentityproperty(self, "exists") && !getentityproperty(self, "dead"))
   {
   changeentityproperty(self, "health", health+5);//add health
   }
}
 
This script instantly changes HP because it's an animation script – it happens during a single frame of the animation.

If you want it to work periodically, you need to change the script and its type.

Save this as "healing.c" inside the scripts folder and callit from your character's header

script data/scripts/healing.c

C-like:
void main(){
   void self = getlocalvar("self"); //Get calling entity.
   void health = getentityproperty(self,"health"); //get health
   int time = openborvariant("elapsed_time");// get time

   if ( time % 600 == 0 && getentityproperty(self, "exists") && !getentityproperty(self, "dead"))
   {
   changeentityproperty(self, "health", health+5);//add health
   }
}

Be careful with using modulo operators against elapsed time. OpenBOR intentionally runs certain updates desynced. So it is possible, however unlikely, that you will have a "miss". I would use a localvar and overflow based timer to guarantee my function fires.

DC
 
Be careful with using modulo operators against elapsed time. OpenBOR intentionally runs certain updates desynced. So it is possible, however unlikely, that you will have a "miss". I would use a localvar and overflow based timer to guarantee my function fires.
ah, I alread saw it happens - in Avengers United Battle Force, the training stage has a code like that to constantly refill the player MP.
C-like:
updatescript @script
void main(){

    int time = openborvariant("elapsed_time");// get time
    if (time % 500 == 0)
    {
       int P1 = getplayerproperty(0, "entity");
       int P2 = getplayerproperty(1, "entity");
       changeentityproperty(P1, "mp", 9999);
       changeentityproperty(P2, "mp", 9999);
     }

}
@end_script

In some rare moments, it won't fire. Probably, this is the cause.
Thanks
 
This script instantly changes HP because it's an animation script – it happens during a single frame of the animation.

If you want it to work periodically, you need to change the script and its type.

Save this as "healing.c" inside the scripts folder and callit from your character's header

script data/scripts/healing.c

C-like:
void main(){
   void self = getlocalvar("self"); //Get calling entity.
   void health = getentityproperty(self,"health"); //get health
   int time = openborvariant("elapsed_time");// get time

   if ( time % 600 == 0 && getentityproperty(self, "exists") && !getentityproperty(self, "dead"))
   {
   changeentityproperty(self, "health", health+5);//add health
   }
}
not to be rude here or nagging here, but I do not know how to make that work. I saved it as heal.c but the script im already using doesnt look like its using anything other than what I showed here. I dont even know how that script is working.
This works:
@script
void self = getlocalvar("self"); //get the self var
void power = getentityproperty(self,"mp"); // get target's current mp
changeentityproperty(self, "mp", power+10);
@end_script

but changing that to this:
@script
void self = getlocalvar("self"); //get the self var
void health = getentityproperty(self,"health"); // get target's current hp
changeentityproperty(self, "health", health+10);
@end_script

Just crashes the game. The few time I got it to not crash the game, the mp worked but it still didnt restore hp.

Also this is the whole animation:
anim run
@script
void self = getlocalvar("self"); //get the self var
void health = getentityproperty(self,"health"); // get target's current hp
changeentityproperty(self, "health", health+10);
@end_script
loop 1
delay 8
offset 80 129
bbox 60 93 20 40
frame data/chars/ken/run00.gif
frame data/chars/ken/run01.gif
frame data/chars/ken/run02.gif
frame data/chars/ken/run03.gif
frame data/chars/ken/run04.gif
 
Last edited:
not to be rude here or nagging here, but I do not know how to make that work. I saved it as heal.c but the script im already using doesnt look like its using anything other than what I showed here. I dont even know how that script is working.
This works:
@script
void self = getlocalvar("self"); //get the self var
void power = getentityproperty(self,"mp"); // get target's current mp
changeentityproperty(self, "mp", power+10);
@end_script

but changing that to this:
@script
void self = getlocalvar("self"); //get the self var
void health = getentityproperty(self,"health"); // get target's current hp
changeentityproperty(self, "health", health+10);
@end_script

Just crashes the game. The few time I got it to not crash the game, the mp worked but it still didnt restore hp.

Also this is the whole animation:
anim run
@script
void self = getlocalvar("self"); //get the self var
void health = getentityproperty(self,"health"); // get target's current hp
changeentityproperty(self, "health", health+10);
@end_script
loop 1
delay 8
offset 80 129
bbox 60 93 20 40
frame data/chars/ken/run00.gif
frame data/chars/ken/run01.gif
frame data/chars/ken/run02.gif
frame data/chars/ken/run03.gif
frame data/chars/ken/run04.gif
Please post your code in code tags.

 
Please post your code in code tags.

Code:
@script
void self = getlocalvar("self"); //get the self var
void power = getentityproperty(self,"mp"); // get target's current mp
changeentityproperty(self, "mp", power+10);
@end_script

Code:
@script
void self = getlocalvar("self"); //get the self var
void health = getentityproperty(self,"health"); // get target's current hp
changeentityproperty(self, "health", health+10);
@end_script

Like that? The first one works, the second one will either crash or do nothing.
 
Code:
@script
void self = getlocalvar("self"); //get the self var
void power = getentityproperty(self,"mp"); // get target's current mp
changeentityproperty(self, "mp", power+10);
@end_script

Code:
@script
void self = getlocalvar("self"); //get the self var
void health = getentityproperty(self,"health"); // get target's current hp
changeentityproperty(self, "health", health+10);
@end_script

Like that? The first one works, the second one will either crash or do nothing.

Yes, that helps immensely. I don't see a problem in your code as is. Please also post the log (in code tags). The log is always step 0 - the engine isn't really crashing, it is performing a controlled shutdown and recording error to the log. That will usually pinpoint the problem or at least get us closer.

DC
 
is pointing exactly where you need to check, line 3508, column 37. And also could use an animation script instead of inline code
anim run
Code:
@script
void self = getlocalvar("self"); //get the self var
void health = getentityproperty(self,"health"); // get target's current hp
changeentityproperty(self, "health", health+10);
@end_script
loop 1
delay 8
offset 80 129
bbox 60 93 20 40
frame data/chars/ken/run00.gif
frame data/chars/ken/run01.gif
frame data/chars/ken/run02.gif
frame data/chars/ken/run03.gif
frame data/chars/ken/run04.gif

this works as mp but not as hp. What do I change?
 
I tried again anyway and I found the crash was due to my error of putting:

Code:
@script
void self = getlocalvar("self"); //get the self var
void health = getentityproperty(self,"health"); // get target's current hp
changeentityproperty(self, "health", power+10);
@end_script

instead of

Code:
@script
void self = getlocalvar("self"); //get the self var
void health = getentityproperty(self,"health"); // get target's current hp
changeentityproperty(self, "health", health+10);
@end_script

so now, it does not crash but it also still does not cause healing.
 
Also this is the whole animation:
anim run
@script
void self = getlocalvar("self"); //get the self var
void health = getentityproperty(self,"health"); // get target's current hp
changeentityproperty(self, "health", health+10);
@end_script
loop 1
delay 8
offset 80 129
bbox 60 93 20 40
frame data/chars/ken/run00.gif
frame data/chars/ken/run01.gif
frame data/chars/ken/run02.gif
frame data/chars/ken/run03.gif
frame data/chars/ken/run04.gif
First issue: you are using an inline script, on a looped animation.
This will fire in EVERY frame of your animation (hence why you want it to be slower)

if you need an inline script to be run only in one frame, you need to wrap it inside a if / else, like this:
@script
if (frame == 1){ // will happens on the second frame - frames are 0 indexed
void self = getlocalvar("self"); //get the self var
void power = getentityproperty(self,"mp"); // get target's current mp
changeentityproperty(self, "mp", power+10);
}
@end_script

I have a function for what you need and it works fine:
C-like:
void refill(int iValue)
//Refill the MP bar with the desired value.
//Douglas Baldan
{
    void self = getlocalvar("self");
    void Health = getentityproperty(self,"health"); //get player health
    changeentityproperty(self, "health", Health+iValue);
}

But needs to be declared on a function file. If you want to use it as inline script (something we don't advice), it should be this:
@script
if (frame == 1){ // will happens on the second frame - frames are 0 indexed
void self = getlocalvar("self");
void Health = getentityproperty(self,"health"); //get player health
int iValue = 10; // Amount of life healed
changeentityproperty(self, "health", Health+iValue);
}
@end_script
 
Ok. I tested it out and it doesnt crash but it also doesnt heal from inside the characters text(Im assuming thats what 'inline' means)
If by function file, you mean the files in the script folder, I can create the heal.c, like you asked and add it in the characters header but then how would I make it so the character only heals during a specific animation? Im honestly trying not to waste yalls time but I did say I dont really know what Im doing.
 
Last edited:
Im honestly trying not to waste yalls time but I did say I dont really know what Im doing.
Don't take this the wrong way or think I'm trying to discourage you, but I think you need to take a few steps back, read the documentation before you can move forward with this.

Because when you use something native to the engine, it takes care of many things automatically. But when it comes to scripts, while you have a lot of power... you also have the problem of having too much power.

I always use this analogy: working with scripts is like handling a chainsaw. Used correctly, it's a very useful tool. But using it incorrectly can be disastrous.

Take a look at these tutorials:
 
Back
Top Bottom