I have an NPC moving randomly. After the player interacts with it, i want the NPC to move to the end of the map and pretend to leave but since i don't know the position at which the NPC is at the end of the event, i can't set a manual route.
Any ideas?
You could have an invisible event set to "through" at the exit point and use the "moveTowardCharacter" function in a move route targeting that event to get the NPC there.
In the Variable OP Tab, you can assign the event's position to variables, which you can then use in IF Branches.
When your Event moves to the top or left, you just need to check whether the x or y variable is 1 (or zero, I'm not sure).
When your Event moves to the bottom or right, you can use this script in an IF branch: $gameVariables.value(X) >= $gameMap.width() || $gameVariables.value(Y) >= $gameMap.height() (Replace X / Y with the Variable ID)
Then it's up to you how you include this check in your Eventing.