Like an assassinating or backstabbing character events. Does anyone have an idea or is it possible by just eventing it?
Detect if player is interacting event from behind?
RPG Maker VXAce SupportGo to Events, then in the 1st tab under Flow Control, go to Conditional Branch. After that, go to the 3rd tab of Conditionl Branch where you can check whether an event/player is facing by going to "Characters."
You would simply check if both are facing the same direction.
You would simply check if both are facing the same direction.
I don't remember if there was a scripted solution already available here, but here's my take on the issue.
Ruby:
class Game_Interpreter
def behind_event?(event_id)
event = $game_map.events[event_id]
return nil if $game_player.direction != event.direction
if $game_player.y == event.y
distance = $game_player.x - event.x
return distance == 1 if player_dir == 4
return distance == -1 if player_dir == 6
elsif $game_player.x == event.x
distance = $game_player.y - event.y
return distance == 1 if player_dir == 2
return distance == -1 if player_dir == 8
end
nil
end
end
This wouldn't work if the event in question is behind the player character.
I feel this Himeworks script can help you out.
Okay, if I want to do this with pure basic eventing, I would do it like this:
Make 4 variables:
And make 1 switch:
Now event
Make 4 variables:
- Event location X (EX)
- Event location Y (EY)
- Player location X (PX)
- Player location Y (PY)
And make 1 switch:
- From Behind (FB.)
Now event
- If EX < PX
- Is event is looking left
- Turn on FB
- Else
- Turn off FB
- end
- Is event is looking left
- end
- If EY < PY
- Is event is looking up
- Turn on FB
- Else
- Turn off FB
- end
- Is event is looking up
- end
- If EX > PX
- Is event is looking up
- Turn on FB
- Else
- Turn off FB
- end
- Is event is looking up
- end
- If EY > PY
- Is event is looking down
- Turn on FB
- Else
- Turn off FB
- end
- Is event is looking down
- end
- If FB = on
- Event what happens when behind
- Else
- Event what happens when not behind
- End
It would still work. To interact with the event, you have to be facing it which means the event has to be facing away from you at the same time.
What you're saying would be correct only if we were calculating distances because then that would matter.
@NoPiessadface
There is also this guide I made on this site: https://forums.rpgmakerweb.com/index.php?threads/proximity-distance-check.79791/
Oh wow... I just saw your solution, and it is soooo much quicker than mine. I could have saved myself 30 minutes of my weekend if I just saw it before I wrote that whole thing. 😛 Haha. But yours only works if the player must look at the target, which makes a lot of sense since it is a direct attack from behind.
My solution is more suitable if you want to be hidden in general, attack or no attack.
While I write this, I get an idea how I will use this myself in a quest where the player has to shadow a NPC, so I didn't write it all for nothing.
@OP, If you only use it for sneak attacks, forget my solution. Vectra's does exactly what you want. 😛
As Lord Vectra pointed out, in order to interact with the event in the first place, your distance from it is already known information: the only variable that needs to be checked is whether the event and player are facing the same way at the time.
There is actually something I missed. @kyonides @Trihan @JohnDoeNews
If you interact with the event, the event faces you (as default by the game) and setting a move route to direction fix in the event page won't fix it, so the direction needs to somehow be fixed prior to doing the backstab.
This is important because, in that case, none of our solutions actually work. it dawned on me just now that events do that. I will edit my post with the solution, but I wanted to say that right now before I left.
If you interact with the event, the event faces you (as default by the game) and setting a move route to direction fix in the event page won't fix it, so the direction needs to somehow be fixed prior to doing the backstab.
This is important because, in that case, none of our solutions actually work. it dawned on me just now that events do that. I will edit my post with the solution, but I wanted to say that right now before I left.
Oh yes, you should not trigger this by "player touch" or "action button". This should be controlled by an external event. This is required for the ranged attacks anyway. (Like a common event triggered by a sneak attack skill)
Your solution still works.
Your solution still works.
If it's controlled by an external event, then you do need the distance/proximity check because then we (or the program) won't know where the player and event is at for the purpose of the sneak attack skill. But you are correct that the "conditional branch on both facing the same direction" is still the same... kind of.
Because you could be facing right and the event also facing right behind you, so it requires a bit more finesse which the OP will find in my guide i have on this site in the comment I mentioned him in.
I think you've forgotten that you could still be standing right quite close to the event and looking in the same direction while not being right behind it but in front of it instead. Thus, the direction alone isn't a helpful method here.
The real issue is the event automatically turning around based on the trigger people choose there.
Your right. So, when controlled by an external event, you still need to take the long way I proposed.
When you use my method, you already have the X and Y values of both the player and the enemy. Subtract them from each other and you have the distance in tiles.
So I guess it was too quick to admit that your solution was better than mine. Sorry man, might have to take that back. 😛
This was for the case where the event is "action key", to clarify.
Original thread: https://forums.rpgmakerweb.com/threads/detect-if-player-is-interacting-event-from-behind.153037/