loop animation

msmalik681

OpenBOR Developer
Staff member
here is a animation script to loop a animation x amount of times before letting the animation continue. this is untested as I am getting ready for work let me know if there are any issues.

Code:
void loopFrame (int moveback, int limit)
{//fixed loop script by msmalik681
	void self = getlocalvar("self"); //get caller
	int frame = getentityproperty(self, "animpos"); //get current frame position
	int counter = getentityvar(self,"counter"); //get the counter.

	if(limit == NULL())
	{
	updateframe(self, frame - moveback);		
	}
	else 	if(counter < limit)
	{
	setentityvar(self,"counter", 1 + counter); // increment counter
	updateframe(self, frame-moveback); //move back to set frame
	}
	else { setentityvar(self,"counter", 0); } //reset loop counter
}

void loopOn ()
{
	void self = getlocalvar("self"); //get caller
	setentityvar(self,"counter", 0); // reset counter
}

void loopOff ()
{
	void self = getlocalvar("self"); //get caller
	setentityvar(self,"counter", NULL()); // null counter
}

so usage is simple just call the command then how many frames back you want to go from the called command then the limit before it continues the animation.  Remember to set the max mp as some point in the animation. if you leave the limit blank it will loop forever. remember to use "loopOn" at the start of the animation and "loopOff" at the end.

example:

Code:
anim idle
	loop	0
	delay	10
	offset	71 300
	bbox	27 33 108 256
@cmd  loopOn
	frame	data/chars/Hero/idle_00
	frame	data/chars/Hero/idle_01
	frame	data/chars/Hero/idle_02
	frame	data/chars/Hero/idle_03
@cmd loopFrame 3 30
#this will loop back to idle_01 30 times.
	frame	data/chars/Hero/idle_04
	frame	data/chars/Hero/idle_03
	frame	data/chars/Hero/idle_02
	frame	data/chars/Hero/idle_01
@cmd loopFrame 2
#this will loop back to idle_02 continuously.
@cmd loopOff
#it will never reach this command but you should have this at the end.
	frame	data/chars/Hero/idle_00
 
I don't want to be a wet blanket, but this is not really workable at all. I'd advise everyone not to use this script as written. There are several problems.

1. Using OpenBOR properties as variables is an old, OLD idea postulated by yours truly, and it was only for constant vlaues (like gender). Even then i wish I'd not done it. I wish I'd never done it. You have to be insanely careful to avoid conflicts.

2. As written, the script will only work one time. After the limit is reached, it won't ever work right again for that entity. You need set a localvar first and count backward.

I started to rewrite it in a gist for you, but keep getting pulled away. Just look at my points and you'll see what to do. :)

DC
 
Hello DC, :)

I am the guilty one here.
I asked Malik's help and he very gently accepted to make it for me.

Sorry for the inconvenient here. Please don't kill Malik, kill me instead :D
 
Damon Caskey said:
I'm not mad, lol... I just want to head you off before you go down a rabbit hole of bugs and issues. :)
It has been confirmed...DC is either the 'Mad Hatter' or the 'Queen of Hearts'
 
MadGear said:
Damon Caskey said:
I'm not mad, lol... I just want to head you off before you go down a rabbit hole of bugs and issues. :)
It has been confirmed...DC is either the 'Mad Hatter' or the 'Queen of Hearts'
:D !!! nice one...

Thanks DC for your concern and help :)
 
Just updated my script in the first post to use entity variables now.  And it was broken the first time sorry.

@DC
"Dont kill me kill Yota" lol  :D

I jumped down the rabbit hole and there was a party down there  8) but seriously I never experienced any bugs but I wont promote using entity properties again.
 
Back
Top Bottom