Solved Script_Play slow down/stop run animation when running has stopped

Question that is answered or resolved.

Glitch

Member
How would I go about using an in-file script (@script, not reliant on external script file) to play an animation when directional key (forward)  is released during run animation?

The animation played would be a slow down/stop run animation, when forward button is released.

I saw it could be done with script somewhere, tried searching but could not find it, found other scripts that I tried using and modifying.

I tried writing it like this:

@script
void self = getlocalvar("self");
int iPIndex = getentityproperty(self,"playerindex"); //Get player index

if(releasekeys(iPIndex, 0, "moveleft")) // Left is pressed?
{
        changeentityproperty(self, "animation",openborconstant("ANI_FREESPECIAL56"));
}
        else if (releasekeys(iPIndex, 0, "moveright"))// Right is pressed?
{changeentityproperty(self, "animation",openborconstant("ANI_FREESPECIAL56"));
}
@end_script

It does not work at all, I am doing something wrong, pretty sure releasekeys is not being used correctly...
How do I get the released key variable/integer and  use it to play an animation?
 
Glitch said:

Glitch, you have a couple of problems here.

First..

My #1 rule of scripting - if you're using @script tags, you're doing it wrong. Seriously. Inline code is the absolute least optimal method 99.99% of the time, and even then it should only be used to call functions. Whatever reason you want specifically to keep the script out of external files, you should be doing the opposite of that. Double for key actions.

Triple when you want to do something in response to press or release event. Scripts in OpenBOR (and pretty much every engine, database, application, etc.) run in response to events. Once the event happens, it's over. It's logically impossible to capture one event inside of another. @script tags insert code into the model's animation script. The animation script is an event. It runs every time a frame updates. When you release a key, that's a different event. See where I'm going with this?

You simply can't catch the press or release of a key within an animation script. You can get the state of a key (whether or not it is currently pressed), but unless you add some time tracking code, there's no way to know when the initial press or release actually happened. Why bother with all that when you don't have to? Do it right and use the keyscript. If you are unsure how, no problem. We'll help.

Second...

Releasekeys is not a native OpenBOR script function. If you copied that from somewhere, it was a custom function the author wrote. Doesn't matter anyway, since if you take my advice and move your concept into a keyscript the event is handled by proxy.

Give me long enough to get to my office and I'll write a quickie function to do the run stop. I need one myself anyway.

DC

 
Damon Caskey said:
Glitch said:

Glitch, you have a couple of problems here.

First..

My #1 rule of scripting - if you're using @script tags, you're doing it wrong. Seriously. Inline code is the absolute least optimal method 99.99% of the time, and even then it should only be used to call functions. Whatever reason you want specifically to keep the script out of external files, you should be doing the opposite of that. Double for key actions.

Triple when you want to do something in response to press or release event. Scripts in OpenBOR (and pretty much every engine, database, application, etc.) run in response to events. Once the event happens, it's over. It's logically impossible to capture one event inside of another. @script tags insert code into the model's animation script. The animation script is an event. It runs every time a frame updates. When you release a key, that's a different event. See where I'm going with this?

You simply can't catch the press or release of a key within an animation script. You can get the state of a key (whether or not it is currently pressed), but unless you add some time tracking code, there's no way to know when the initial press or release actually happened. Why bother with all that when you don't have to? Do it right and use the keyscript. If you are unsure how, no problem. We'll help.

Second...

Releasekeys is not a native OpenBOR script function. If you copied that from somewhere, it was a custom function the author wrote. Doesn't matter anyway, since if you take my advice and move your concept into a keyscript the event is handled by proxy.

Give me long enough to get to my office and I'll write a quickie function to do the run stop. I need one myself anyway.

DC

That makes so much sense Damon Caskey , I understand what you mean in regards to using normal external scripts and the actual use of them in relation to what one requires (still learning from you guys about that :) ). If I am able to get this one it would actually be the first time any of my characters will be using a external script file as I was always daunted by the sheer amount of different external scripts :-X

I would really appreciate a script file that would enable this slow down/stop run ability :), whenever you have time, in the meantime I have got the animations ready. Thank you Damon Caskey
 
Glitch I use this on my Avengers United Battle Force game (in Tigra). it was using inline script, but then I've converted to external functions.

I have 3 functions to control it (goes into animationscript):

Code:
void runstart (void anim){
	// Execute a run stop animation
	// Thanks WhiteDragon
	void self = getlocalvar("self");
	if ( getentityvar(self,"running") == 1 ) {
		setentityvar(self,"running",NULL());
		performattack(self,openborconstant(anim),1);
		}	
}

void runset (){
	// Set run status
	// Thanks WhiteDragon
	void self = getlocalvar("self");
    setentityvar(self,"running",1);
}

void runstop(){
	// Reset runstop condition
	// Thanks WhiteDragon
	void self = getlocalvar("self");
	if ( getentityvar(self,"running") == 1 ) {
   	setentityvar(self,"running",NULL());
	}
}

On RUN animation, I set this:
anim run
delay 6
loop 1
offset 100 124
bbox 80 92 44 31
@cmd runset
frame data/chars/tigra/run00.gif
sound data/sounds/step.wav
frame data/chars/tigra/run01.gif
frame data/chars/tigra/run02.gif

