Solved a question about off-screen attacks

Question that is answered or resolved.

Matute2175

New member
hello people, I have a question: I want some enemies to not be able to attack me from outside the screen, for this I can use offscreen_noatk_factor, but that affects all the attacks, and I need it to only affect one of their specific attacks (the typical ones throwing knives). How could I solve it? Thank you!!
 
Solution
I can't recall where or when I posted such function.
I decided to just code new one such as this:
C:
void offscreenoff(float dx)
{// Cancels attack if entity is offscreen
    void self = getlocalvar("self");
    int x = getentityproperty(self,"x"); //Get character's x coordinate
    int XPos = openborvariant("xpos"); //Get screen edge's position
    int Screen = openborvariant("hResolution"); // Get screen width

    if(x > XPos + Screen + dx){ // Offscreen to the right?
      setidle(self, openborconstant("ANI_IDLE"));
    } else if(x < XPos - dx){ // Offscreen to the left?
      setidle(self, openborconstant("ANI_IDLE"));
    }
}

Ex: @cmd offscreenoff 50 will make enemy cancels his/her/its attack if the enemy is 50 pixels...
For something that granular, you'll need to write a script that disables specific attacks while off-screen. The quick and dirty way is to build a function that forces model back to idle state & animation whenever entity is off-screen. Then call that function on first frame of the attacks you want disabled. I say quick and dirty because there would be a 1 frame stutter as entity tries attack and immediately reverts to idle. Not a big deal though, since it's off-screen and would be nearly imperceptible even if you could see it.

IIRC @Bloodbane already has an off-screen disalbe posted somewhere, so you might be able to save a few moments searching around first.

DC
 
I can't recall where or when I posted such function.
I decided to just code new one such as this:
C:
void offscreenoff(float dx)
{// Cancels attack if entity is offscreen
    void self = getlocalvar("self");
    int x = getentityproperty(self,"x"); //Get character's x coordinate
    int XPos = openborvariant("xpos"); //Get screen edge's position
    int Screen = openborvariant("hResolution"); // Get screen width

    if(x > XPos + Screen + dx){ // Offscreen to the right?
      setidle(self, openborconstant("ANI_IDLE"));
    } else if(x < XPos - dx){ // Offscreen to the left?
      setidle(self, openborconstant("ANI_IDLE"));
    }
}

Ex: @cmd offscreenoff 50 will make enemy cancels his/her/its attack if the enemy is 50 pixels offscreen.
 
Last edited by a moderator:
Solution
Back
Top Bottom