Jump to content
AeghtyAteKees

Shaz's Region Common Events

Recommended Posts

Shaz wrote this really convenient script that calls common events from the map when the player stands on or faces a certain region.

 

Is it possible to use this script to also call a common event when the action button is pressed while standing on or facing a region? Or would that require modification?

 

Thanks!

Share this post


Link to post
Share on other sites

Do you have a readable version of the script with line breaks ?

 

The way it is stored on rmn makes the script uneditable

Share this post


Link to post
Share on other sites


#============================================================================

# REGION COMMON EVENTS

# v1.0 by Shaz

#----------------------------------------------------------------------------

# This script allows you to paint regions on your map, and set up common

# events to be run when the player walks onto or faces a tile with that

# region id.

#----------------------------------------------------------------------------

# To Install:

# Copy and paste into a new script slot in Materials. This script aliases

# existing methods, so can go below all other custom scripts.

#----------------------------------------------------------------------------

# To Use:

# Paint regions on the map over the tiles you want to trigger events

# Create a common event that will do whatever you want to happen when the

# player walks on or bumps into a tile with that region

# Add one of the following lines to the map's note box

#

# regevt: reg_id on common_event_id

# This will trigger the common event when the player steps on the tile

# eg: regevt: 63 on 15

# will call common event 15 when the player steps on a region 63 tile

# regevt: reg_id face common_event_id

# This will trigger the common event when the player is facing, but not

# standing on the tile

# eg: regevt: 62 face 12

# will call common event 12 when the player is facing a region 62 tile

# (you might use this if you want something to happen when the player

# bumps into a wall - paint the bottom of the wall with region 62)

#----------------------------------------------------------------------------

# Terms:

# Use in free or commercial games

# Credit Shaz

#============================================================================

 

class Game_Map

#--------------------------------------------------------------------------

# * Setup

#--------------------------------------------------------------------------

alias shaz_re_game_map_setup setup

def setup(map_id)

shaz_re_game_map_setup(map_id)

setup_region_events

end

#--------------------------------------------------------------------------

# * Setup Common Events for Regions

#--------------------------------------------------------------------------

def setup_region_events

@reg_evt = {}

@req = []

@map.note.split(/[\r\n+]/).each do |line|

case line

when /regevt:\s*(\d+)\s*(\w+)\s*(\d+)/i

reg = $1.to_i

mode = $2

ce = $3.to_i

if !@reg_evt.has_key?(reg)

@reg_evt[reg] = {}

end

@reg_evt[reg][mode] = ce

end

end

end

#--------------------------------------------------------------------------

# * Check Region Events

#--------------------------------------------------------------------------

def check_region_event(x, y, dir)

reg = region_id(x, y)

next_reg = region_id(x_with_direction(x, dir), y_with_direction(y, dir))

if @reg_evt[reg] && @reg_evt[reg]["on"]

@req.push(@reg_evt[reg]["on"])

end

if @reg_evt[next_reg] && @reg_evt[next_reg]["face"]

@req.push(@reg_evt[next_reg]["face"])

end

end

#--------------------------------------------------------------------------

# * Frame Update

# main: Interpreter update flag

#--------------------------------------------------------------------------

alias shaz_re_game_map_update update

def update(main = false)

shaz_re_game_map_update(main)

$game_temp.reserve_common_event(@req.shift) if

!$game_temp.common_event_reserved? && @req.size > 0

end

end

 

 

class Game_Player < Game_Character

#--------------------------------------------------------------------------

# * Frame Update

#--------------------------------------------------------------------------

alias shaz_re_game_player_update update

def update

old_x = @x

old_y = @y

old_dir = @direction

shaz_re_game_player_update

$game_map.check_region_event(@x, @y, @direction) if

@x != old_x || @y != old_y || @direction != old_dir

end

end

Share this post


Link to post
Share on other sites

Try this script

class Game_Player < Game_Character
  
  alias trigger_region_update update
  def update
    trigger_region_update
	$game_map.check_trigger_region_event(@x, @y, @direction) if Input.trigger?(:C)
  end
end

class Game_Map 
    def check_trigger_region_event(x, y, dir)
		reg = region_id(x, y)
		next_reg = region_id(x_with_direction(x, dir), y_with_direction(y, dir))
		if @reg_evt[reg] && @reg_evt[reg]["trigger_on"]
		  @req.push(@reg_evt[reg]["trigger_on"])
		end
		if @reg_evt[next_reg] && @reg_evt[next_reg]["trigger_face"]
		  @req.push(@reg_evt[next_reg]["trigger_face"])
		end
    end
end

It uses the same notation but you need to use the codes trigger_on and trigger_face to indicate you want it to work when the player does an input

Share this post


Link to post
Share on other sites

This works great! Thank you for being so helpful on this forum!

 

Can I bother you for one more tweak? I need directional checking for this to be practical in my project. Would it be a good idea to do trigger_face_(d) to specify a direction? You could use the 2 4 6 8 directions or even l r u d for "left" "right" "up" and "down". And if possible, the support for more than one direction such as "trigger_face_lr (or 4 and 6)" for an event that can only be activated from the sides.

 

Thanks! :D

Share this post


Link to post
Share on other sites

only for facing and nly on player input but I could add that if you need it

Edited by Shiggy

Share this post


Link to post
Share on other sites

If you could add directional support for the "on" region trigger, that would be awesome.

 

However, the directional commands don't seem to be working.

Share this post


Link to post
Share on other sites

I did some test, trigger_face_l was to long an cutting to the next line preventing the script to read the notebox correctly

 

https://www.dropbox.com/s/jhonnhlcw3byj2q/region_events_addon.rb?dl=0

 

so now it's
tri_face_d/lr/u

and
tri_on_d/r/l/u

to indicate you need an input , facing a certain direction and being on or in front of a region

Share this post


Link to post
Share on other sites

Hmm... I get a lot of no method errors that I can't seem to consistently recreate... :/ Also, the up direction is the only direction that I can get to work.

 

Also (and I'm not sure if this is something you can patch or not, but...), the script cues up several instances of the common event if the trigger is pressed while the common event is running. So if the common event is a message window, for example, and you trigger the region three times, you'll get the message three times.

 

(Also, you're missing an "end" at the bottom of the script).

 

Thank you for your help!

Share this post


Link to post
Share on other sites

I updated the file,it should work this time

Share this post


Link to post
Share on other sites

This thread is closed, due to being solved. If for some reason anybody would like to re-open this thread, just send me a PM or report the thread. (=

Share this post


Link to post
Share on other sites

Reopened at OP's request. c:

Share this post


Link to post
Share on other sites

Hi, Shiggy! Thanks for being my go-to for help with this feature of my project. Anyways, you corrected many No Method errors in the last fix you did, though I just now found another one: if you try to use trigger_face without any direction. And I've since used every feature of this snippet but that one, so I can more or less guarantee that's the only thing about it that doesn't work.

 

If you could patch that for me, I would be forever grateful. Thanks for all your continued support.

 

:D

Spoiler

 

 

Share this post


Link to post
Share on other sites

Obviously, it's been a while so I'm not sure. But with a quick glance . I would say that at line 37, it should be 

 @req.push(@reg_evt[next_reg]["trigger_face"])

instead of

@req.push(@reg_evt[reg]["trigger_face"])

Try it, I will then update the file if it works.

Share this post


Link to post
Share on other sites

 

4 hours ago, AeghtyAteKees said:

Works like a charm!

 

Ok good, I've updated the dropbox file in case someone else uses the script.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
Top ArrowTop Arrow Highlighted