Making a guard vulnerable only from behind

Hi,

in my game guards are roaming around with a "cone of vision". As soon as the player steps into the cone (=is seen by the guard) the game is over. I did this with the help of the Plugin OcRam_lights and it works 🙂 https://ocram-codes.net

◆Comment:<light:1:600:#ff0000:360>
:Comment:<light-ex:0,24:90:0:0>
◆If:Script:this.event().isPlayerInLightRadius()
◆Show Balloon Icon:This Event, Exclamation
◆Play SE:Load2 (90, 100, 0)
◆Text:None, None, Window, Bottom
:Text:Got you!
◆Game Over
◆
:End

Now I want to give the player an opportunity to knock guards out, simply by approaching them from behind and press the enter button.

I'm facing two problems now:

1. Roaming around with the cone of vision is a parallel event. But I want that there is a action-button-trigger too (to trigger the knocking-out, if the player "talks" to the guard)

2. I can't find a way to make the knocking-out only trigger-able from behind 🙁 Is there a way to make a event only trigger-able from one specific direction? I know that there is condition to make it depending of the direction of the player, but since the guard is running around that's not a option for me 🙁

Can anybody help me with that? 🙂

Thanks so much
You can't change how an event triggers, but you can put what it does inside a conditional branch so the code will only be executed if the direction portion is correct.

There was just a thread yesterday asking about triggering events if they touch the front, and a JavaScript conditional was given for it. Take a look at that, see how the direction checking works.

I don't immediately have any suggestions on how to give the event a parallel process and also allow for an interaction trigger.
you can try something like this to add it:
its from a sneak attack from behind.

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
you can try something like this to add it:
its from a sneak attack from behind.

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
Ah, that's awesome, this is a really nice idea.
It works. But now I still have the problem that I can't let the guards walk around and search you at the same time :-/
if you catch the NPC, that is where you can knock him out,
otherwise, you are in the light can they catch you 🙂

this is just a simple basic setup with the action button 🙂 so you need
to play around how exacly the attack is done or how to knowck him out
if it has the item to do so, or stun him for x seconds 🙂

EDIT: HIME has [Event rigger Labels] which might works in parallels events.
but I cannot tell for sure, while I use it for a specific complex event that
I need it in order to work 🙂

so you can puzzle around to make it work the way you like 🙂
Stupid workaround idea:
have an invisible event set to the lower layer, with an interact on buttonpress. These events always trigger when the player is standing on them, rather when the player is next to them.

in its moveroute, tell it to teleport to the tile behind the guard, on loop. ( this.setPosition(x,y) or this.locate(x,y) or whatever)

have the invisible event do your sneaking up behind guard logic.
thanks, I had something like this in mind too, but I didn't know how I could make the invisible event always follow the guard.

I will try the different solutions later and let you know what worked best for me 🙂
Stupid workaround idea:
have an invisible event set to the lower layer, with an interact on buttonpress. These events always trigger when the player is standing on them, rather when the player is next to them.

in its moveroute, tell it to teleport to the tile behind the guard, on loop. ( this.setPosition(x,y) or this.locate(x,y) or whatever)

have the invisible event do your sneaking up behind guard logic.

hm, so I tried it and so far it doesn't really work.
I set the guard on "parallel" and set 2 variables for the position

◆Control Variables:#0006 Guard1X = Map X of This Event
◆Control Variables:#0007 Guard1Y = Map Y of This Event

Then I set the autonomous movement of the invisible event an "costom", clicked on route and then "script". There I wrote "this.setPosition(Guard1X, Guard1Y)" (I also tried this.setPosition({Guard1X}, {Guard1Y}), because I'm not sure about the syntax here). In both cases I get an error as soon as I start the game: "Guard1X not defined".

I believe it's basically just a syntax-error, because imho this should work 😀 Am I using the right syntax for the variables?

EDIT: Ah, I found some learning material from Draftwood Gaming on YT, now it is working.

What I wrote now in the movement script is

this.setPosition($gameVariables.value(6),$gameVariables.value(7))

Are there any suggestions for learning material for the JavaScript stuff in RMMZ? 🙂
I'm glad it's working 🙂

Writing javascript is very similar between MZ and MV. Most of the things you have to call in the engine are unchanged, or are at least pretty similar (that's why fossil is possible as a project). The MV script call list mostly works in MZ, and is a fantastic resource.
2) Can't you check the direction of the player AND the guard in a conditional branch? If you caught the guard behind both are facing the same direction. If you catch it from the side there is no way you're facing the same way.

1) There should be a conditional branch to see if the player has pressed the action button.
You can simply use it with the point above and another condition to check if the player is within the guard "$gameMap.distance(x1, y1, x2, y2)" <- This one is for MV, i'm still newbie with MZ so i don't know if it's the same
Can't you check the direction of the player AND the guard in a conditional branch?
No, because by the time the first event command runs, the event has already turned around to face the player.

Original thread: https://forums.rpgmakerweb.com/threads/making-a-guard-vulnerable-only-from-behind.135871/