Solved Limit attack subjet to screen

Question that is answered or resolved.

dantedevil

Well-known member
Y see the enemies with knifes some times throw the knife while they are located outside the screen.
Most often happens while the enemy recently is spawned out of the screen.
So I wanna know if possible create a way to the enemy only perform this attack, when he is into the screen.
 
Last edited:
Solution
No, here x is entity position so it's already set.

Code:
(x > xpos && x < xpos + rWidth)

is supposed to mean entity is on screen

so
Code:
!(x > xpos && x < xpos + rWidth)

is then supposed to mean not on screen.

I guess there might be a problem with rWidth.

replace this line :

Code:
int rWidth = openborvariant("viewportw");

with this line :

Code:
int rWidth = openborvariant("hResolution");
Should be possible with simple maths using :

- xpos = scroll x position openborvariant("xpos")
- rWidth = resolution width openborvariant("viewportw") I think
- x = enemy x position

if(x > xpos && x < xpos + rWidth) doAttack


And if you don't have a custom system to initiate attacks just use the hardcoded one and in your animation first frame cancel to idle if negation of the previous condition.
 
Thanks my friend!

I don't have a custom system to initiate attack, but i dont understand
how make this:

"cancel to idle if negation of the previous condition."

This is my animation, but no idea how create a cancel script using your previous condition.

Code:
anim attack2
	range	200 350
	loop	0
	delay	20
	offset	82 177
	bbox	58 80 42 99
        sound   data/sounds/sw1.wav
	frame	data/chars/bd3/throwk01.png
	delay	6
        sound   data/sounds/p2a.wav
	frame	data/chars/bd3/throwk02.png
	frame	data/chars/bd3/throwk03.png
	frame	data/chars/bd3/throwk04.png
        sound   data/sounds/knife.wav
	delay	4
	@cmd    shooter2 "knifer" 50 85 -1 4 0 0
	frame	data/chars/bd3/throwk05.png
	delay	60
	frame	data/chars/bd3/throwk05.png

 
Just put something like that at the top of this animation :

Code:
@script
void vSelf = getlocalvar("self");
if(! condition){
  setidle(vSelf);
}
@end_script

I let you replace condition with the matching variables given above.
 
Beastie once posted about this command which should be put in models.txt

offscreen_noatk_factor 1

It could stop enemies from attacking offscreen
I haven't tried it myself though
 
Bloodbane said:
Beastie once posted about this command which should be put in models.txt

offscreen_noatk_factor 1

It could stop enemies from attacking offscreen
I haven't tried it myself though

This seems to do exactly what dantedevil wants  :)
 
Sorry for the late, I just try and not work for me.

Here the error log:
Code:
Script error: data/chars/bd3/bd3.txt, line 26: Invalid function call or expression 'x' (in production 'postfix_expr2')

if(- xpos = scroll x position openborvariant("xpos")
                   ^



Script error: data/chars/bd3/bd3.txt, line 27: Invalid function call or expression 'width' (in production 'postfix_expr2')

- rWidth = resolution width openborvariant("viewportw") I think
                      ^



Script error: data/chars/bd3/bd3.txt, line 27: Invalid function call or expression 'think' (in production 'postfix_expr2')

- rWidth = resolution width openborvariant("viewportw") I think
                                                          ^



Script error: data/chars/bd3/bd3.txt, line 28: Invalid function call or expression 'x' (in production 'postfix_expr2')

- x = enemy x position
            ^


Script compile error in 'animationscript': xpos line 26, column 5

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

Can't compile script 'animationscript' data/chars/bd3/bd3.txt
Total Ram: 4294967295 Bytes
 Free Ram: 4294967295 Bytes
 Used Ram: 138858496 Bytes

Here the animation with the script:
Code:
anim attack2
	range	200 350
	loop	0
@script
void vSelf = getlocalvar("self");
if(- xpos = scroll x position openborvariant("xpos")
- rWidth = resolution width openborvariant("viewportw") I think
- x = enemy x position

if(x > xpos && x < xpos + rWidth) doAttack){
  setidle(vSelf);
}
@end_script
	delay	20
	offset	82 177
	bbox	58 80 42 99
        sound   data/sounds/sw1.wav
	frame	data/chars/bd3/throwk01.png
	delay	6
        sound   data/sounds/p2a.wav
	frame	data/chars/bd3/throwk02.png
	frame	data/chars/bd3/throwk03.png
	frame	data/chars/bd3/throwk04.png
        sound   data/sounds/knife.wav
	delay	4
	@cmd    shooter2 "knifer" 50 85 -1 4 0 0
	frame	data/chars/bd3/throwk05.png
	delay	60
	frame	data/chars/bd3/throwk05.png
 
Remove "i think", but still crash.

Code:
Script error: data/chars/bd3/bd3.txt, line 26: Invalid function call or expression 'x' (in production 'postfix_expr2')

if(- xpos = scroll x position openborvariant("xpos")
                   ^



Script error: data/chars/bd3/bd3.txt, line 27: Invalid function call or expression 'width' (in production 'postfix_expr2')

- rWidth = resolution width openborvariant("viewportw")
                      ^



Script error: data/chars/bd3/bd3.txt, line 28: Invalid function call or expression 'x' (in production 'postfix_expr2')

- x = enemy x position
            ^


Script compile error in 'animationscript': xpos line 26, column 5

********** An Error Occurred **********
*            Shutting Down            *
 
It was not ready to be compiled code that I posted, just suggestion on how to write it.

Here's ready to use code :

Code:
@script
	void vSelf = getlocalvar("self");
	int xpos = openborvariant("xpos");
	int rWidth = openborvariant("viewportw");
	int x = getentityproperty(vSelf, "x");

	if(! (x > xpos && x < xpos + rWidth)){
		setidle(vSelf);
	}
@end_script

You could also try setting

Code:
offscreen_noatk_factor 1

in models.txt, as suggested by BloodBane. But this command will have a global effect.
 
I need set x or something right?

Because if I use the script exactly how you give me, the enemy always goes to the idle anmation when perform the kinife attack.

I need set this part?

if(! (x > xpos && x < xpos + rWidth)){
setidle(vSelf);
 
No, here x is entity position so it's already set.

Code:
(x > xpos && x < xpos + rWidth)

is supposed to mean entity is on screen

so
Code:
!(x > xpos && x < xpos + rWidth)

is then supposed to mean not on screen.

I guess there might be a problem with rWidth.

replace this line :

Code:
int rWidth = openborvariant("viewportw");

with this line :

Code:
int rWidth = openborvariant("hResolution");
 
Solution
Back
Top Bottom