Ranged attacks

I'm looking for a way to simply have one of two attack animations play depending on range of enemy. I tried to do this using range but it displays whichever attack is the chain attack starter regardless of range and I can't seem to find the actual script for this outside of the @cmd part of it. If anyone knows of a way to accomplish this please share or if you know what script I should use please share also
 
I was told that the script I'm trying to use is outdated so could anyone suggest a method with or without using script or atleast tell what section to check because everything I find that is about range hasn't worked. I'm just trying to have the jab animation play if they are atleast 60 pixels away or the elbow if they're close enough thats all nothing complex i've been looking for days now with no luck so any help or suggestions or guesses is appreciated
 
the range command does not serve?

range {min} {max}

~Used for AI controlled entities' attacks and jump. Usually used by enemy, NPC and homing projectile.
~This command lets the entities know when to perform their attacks or to jump on platforms.
~For the entity to use the attack, its opponent must be more than {min} away, but less than {max} away in x axis.
~Entity's opponent is determined by 'hostile' setting (see Header Data above).
~For the enemy to jump on a platform, the enemy must be within {min} pixels of the platform, and the platform must be less than {max} pixels high.
~This is measured in pixels, starting at the entity's offset point and moving towards the opponent's offset.
~If not included, the first number will default to -10, and the second to 20 times the entity's jumpheight variable.
~For homing projectiles, this determines their targeting range.
~If this command is declared together with 'rangez' and/or 'rangea', opponent's location must be within ALL of them before attack animation is performed.
~Default 'range' for ATTACK{#} is 0 75, for JUMPATTACK and JUMPATTACK2 is 0 150, for UPPER -10 120 and for BLOCK is 1 100. The last one only has effect if enemy uses 'nopassiveblock'.

rangez {min} {max}

~This command works similar with 'range' (see above) except that it works in z axis instead.
~Default values for {min} and {max} are '-grabdistance/3' and 'grabdistance/3' respectively.
~If this command is declared together with 'range' and/or 'rangea', opponent's location must be within ALL of them before attack animation is performed.

rangea {min} {max}

~This command works similar with 'range' (see above) except that it works in y axis or altitude instead.
~Default values for {min} and {max} are -1000 and 1000 respectively.
~If this command is declared together with 'range' and/or 'rangez', opponent's location must be within ALL of them before attack animation is performed.

rangeb {min} {max}

~This command works similar with 'range' (see above) except that it works in y axis and detects opponent's base instead.
~Unlike 'rangea', it only detects base instead of altitude. Opponent's altitude will be ignored.
~Default values for {min} and {max} are -1000 and 1000 respectively.
~If this command is declared together with other range commands above, opponent's location must be within ALL of them before attack animation is performed.
 
For some reason range is not being acknowledged for the second combo set 1 2 3 4 5 0 6 4 5 i want attack 6 to happen when enemies are a min of 60 but no matter how far they are attack1 is the animation used and apparently no one can offer insight on this
 
Please tell me if you see anything that would prevent attack6 from activating at the designated range because I can't find any reason this is not working

Code:
name Leonardo
type player
health  230
gfxshadow	1
speed   13
riseinv 1
grabdistance 40
throw  6 3
jumpheight 5.8
jumpspeed 34
jumpmove   3  3
atchain    1  2 3 4 5 0 6 4 5
running 30  5.5  1.3 1  1
combostyle 1
com D F A freespecial




palette    data/chars/leonardo/alt.png





anim	attack1
	delay	12
	attack	139 62 33 38 7 0 1 0 7 0
	bbox	116 64 26 78
	offset	125 149
	frame	data/chars/leonardo/attack/00.png
		
anim	attack2
	delay	10
	range	0 50
	bbox	106 64 35 82
	offset	127 149
	frame	data/chars/leonardo/kick/2/00.png
	delay	12
	attack	132 99 49 45 7 0 1 0 8 0
	frame	data/chars/leonardo/kick/2/01.png
		
anim	attack3
	delay	9
	range	60 80
	bbox	102 63 34 79
	offset	126 148
	frame	data/chars/leonardo/kick/1/00.png
	attack	151 77 37 55 7 0 1 0 9 0
	delay	12
	frame	data/chars/leonardo/kick/1/01.png
	delay	9
	frame	data/chars/leonardo/get/00.png
		
anim	attack4
	delay	9
	range	60 80
	bbox	92 62 40 84
	offset	130 147
	frame	data/chars/leonardo/kick/4/00.png
	attack	130 53 51 75 8 0 1 0 9 0
	delay	10
	frame	data/chars/leonardo/kick/4/01.png
	delay	9
	frame	data/chars/leonardo/get/00.png
		
anim	attack5
	fastattack	1
	delay	8
	range	80 140
	bbox	92 69 42 76
	offset	106 148
	frame	data/chars/leonardo/attack/2/00.png
	delay	8
	frame	data/chars/leonardo/attack/2/01.png
	delay	12
	attack	153 68 68 81 12 2 1 1 10 9
	frame	data/chars/leonardo/attack/2/02.png
		
anim	attack6
	loop	0
	rangea	0 330
	range	60 330
	delay	9
	attack	149 67 71 35 7 0 0 1 7 9
	bbox	114 66 26 79
	offset	123 150
	frame	data/chars/leonardo/attack/01.png
		
anim	fall
	delay	10
	offset	116 163
	frame	data/chars/leonardo/fall/00.png
	delay	10
	frame	data/chars/leonardo/fall/01.png
	delay	10
	offset	108 166
	frame	data/chars/leonardo/fall/02.png
	delay	15
	offset	116 153
	frame	data/chars/leonardo/fall/03.png
		
anim	freespecial
	loop	0
	delay	3
	bbox	111 58 21 89
	offset	123 148
	frame	data/chars/leonardo/special/2/00.png
	loop	0
	delay	3
	frame	data/chars/leonardo/special/2/01.png
	loop	0
	delay	3
	attack	39 55 171 34 15 1 1 0 6 15
	frame	data/chars/leonardo/special/2/02.png
	loop	0
	delay	3
	attack	0 0 0 0 0 0 0 0 0 0
	frame	data/chars/leonardo/special/2/03.png
	loop	0
	delay	3
	frame	data/chars/leonardo/special/2/04.png
	loop	0
	delay	3
	frame	data/chars/leonardo/special/2/05.png
	loop	0
	delay	3
	attack	44 54 159 40 13 1 1 0 6 15
	frame	data/chars/leonardo/special/2/06.png
	loop	0
	delay	3
	attack	0 0 0 0 0 0 0 0 0 0
	frame	data/chars/leonardo/special/2/07.png
	loop	0
	delay	3
	frame	data/chars/leonardo/special/2/00.png
	loop	0
	delay	3
	frame	data/chars/leonardo/special/2/01.png
	loop	0
	delay	3
	attack	42 58 156 37 13 1 1 0 6 15
	frame	data/chars/leonardo/special/2/02.png
	loop	0
	delay	3
	attack	0 0 0 0 0 0 0 0 0 0
	frame	data/chars/leonardo/special/2/03.png
	loop	0
	delay	3
	frame	data/chars/leonardo/special/2/04.png
	loop	0
	delay	3
	frame	data/chars/leonardo/special/2/05.png
	loop	0
	delay	3
	attack	42 57 156 38 13 1 1 0 6 15
	frame	data/chars/leonardo/special/2/06.png
	loop	0
	delay	3
	attack	0 0 0 0 0 0 0 0 0 0
	frame	data/chars/leonardo/special/2/07.png
	loop	0
	delay	9
	frame	data/chars/leonardo/get/00.png
		
anim	grab
	loop	0
	offset	121 149
	frame	data/chars/leonardo/00.png
		
anim	idle
	delay	12
	bbox	101 72 35 73
	offset	119 149
	frame	data/chars/leonardo/idle/00.png
	delay	12
	frame	data/chars/leonardo/idle/01.png
	loop	1
	delay	12
	frame	data/chars/leonardo/idle/02.png
		
anim	jump
	delay	7
	bbox	105 80 33 63
	offset	123 149
	frame	data/chars/leonardo/jump/00.png
	delay	9
	frame	data/chars/leonardo/jump/01.png
	delay	15
	frame	data/chars/leonardo/jump/02.png
	delay	9
	frame	data/chars/leonardo/jump/03.png
		
anim	pain
	delay	12
	bbox	101 74 29 70
	offset	119 151
	frame	data/chars/leonardo/pain/00.png
	delay	20
	frame	data/chars/leonardo/pain/01.png
		
anim	rise
	delay	15
	offset	122 150
	frame	data/chars/leonardo/fall/03.png
	delay	20
	frame	data/chars/leonardo/get/01.png
	delay	25
	frame	data/chars/leonardo/get/00.png
		
anim	run
	delay	10
	bbox	56 83 28 77
	offset	76 162
	frame	data/chars/Michelangelo/run/00.png
	delay	10
	frame	data/chars/Michelangelo/run/01.png
	delay	10
	frame	data/chars/Michelangelo/run/02.png
	delay	10
	frame	data/chars/Michelangelo/run/03.png
	loop	1
	delay	10
	frame	data/chars/Michelangelo/run/04.png
		
anim	runattack
	delay	9
	bbox	101 72 41 72
	offset	121 150
	frame	data/chars/leonardo/attack/1/00.png
	delay	7
	frame	data/chars/leonardo/attack/1/02.png
	delay	7
	move	25
	frame	data/chars/leonardo/attack/1/03.png
	attack	173 80 74 57 10 2 1 0 0 0
	delay	9
	move	0
	frame	data/chars/leonardo/attack/1/04.png
	delay	11
	frame	data/chars/leonardo/attack/1/00.png
		
anim	select
	delay	15
	offset	123 150
	frame	data/chars/leonardo/select/00.png
	delay	15
	frame	data/chars/leonardo/select//01.png
	delay	15
	frame	data/chars/leonardo/select/02.png
	delay	20
	frame	data/chars/leonardo/select/03.png
	delay	20
	frame	data/chars/leonardo/select/04.png
	delay	20
	frame	data/chars/leonardo/select/05.png
	delay	20
	frame	data/chars/leonardo/select/06.png
	delay	20
	frame	data/chars/leonardo/attack/1/00.png
		
anim	throw
	delay	7
	offset	122 150
	frame	data/chars/leonardo/slam/00.png
	delay	7
	frame	data/chars/leonardo/slam/01.png
	delay	7
	frame	data/chars/leonardo/slam/02.png
	delay	7
	frame	data/chars/leonardo/slam/03.png
	delay	10
	frame	data/chars/leonardo/get/00.png
		
anim	waiting
	delay	15
	offset	124 150
	frame	data/chars/leonardo/select/00.png
	delay	15
	frame	data/chars/leonardo/select/01.png
	loop	1
	delay	15
	frame	data/chars/leonardo/select/02.png
		
anim	walk
	delay	15
	bbox	107 71 28 68
	offset	122 148
	frame	data/chars/leonardo/walk/00.png
	delay	15
	frame	data/chars/leonardo/walk/01.png
	delay	15
	frame	data/chars/leonardo/walk/02.png
	delay	15
	frame	data/chars/leonardo/walk/03.png
	loop	1
	delay	15
	frame	data/chars/leonardo/walk/04.png
		
#|edited by openBor Stats v 0.67
 
I'll try to give you some help with my basic knowledge of Openbor.

-First, what is the meaning of "0" in your atchain combo?

-2nd 0 is not a correct value AFAIK, It might be the reason attack6 never happens.

Hope it helps.
 
Use the Combostyle setting to enable advanced mode for Atchain.
With advanced use of Atchain, you may enter up to twelve attacks in the sequence. In addition, alternate chains can be enabled based upon range to the target using 0 as a divider.

I know its possible because hawkeye can do this in mfa2 by zvitor

Thanks for the response
 
I know what he means, I asked about this a while back on lavalit and never solved it either.

for example -

If char is at normal distance he will use punch
image.png


if he is close range he will use elbow
image.png
 
There's an entry in the wiki about atchain.

BeasTie said:
I know what he means, I asked about this a while back on lavalit and never solved it either.

for example -

If char is at normal distance he will use punch
image.png


if he is close range he will use elbow
image.png

As for this, the simplest thing to do is a range based script. In the first frame of one animation, look to see if there is a hostile target in range of the alternate animation. If yes, then switch to the alternate. It's simpler than it sounds and there are examples all over the place. It won't even mess up an attack chain.

This is the function you will need, and it's tailor made to do the job:

Code:
entity = findtarget({owner}, {animation});

Returns first hostile entity in range of {animation}.

{owner}: Required. Entity performing search. Usually self.
{animation}: Optional animation constant. If omitted, {owner's} current animation is used instead.

DC
 
I found this script but I'm not sure how to word the cmd in the text file. @cmd ani0020  "ANI_Attack6" isn't working do I need to add more or am I simply writing it wrong because openbor crashes when I try it this way and press attack and every other way I've worded it openbor crashes before even loading.

Code:
int ani0020(int iAni, int iTAni){
    
	/*
	ani0020
	Damon Vaughn Caskey
	Perform alternate animation if target is within range and in specified animation.

	iAni:	Alternate attack.
	iTAni:	Target animation.
	*/

    void vSelf      = getlocalvar("self");					//Caller.                                                         
    void vOpp       = findtarget(vSelf, iAni);				//Nearest target in range of alternate attack.
	
	if (vOpp)												//Found a target?
	{
		if(getentityproperty(vOpp, "animationID") == iTAni)	//Animation match?
		{
			ani0009(vSelf, iAni, 0);						//Perform alternate attack.
			return 1;										//Return 1.
		}
	}

	return 0;												//Return 0.
}
 
Thegr8test said:
I found this script but I'm not sure how to word the cmd in the text file. @cmd ani0020  "ANI_Attack6" isn't working do I need to add more or am I simply writing it wrong because openbor crashes when I try it this way and press attack and every other way I've worded it openbor crashes before even loading.

BeasTie said:
@Damon Caskey - We we're talking about this script ani0020, I think thegreatest changed his original post.

For that function to work, you need to pass the animation constant, not a text name. You are also forgetting to add all the parameters. Lastly, that function happens to depend on another function (ani009).

In any case, here's a script that contains an updated version of both; it should have everything you need. Put it into a file, include it in your animation script and unless I made some typos you'll be good to go. Notice the use of #defined constants. Constants in an animation script also work in the model's text file. This is an extremely powerful feature that will help keep things organized.

Code:
#define FALSE	0	// False value.
#define TRUE	1	// True value.
#define DEFAULT	NULL()	// No parameter value - fall back to a default.

/******Animation, adjustment flags*****/
#define ANI_BY_CHANGE_PROP	0	// Set animation using "changentityproperty".
#define ANI_BY_PERFORM_ATTACK	1	// Set animation using "performattack".
#define ANI_RESET_FALSE		0	// Performattack will do nothing if new animation = current.
#define ANI_RESET_TRUE		1	// Performattack will reset animation to first frame if new animation = current.

int ani_set_animation(void ent, int animation, int method, int reset)
{
	/*
	ani_set_animation
	Damon Vaughn Caskey
	2013-11-03

	Animation switch wrapper. Verify animation exists and then set using desired method. Replaces ani0009.

	vEnt:		Target entity.
	animation:	Animation to use.
	method:		Method to set animation. See Animation, adjustment flags in constants.h for flag list.
	*/

	int valid = FALSE;		// Requested animation valid.

	// Default for any omitted values.
	if(ent == DEFAULT) ent = getlocalvar("self");
	if(method == DEFAULT) method = ANI_BY_CHANGE_PROP;
	if(reset == DEFAULT) reset = ANI_RESET_FALSE;

	valid = getentityproperty(ent, "animvalid", animation);

	// Is requested animation valid?
	if (valid == TRUE)			
    	{
		switch (method)
		{
			// Set animation with entity property.
			default:			
			case ANI_BY_CHANGE_PROP:

				changeentityproperty(ent, "animation", animation);	
				break;

			// Set animation with perform attack command.
			case ANI_BY_PERFORM_ATTACK:

				performattack(ent, animation, reset);				
				break;
		}
    	}
    
	// Return valid as a result.
	return valid;
}

int ani_set_on_range(void ent, int alternate, int target_ani){
    
	/*
	ani_set_on_range
	Damon Vaughn Caskey
	2014-07-24

	Perform alternate animation if target is within range and in (optionaly) in specified animation.

	ent:		Entity that will switch animations. If NULL will default to caller.
	alternate:	Alternate attack.
	target_ani:	Target animation.	
	*/

	int  result		= NULL();	// Result of function. 
    	void target		= NULL();	// Target entity.
	void target_ani_current	= NULL();	// Target entity's current animation.

	// Default to caller if ent is not provided.
	if(ent == DEFAULT) ent = getlocalvar("self");
	 
	
	// Find target (if any) in range of specified animation.
	target = findtarget(ent, alternate);
	
	// Found a target?
	if (target)												
	{
		// Get target's current animation.
		target_ani_current = getentityproperty(target, "animationID");

		// Animation match or omitted?
		if(target_ani_current == target_ani || target_ani == DEFAULT)
		{
			// Perform alternate attack.
			result = ani_set_animation(ent, alternate, ANI_BY_CHANGE_PROP);					
		}
	}

	// Return result.
	return result;
}

Now in your model text you can do something like this:

Code:
anim WHATEVER

		# Switch to Whatever2 if target is in range of it.
		@cmd ani_set_on_range DEFAULT openborconstant("WHATEVER2") DEFAULT
	frame data/chars/dude/0001.png
	frame data/chars/dude/0002.png
	frame data/chars/dude/0003.png
	frame data/chars/dude/0004.png

anim WHATEVER2

	# Can't forget a range setting.
	range 0 20

	frame data/chars/dude/0005.png
	frame data/chars/dude/0006.png
	frame data/chars/dude/0007.png
	frame data/chars/dude/0008.png

Now anytime there is a hostile target in range of WHATEVER2, it will play in place of WHATEVER.

HTH,
DC

 
Back
Top Bottom