Jump to content


Photo

Event Positions


  • Please log in to reply
4 replies to this topic

#1 Tsukihime

Tsukihime

    Advanced Member

  • Ace Member
  • 7120 posts
  • LocationToronto
  • RM Skill - Coder

Awards Bar:

Users Awards

Posted 18 May 2012 - 11:01 AM

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 by Tsukihime, 02 August 2016 - 01:54 PM.

All of my work can be found on my website:

banner200x40.png

You can follow me on any of these platforms:

logo_facebook40x40.pnglogo_twitter40x40.pnglogo_youtube40x40.pnglogo_patreon40x40.pnglogo_instagram40x40.png

Go here for Bugs and Requests.
 
Want to become a beta tester for my plugins before they are released to the public?

#2 Wendell

Wendell

    The Persona Lover

  • Ace Member
  • 507 posts
  • RM Skill - Eventer

Posted 09 November 2012 - 04:13 PM

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.

Posted Image

zexeriA.png


#3 Kuro Neko

Kuro Neko

    Advanced Member

  • Ace Member
  • 59 posts

Posted 22 May 2014 - 01:22 PM

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 by Kuro Neko, 22 May 2014 - 01:23 PM.


#4 Tsukihime

Tsukihime

    Advanced Member

  • Ace Member
  • 7120 posts
  • LocationToronto
  • RM Skill - Coder

Awards Bar:

Users Awards

Posted 23 May 2014 - 10:05 AM

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.
All of my work can be found on my website:

banner200x40.png

You can follow me on any of these platforms:

logo_facebook40x40.pnglogo_twitter40x40.pnglogo_youtube40x40.pnglogo_patreon40x40.pnglogo_instagram40x40.png

Go here for Bugs and Requests.
 
Want to become a beta tester for my plugins before they are released to the public?

#5 Kuro Neko

Kuro Neko

    Advanced Member

  • Ace Member
  • 59 posts

Posted 23 May 2014 - 12:34 PM

Excuse me, but am i using your script correctly?

Untitled_zps4d54f5cf.jpg






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users