Tsukihime 1,489 Posted May 18, 2012 (edited) Event Positions Author: Tsukihime Overview Often times you want to create event conditions for when the player leaves a particular tile. For example, if the player is standing on a push button, you want to check whether the player has left or not. This script provides extended position-tracking information, such as the last x,y position a character was on and the last region ID. Features Get the player's previous position and region Get an event's previous position and region Usage These are mainly for events. You can access position information by the standard $game_player.x $game_player.y $game_player.region_id $game_player.last_x $game_player.last_y $game_player.last_region_id $game_map.events[event_id].x $game_map.events[event_id].last_y You can also use some methods that make this easier player_pos player_last_pos event_pos(event_id) event_last_pos(event_id) These return a list of values corresponding to your position information player_pos ==> returns [x, y] player_last_pos ==> returns [last_x, last_y] The "last position" is updated whenever you successfully move to a new position. So if you're walking against a wall, your last position doesn't change (and it shouldn't cause you haven't moved yet). Example Suppose you really were making a push-button which is activated when you stand on it, and deactivated when you leave. Actually, you don't need this script for it lol Anyways you'd have two event pages The first page has a conditional branch if player_pos == event_pos(@event_id) #turn it on self-switch ON Second page has a conditional branch if player_pos != event_pos(@event_id) #turn it off self-switch OFF While you can do this without using a script, you must agree that it's much more compact. Another example is the ground-breaking request which I wrote this script for, where you are checking arbitrary tiles and arbitrary player positions. Downloads Script: Download here Edited August 2, 2016 by Tsukihime Share this post Link to post Share on other sites
Wendell 81 Posted November 9, 2012 I can use this script to, for example, make the flames to go to the top of the barrels instead of the middle? Sorry if I completly misunderstood the script. Share this post Link to post Share on other sites
Kuro Neko 0 Posted May 22, 2014 (edited) It's just me or your script really full of chinese or somethings? 'cause it looks like this: =begin à¨ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€à´€à´€ ** Event Position à¨â€€ä„€ç”€ç€æ €æ¼€çˆ€ã¨€â€€ä €æ¤€æ´€æ”€à´€à´€ Version: 1.0 à¨â€€ä€æ„€ç€æ”€ã¨€â€€ä´€æ„€ç¤€â€€ã„€ã €â°€â€€ãˆ€ã€€ã„€ãˆ€à´€à´€ ------------------------------------------------------------------------------ à¨â€€â¨€â¨€â€€äŒ€æ €æ„€æ¸€æœ€æ”€â€€æ°€æ¼€æœ€à´€à´€ 1.0 May 18 à¨â€€â€€â€€â´€ä¤€æ¸€æ¤€ç€æ¤€æ„€æ°€â€€çˆ€æ”€æ°€æ”€æ„€çŒ€æ”€à´€à´€ ------------------------------------------------------------------------------ à¨â€€ä”€ç €ç€æ”€æ¸€æ€æ”€æ€â€€ç€€æ¼€çŒ€æ¤€ç€æ¤€æ¼€æ¸€â€€æŒ€æ €æ”€æŒ€æ¬€çŒ€â€€æ˜€æ¼€çˆ€â€€æŒ€æ €æ„€çˆ€æ„€æŒ€ç€æ”€çˆ€â€€æ¼€æˆ€æ¨€æ”€æŒ€ç€çŒ€â€€â €ç€€æ°€æ„€ç¤€æ”€çˆ€çŒ€â°€â€€æ”€ç˜€æ”€æ¸€ç€çŒ€â°€â€€æ”€ç€æŒ€â¤€à´€à´€ à¨â€€ä„€æŒ€æŒ€æ”€çŒ€çŒ€â€€ç”€çŒ€æ¤€æ¸€æœ€â€€â€æœ€æ„€æ´€æ”€å¼€ç€€æ°€æ„€ç¤€æ”€çˆ€â¸€æ°€æ„€çŒ€ç€å¼€ç €â°€â€€â€æœ€æ„€æ´€æ”€å¼€ç€€æ°€æ„€ç¤€æ”€çˆ€â¸€æ°€æ„€çŒ€ç€å¼€ç¤€â°€â€€æ”€ç€æŒ€â¸€à´€à´€ à¨â€€ä¼€çˆ€â°€â€€æ˜€æ¼€çˆ€â€€çŒ€æ €æ¼€çˆ€ç€â´€æ €æ„€æ¸€æ€â°€â€€æ¨€ç”€çŒ€ç€â€€ç”€çŒ€æ”€â€€ç€æ €æ”€â€€æŒ€æ¼€æ¸€ç˜€æ”€æ¸€æ¤€æ”€æ¸€æŒ€æ”€â€€æ´€æ”€ç€æ €æ¼€æ€çŒ€â€€ç€€çˆ€æ¼€ç˜€æ¤€æ€æ”€æ€â€€æ˜€æ¼€çˆ€à´€à´€ the Interpreter à¨â€€â€€à´€à´€ event_pos(event_id) à¨â€€â€€â€€â€€æ”€ç˜€æ”€æ¸€ç€å¼€æ°€æ„€çŒ€ç€å¼€ç€€æ¼€çŒ€â €æ”€ç˜€æ”€æ¸€ç€å¼€æ¤€æ€â¤€à´€à´€ player_pos à¨â€€â€€â€€â€€ç€€æ°€æ„€ç¤€æ”€çˆ€å¼€æ°€æ„€çŒ€ç€å¼€ç€€æ¼€çŒ€à´€à´€ à¨â€€å€æ €æ”€çŒ€æ”€â€€çˆ€æ”€ç€ç”€çˆ€æ¸€â€€æ„€æ¸€â€€æ„€çˆ€çˆ€æ„€ç¤€â€€æ¼€æ˜€â€€ç˜€æ„€æ°€ç”€æ”€çŒ€â€€çˆ€æ”€ç€€çˆ€æ”€çŒ€æ”€æ¸€ç€æ¤€æ¸€æœ€â€€æ¤€æ¸€æ˜€æ¼€çˆ€æ´€æ„€ç€æ¤€æ¼€æ¸€â€€æ„€æˆ€æ¼€ç”€ç€â€€ç€æ €æ”€à´€à´€ current position or the last position à¨â€€à´€à´€ Supports 4-dir and 8-dir movement, but not jumping à¨ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€à´€à´€ =end à¨â€æ¤€æ´€ç€€æ¼€çˆ€ç€æ”€æ€â€€ã´€â€€ç¬€ç´€â€€æ¤€æ˜€â€€â€æ¤€æ´€ç€€æ¼€çˆ€ç€æ”€æ€â¸€æ¸€æ¤€æ°€ã¼€à´€à´€ $imported["Tsuki_EventPosition"] = true à¨âŒ€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€à´€à´€ # ** Rest of the Script à¨âŒ€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€ã´€à´€à´€ à¨æŒ€æ°€æ„€çŒ€çŒ€â€€äœ€æ„€æ´€æ”€å¼€äŒ€æ €æ„€çˆ€æ„€æŒ€ç€æ”€çˆ€äˆ€æ„€çŒ€æ”€à´€à´€ à¨â€€â€€æ„€ç€ç€çˆ€å¼€æ„€æŒ€æŒ€æ”€çŒ€çŒ€æ¼€çˆ€â€€ã¨€æ°€æ„€çŒ€ç€å¼€ç €à´€à´€ attr_accessor :last_y à¨â€€â€€æ„€ç€ç€çˆ€å¼€æ„€æŒ€æŒ€æ”€çŒ€çŒ€æ¼€çˆ€â€€ã¨€æ°€æ„€çŒ€ç€å¼€çˆ€æ”€æœ€æ¤€æ¼€æ¸€å¼€æ¤€æ€à´€à´€ à¨â€€â€€æ„€æ°€æ¤€æ„€çŒ€â€€æ”€ç˜€æ”€æ¸€ç€å¼€ç€€æ¼€çŒ€æ¤€ç€æ¤€æ¼€æ¸€å¼€æ¤€æ¸€æ¤€ç€å¼€æŒ€æ €æ„€çˆ€å¼€æ´€æ”€æ´€æ”€æˆ€æ”€çˆ€çŒ€â€€æ¤€æ¸€æ¤€ç€å¼€ç€€ç”€æˆ€æ°€æ¤€æŒ€å¼€æ´€æ”€æ´€æˆ€æ”€çˆ€çŒ€à´€à´€ def init_public_members à¨â€€â€€â€€â€€æ”€ç˜€æ”€æ¸€ç€å¼€ç€€æ¼€çŒ€æ¤€ç€æ¤€æ¼€æ¸€å¼€æ¤€æ¸€æ¤€ç€å¼€æŒ€æ €æ„€çˆ€å¼€æ´€æ”€æ´€æ”€æˆ€æ”€çˆ€çŒ€à´€à´€ @last_x = -1 à¨â€€â€€â€€â€€ä€€æ°€æ„€çŒ€ç€å¼€ç¤€â€€ã´€â€€â´€ã„€à´€à´€ @last_region_id = 0 à¨â€€â€€æ”€æ¸€æ€à´€à´€ à¨â€€â€€æ€æ”€æ˜€â€€ç”€ç€€æ€æ„€ç€æ”€å¼€æ°€æ„€çŒ€ç€å¼€ç€€æ¼€çŒ€â €æ€â¤€à´€à´€ if passable?(@x, @y, d) à¨â€€â€€â€€â€€â€€â€€ä€€æ°€æ„€çŒ€ç€å¼€ç €â€€ã´€â€€ä€€ç €à´€à´€ @last_y = @y à¨â€€â€€â€€â€€â€€â€€ä€€æ°€æ„€çŒ€ç€å¼€çˆ€æ”€æœ€æ¤€æ¼€æ¸€å¼€æ¤€æ€â€€ã´€â€€çˆ€æ”€æœ€æ¤€æ¼€æ¸€å¼€æ¤€æ€à´€à´€ end à¨â€€â€€æ”€æ¸€æ€à´€à´€ à¨â€€â€€æ„€æ°€æ¤€æ„€çŒ€â€€æ”€ç˜€æ”€æ¸€ç€å¼€ç€€æ¼€çŒ€æ¤€ç€æ¤€æ¼€æ¸€å¼€æ´€æ¼€ç˜€æ”€å¼€çŒ€ç€çˆ€æ„€æ¤€æœ€æ €ç€â€€æ´€æ¼€ç˜€æ”€å¼€çŒ€ç€çˆ€æ„€æ¤€æœ€æ €ç€à´€à´€ def move_straight(d, turn_ok = true) à¨â€€â€€â€€â€€ç”€ç€€æ€æ„€ç€æ”€å¼€æ°€æ„€çŒ€ç€å¼€ç€€æ¼€çŒ€â €æ€â¤€à´€à´€ event_position_move_straight(d, turn_ok) à¨â€€â€€æ”€æ¸€æ€à´€à´€ à¨â€€â€€æ„€æ°€æ¤€æ„€çŒ€â€€æ”€ç˜€æ”€æ¸€ç€å¼€ç€€æ¼€çŒ€æ¤€ç€æ¤€æ¼€æ¸€å¼€æ´€æ¼€ç˜€æ”€å¼€æ€æ¤€æ„€æœ€æ¼€æ¸€æ„€æ°€â€€æ´€æ¼€ç˜€æ”€å¼€æ€æ¤€æ„€æœ€æ¼€æ¸€æ„€æ°€à´€à´€ def move_diagonal(horz, vert) à¨â€€â€€â€€â€€ç”€ç€€æ€æ„€ç€æ”€å¼€æ°€æ„€çŒ€ç€å¼€ç€€æ¼€çŒ€â €æ€â¤€à´€à´€ event_position_move_diagonal(horz, vert) à¨â€€â€€æ”€æ¸€æ€à´€à´€ end à¨à´€à´€ class Game_Interpreter à¨â€€â€€à´€à´€ def event_pos(event_id) à¨â€€â€€â€€â€€å¬€â€æœ€æ„€æ´€æ”€å¼€æ´€æ„€ç€€â¸€æ”€ç˜€æ”€æ¸€ç€çŒ€å¬€æ”€ç˜€æ”€æ¸€ç€å¼€æ¤€æ€å´€â¸€ç €â°€â€€â€æœ€æ„€æ´€æ”€å¼€æ´€æ„€ç€€â¸€æ”€ç˜€æ”€æ¸€ç€çŒ€å¬€æ”€ç˜€æ”€æ¸€ç€å¼€æ¤€æ€å´€â¸€ç¤€å´€à´€à´€ end à¨â€€â€€à´€à´€ def event_last_pos(event_id) à¨â€€â€€â€€â€€å¬€â€æœ€æ„€æ´€æ”€å¼€æ´€æ„€ç€€â¸€æ”€ç˜€æ”€æ¸€ç€çŒ€å¬€æ”€ç˜€æ”€æ¸€ç€å¼€æ¤€æ€å´€â¸€æ°€æ„€çŒ€ç€å¼€ç €â°€â€€â€æœ€æ„€æ´€æ”€å¼€æ´€æ„€ç€€â¸€æ”€ç˜€æ”€æ¸€ç€çŒ€å¬€æ”€ç˜€æ”€æ¸€ç€å¼€æ¤€æ€å´€â¸€æ°€æ„€çŒ€ç€å¼€ç¤€å´€à´€à´€ end à¨â€€â€€à´€à´€ def player_pos à¨â€€â€€â€€â€€å¬€â€æœ€æ„€æ´€æ”€å¼€ç€€æ°€æ„€ç¤€æ”€çˆ€â¸€ç €â°€â€€â€æœ€æ„€æ´€æ”€å¼€ç€€æ°€æ„€ç¤€æ”€çˆ€â¸€ç¤€å´€à´€à´€ end à¨â€€â€€à´€à´€ def player_last_pos à¨â€€â€€â€€â€€å¬€â€æœ€æ„€æ´€æ”€å¼€ç€€æ°€æ„€ç¤€æ”€çˆ€â¸€æ°€æ„€çŒ€ç€å¼€ç €â°€â€€â€æœ€æ„€æ´€æ”€å¼€ç€€æ°€æ„€ç¤€æ”€çˆ€â¸€æ°€æ„€çŒ€ç€å¼€ç¤€å´€à´€à´€ end à¨æ”€æ¸€æ€ Edited May 22, 2014 by Kuro Neko Share this post Link to post Share on other sites
Tsukihime 1,489 Posted May 23, 2014 Just noticed that a lot of my dropbox files are corrupt. I don't know which ones are still being referenced so I'll just go and update all of it with proper versions. Share this post Link to post Share on other sites
Kuro Neko 0 Posted May 23, 2014 Excuse me, but am i using your script correctly? Share this post Link to post Share on other sites