Sneak attack (walking up behind an NPC and knocking them out)

Is there a way to change what action happens when approaching an NPC if you click the NPC while it is not facing you? I am interested in doing a stealth area in a game where you have to sneak up behind the enemy and "knock them out."

This would also mean somehow making it so that any time you are directly in front of the NPC (or at least a few blocks in front of the NPC) then the NPC "catches you."

If the NPC were stationary this would be easy, but having the NPC walk a patrol where you have to navigate around its view and get up behind it to "knock it out" seems like it may be difficult.
yes-ish.
there is a direction property you could tap into, but I don't remember how that is processed when the event moves.

either way, it'll still require a script call to grab that property... but how big of a script call to a point where it'd become a plugin? IDK
stationary turn is simple:

moveroute -> turn right, wait x, turn down, wait x, turn left, wait x, turn up, wait x, repeat

as for condition branch, beats me, but I like the idea though.
Yep has a stealth plugin, but there is also a selfswitch sensor with range ability.
but no idea how to attack from the back only and not the sides.
To do this without a plugin would require a few variables that are in parallel processing.
Players X, Players Y, Event X, Event Y, Player Direction, Event Direction. With this, you could set up which switch is flipped depending on which direction the player and event are to each other. Example: If player is "behind" event (depending on which direction the event is facing), on action press turn event self switch to b,c,d...whichever is you need/want.
I tried something :

I made an event as "action press"

With the following commands :

Variable 1 = Player direction
Variable 2 = Event direction
Condition : Variable 1 == Variable 2
=> You got me !
Else
=> Catch !
End

If both directions are the same, it means you are on its back (if you are in front or side by side, you can't activate with action press)

Problem :
When you start the event, it looks at you ...
Aaaaaaand it messed up all

Spoiler: Problem and solution on VX ace
So I added a little thing to the Characters (events, player, follower ...)
A little script that makes an already existing variable usable
This variable keep in memory the direction before you start the event

So with this script :

Ruby:
class Game_CharacterBase
  attr_reader   :prelock_direction
end

You can get the pre-lock direction with the command
Ruby:
get_character(0).prelock_direction

get_character(0) is the interpreter way to use an event.

catch.png


Now, if I activate the event and we were both looking the same direction before, the condition is valid.
If we were not looking the same direction, he catch me


NOW the thing is to do that for MV, so I will check that
But it's surely possible
I just don't know MV well, so it may take time

Here is the solution for MV :
catch_mv.png


The line for the variable is :
Ruby:
this.character(0)._prelockDirection
Seems like we're close to solving this one. @hinola - I am using MV and do not speak Spanish, and also variables always confuse me, so I wasn't able to figure out exactly what you did, haha.
@JayIsrael it means, Variable 1 = event (event name)

variable 1 event = this.character(0)._prelockDirection
variable 2 player = Direction of player
if direction var1 = var 2
"you catch the npc"
else
"event catch you"
end

thats what is basicly said. while I dont know spanish as well.
But I speak english
The screenshot is in french
There is 8 words in french in the screen

I can't explain more that I did

You save directions in a variable (down = 2, left = 4, right = 6, top = 8, but you don't need to know that)
If both directions are the same, the events looks the same way
If you activate it, it means the event look the same direction, so you are in his back

If you got that to work, there is still the detections event to do, but only when the first step is finish, whatever the solution you take.
Okay - here is something for detection.


This plugin allows you to set an event that happens when your player is a certain number of blocks from the event - so even moving events, when the player is like, say, 4 blocks from the event, you can make it turn a switch.

So - if I can figure out how to set a variable so that it only detects when the event and the player are facing each other, then I do believe we will have the recipe for a stealth game where one can get the player to have to sneak behind a guard to knock them out or pick their pocket.

I feel like the pieces are all here, but I just need to be better at working variables.
Alright - figured out the direction variable thing and I have successfully made it so that a character can pick-pocket.
Still need to figure out a way to disable the event from turning to face the player any time it is interacted with, because otherwise it looks like the player has been captured pick-pocketing.

Trying to work in the event sensor plugin so that it can catch the player when the player is in front of it, but it won't sense the player when the player is behind it. .

Original thread: https://forums.rpgmakerweb.com/threads/sneak-attack-walking-up-behind-an-npc-and-knocking-them-out.120142/