On IDLE animation, I use this function to make her go to FOLLOW3 animation (which is my run stop animation)
anim idle
loop 1
offset 100 124
bbox 88 71 24 54
delay 16
@cmd runstart "ANI_FOLLOW3"
frame data/chars/tigra/stand00.gif
frame data/chars/tigra/stand01.gif
frame data/chars/tigra/stand02.gif
frame data/chars/tigra/stand01.gif

Then I set this last function on the animations she can use but aren't the idle animation. Not on all animation, but on the ones she can use without passing through the idle, like riseattack
anim jump
loop 0
delay 8
dropframe 2
offset 100 124
bbox 84 56 33 36
cancel 0 9 0 d f a freespecial13
@cmd runstop
frame data/chars/tigra/jump00.gif

Probably, there should be a better way to do it. But its working now - maybe I will change this on the future.
 
O Ilusionista said:
Glitch I use this on my Avengers United Battle Force game (in Tigra). it was using inline script, but then I've converted to external functions.

I have 3 functions to control it (goes into animationscript):

Code:
void runstart (void anim){
	// Execute a run stop animation
	// Thanks WhiteDragon
	void self = getlocalvar("self");
	if ( getentityvar(self,"running") == 1 ) {
		setentityvar(self,"running",NULL());
		performattack(self,openborconstant(anim),1);
		}	
}

void runset (){
	// Set run status
	// Thanks WhiteDragon
	void self = getlocalvar("self");
    setentityvar(self,"running",1);
}

void runstop(){
	// Reset runstop condition
	// Thanks WhiteDragon
	void self = getlocalvar("self");
	if ( getentityvar(self,"running") == 1 ) {
   	setentityvar(self,"running",NULL());
	}
}

On RUN animation, I set this:
anim run
delay 6
loop 1
offset 100 124
bbox 80 92 44 31
@cmd runset
frame data/chars/tigra/run00.gif
sound data/sounds/step.wav
frame data/chars/tigra/run01.gif
frame data/chars/tigra/run02.gif

On IDLE animation, I use this function to make her go to FOLLOW3 animation (which is my run stop animation)
anim idle
loop 1
offset 100 124
bbox 88 71 24 54
delay 16
@cmd runstart "ANI_FOLLOW3"
frame data/chars/tigra/stand00.gif
frame data/chars/tigra/stand01.gif
frame data/chars/tigra/stand02.gif
frame data/chars/tigra/stand01.gif

Then I set this last function on the animations she can use but aren't the idle animation. Not on all animation, but on the ones she can use without passing through the idle, like riseattack
anim jump
loop 0
delay 8
dropframe 2
offset 100 124
bbox 84 56 33 36
cancel 0 9 0 d f a freespecial13
@cmd runstop
frame data/chars/tigra/jump00.gif

Probably, there should be a better way to do it. But its working now - maybe I will change this on the future.

That looks exactly like what I need, I have a slow down animation and a stop full to turn around (if back is pressed while running), thank you so much Ilu :) .
I will copy this script play with it tomorrow, and maybe if  DC has another one I can combine both (don't want to get to ahead and confuse myself though lol :o)
 
It is working just as required , thank you O Ilusionista & White Dragon . It even works with my cancel to ''slow down and stop run then turn around'' animation when back key is pressed while running.

Just one small issue (though as it is perfect):

I use the @cmd runstop after the run in the (cancel) freespecial attacks, but after playing freespecial and if I am still holding forward button, the character continues to run again (luckily it plays the run anim from beginning which has character starting to run frames).

How would I switch off run after playing a cancel from run?

As it is perfect though, in real life after running and performing a lunge punch (or other run momentum attacks) a person can then start running again...but their stamina would reduce exponentially ... maybe I should leave it as is and have a small energycost for running animation itself?. What do you guys think?

 
Ah, I had the same issue with Brand on my project.
Looks like when you are on the running animation and use CANCEL, the engine doesn't update the "running" flag.
(When you run, there is an internal flag called "running" which is set to 1).

I forgot to report it, but there is a quick solution for that:
Code:
changeentityproperty(self, "aiflag", "running", 0);

You can use a short inline version as this:
Code:
@cmd changeentityproperty getlocalvar("self") "aiflag" "running" 0
(I haven't tried this short version, but it should work).

Edit: reported https://github.com/DCurrent/openbor/issues/100
 
I had the same idea to use the change property to put the running flag off :o , you beat me to it O Ilusionista

I inserted it into the script:

Code:
void runstart (void anim){
	// Execute a run stop animation
	// Thanks WhiteDragon
	void self = getlocalvar("self");
	if ( getentityvar(self,"running") == 1 ) {
		setentityvar(self,"running",NULL());
		performattack(self,openborconstant("ANI_FREESPECIAL56"),1);
		}	
}

void runset (){
	// Set run status
	// Thanks WhiteDragon
	void self = getlocalvar("self");
    setentityvar(self,"running",1);
}

void runstop(){
	// Reset runstop condition
	// Thanks WhiteDragon
	void self = getlocalvar("self");
	if ( getentityvar(self,"running") == 1 ) {
   	setentityvar(self,"running",NULL());
	changeentityproperty(self, "aiflag", "running", 0);
	}
}


Works excellently now, I made sure to put ''@cmd runstop'' in all the required animations


 
Back
Top Bottom