Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

 
Reply to this topicStart new topic
> VXAce: Evented Page Conditions
Night_Runner
post May 27 2012, 02:33 AM
Post #1


Level 50
Group Icon

Group: +Gold Member
Posts: 1,525
Type: Scripter
RM Skill: Undisclosed




*Evented Page Conditions

Version: 1.0
Author: Night_Runner
Release Date: 27 May 2012

Platform: RPG Maker VX Ace

Exclusive Script at RPG RPG Revolution


Introduction
This script allows developers to use condional branches to set whether an event's page should be active.
In my second screenshot I show how a developer could allow/disallow a page based on the conditional branch, which checks if a short sword is in the party's inventory.

Features
By using the event's commands to set whether a page should be active allows much more control over development, and makes the events flow a lot nicer.
A lot of the features added through this script could easily be implemented with events, but this script is designed to minimise the lag that could be created through eventing, and would save on a lot of switches/variables, keeping the switch/variable lists cleaner.

NOTE
There are two conditional branches that I do not update the events for, the first being the enemy (their state or whatever) since this script can't be run during battle, and second being the direction of the player/event, because it would take too much processing to reset the event's page every time the player turns.


Script
CODE
#==============================================================================
# ** VXAce: Night_Runner's Evented Page Conditions
#------------------------------------------------------------------------------
# History:
#  Date Created: 27/May/2012
#  Inspired by: Tsukihime's Scripted event page conditions
#   @>http://www.rpgrevolution.com/forums/index.php?showtopic=56516
#  Script Posted:
#   @> http://www.rpgrevolution.com/forums/index.php?showtopic=56520
#
# Description:
#  This script allows developers to use condional branches to set whether an
#  event's page should be active.
#
# How to Install:
#  Highlight and copy the entire script.
#  In your game's editor, select Tools >> Script Editor.
#  Along the left hand side scroll to the bottom, right click on after
#  'Materials' and select 'Insert'.
#  Paste in the blank window on the right.
#
# How to Use:
#  See the screenshots attached.
#==============================================================================



#==============================================================================
# ** Game_Timer
#------------------------------------------------------------------------------
#  Edited to refresh the map when certain actions occur.
#==============================================================================

class Game_Timer
  #--------------------------------------------------------------------------
  # * Alias Methods
  #--------------------------------------------------------------------------
  alias nr_cusCond_update  update  unless $@
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update(*args)
    # Get the count at the start of the event
    count_at_start = @count
    # Run the original update
    nr_cusCond_update(*args)
    # If the counter has changed
    fr = Graphics.frame_rate
    # Note the divide operation takes a lot of time, so we have this check
    # without the divide first to try and reduce wasted processing
    #  This will reduce wastage when the count is not active
    if count_at_start != @count
      if (count_at_start / fr) != (@count / fr)
        on_change
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Processing When the Time Changes
  #--------------------------------------------------------------------------
  def on_change
    $game_map.need_refresh = true
  end
end



#==============================================================================
# ** Game_Actor
#------------------------------------------------------------------------------
#  Edited to refresh the map when certain actions occur.
#==============================================================================

class Game_Actor
  #--------------------------------------------------------------------------
  # * Alias Methods
  #--------------------------------------------------------------------------
  alias nr_cusCond_refresh       refresh       unless $@
  alias nr_cusCond_learn_skill   learn_skill   unless $@
  alias nr_cusCond_forget_skill  forget_skill  unless $@
  alias nr_cusCond_change_class  change_class  unless $@
  #--------------------------------------------------------------------------
  # * Set Name
  #--------------------------------------------------------------------------
  def name=(*args)
    # Apply the name
    @name = args
    # Update for the changes
    on_change
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh(*args)
    # Run the original refresh
    nr_cusCond_refresh(*args)
    # Update for the changes
    on_change
  end
  #--------------------------------------------------------------------------
  # * Learn Skill
  #--------------------------------------------------------------------------
  def learn_skill(*args)
    # Run the original learn_skill
    nr_cusCond_learn_skill(*args)
    # Update for the changes
    on_change
  end
  #--------------------------------------------------------------------------
  # * Forget Skill
  #--------------------------------------------------------------------------
  def forget_skill(*args)
    # Run the original forget_skill
    nr_cusCond_forget_skill(*args)
    # Update for the changes
    on_change
  end
  #--------------------------------------------------------------------------
  # * Change Class
  #--------------------------------------------------------------------------
  def change_class(*args)
    # Run the original change_class
    nr_cusCond_change_class(*args)
    # Update for the changes
    on_change
  end
  #--------------------------------------------------------------------------
  # * Processing When Changes Occur
  #--------------------------------------------------------------------------
  def on_change
    $game_map.need_refresh = true
  end
end



#==============================================================================
# ** Game_Party
#------------------------------------------------------------------------------
#  Edited to refresh the map when certain actions occur.
#==============================================================================

class Game_Party
  #--------------------------------------------------------------------------
  # * Alias Methods
  #--------------------------------------------------------------------------
  alias nr_cusCond_add_actor     add_actor     unless $@
  alias nr_cusCond_remove_actor  remove_actor  unless $@
  alias nr_cusCond_gain_gold     gain_gold     unless $@
  alias nr_cusCond_lose_gold     lose_gold     unless $@
  #--------------------------------------------------------------------------
  # * Add an Actor
  #--------------------------------------------------------------------------
  def add_actor(*args)
    # Run the original add_actor
    nr_cusCond_add_actor(*args)
    # Update for the changes
    on_change
  end
  #--------------------------------------------------------------------------
  # * Remove Actor
  #--------------------------------------------------------------------------
  def remove_actor(actor_id)
    # Run the original remove_actor
    nr_cusCond_remove_actor(*args)
    # Update for the changes
    on_change
  end
  #--------------------------------------------------------------------------
  # * Increase Gold
  #--------------------------------------------------------------------------
  def gain_gold(*args)
    # Run the original gain_gold
    nr_cusCond_gain_gold(*args)
    # Update for the changes
    on_change
  end
  #--------------------------------------------------------------------------
  # * Decrease Gold
  #--------------------------------------------------------------------------
  def lose_gold(*args)
    # Run the original gain_gold
    nr_cusCond_lose_gold(*args)
    # Update for the changes
    on_change
  end
  #--------------------------------------------------------------------------
  # * Processing When Changes Occur
  #--------------------------------------------------------------------------
  def on_change
    $game_map.need_refresh = true
  end
end



#==============================================================================
# ** Game_Vehicle
#------------------------------------------------------------------------------
#  Edited to refresh the map when certain actions occur.
#==============================================================================

class Game_Vehicle
  #--------------------------------------------------------------------------
  # * Alias Methods
  #--------------------------------------------------------------------------
  alias nr_cusCond_get_on   get_on   unless $@
  alias nr_cusCond_get_off  get_off  unless $@
  #--------------------------------------------------------------------------
  # * Board Vehicle
  #--------------------------------------------------------------------------
  def get_on
    # Run the original get_on
    nr_cusCond_get_on(*args)
    # Update for the changes
    on_change
  end
  #--------------------------------------------------------------------------
  # * Get Off Vehicle
  #--------------------------------------------------------------------------
  def get_off
    # Run the original get_off
    nr_cusCond_get_off(*args)
    # Update for the changes
    on_change
  end
  #--------------------------------------------------------------------------
  # * Processing When Changes Occur
  #--------------------------------------------------------------------------
  def on_change
    $game_map.need_refresh = true
  end
end



#==============================================================================
# ** Game_Event
#------------------------------------------------------------------------------
#  Edited to allow checking the conditions using the event.
#==============================================================================

class Game_Event
  #--------------------------------------------------------------------------
  # * Alias Methods
  #--------------------------------------------------------------------------
  alias nr_cusCond_conditions_met?  conditions_met?   unless $@
  #--------------------------------------------------------------------------
  # * Determine if Event Page Conditions Are Met
  #--------------------------------------------------------------------------
  def conditions_met?(page, *args)
    # If the event is looking to use this script
    if page.list.inspect.include?("reject_page")
      # Create the interpreter, set it up, and test
      interpreter = Game_Interpreter.new
      interpreter.setup(page.list, @event.id)
      interpreter.cusCond_execute
      # If the page should be used
      if interpreter.cosCond_use_page == true
        return true
      # If the page should not be used
      elsif interpreter.cosCond_use_page == false
        return false
      end
      # If undecided, run the original conditions_met?
    end
    # Run the original conditions_met?
    return nr_cusCond_conditions_met?(page, *args)
  end
end



#==============================================================================
# ** Game_Interpreter
#------------------------------------------------------------------------------
#  Edited to allow executing the event, to check if the conditions are met
#==============================================================================

class Game_Interpreter
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_reader :cosCond_use_page
  #--------------------------------------------------------------------------
  # * Use Event
  #--------------------------------------------------------------------------
  def use_page
    # If we are not testing the event, do nothing
    return if @cusCond_testing_event != true
    # Let the Game_Event know that the conditions are met
    @cosCond_use_page = true
    @index = @list.size
  end
  #--------------------------------------------------------------------------
  # * Reject Page
  #--------------------------------------------------------------------------
  def reject_page
    # If we are not testing the event, do nothing
    return if @cusCond_testing_event != true
    # Let the Game_Event know that the conditions are NOT met
    @cosCond_use_page = false
    @index = @list.size
  end
  #--------------------------------------------------------------------------
  # * Execute
  #--------------------------------------------------------------------------
  def cusCond_execute
    # Default to not using the page (if use_page and reject page are not found)
    @cosCond_use_page = false
    # Set a flag, we are testing the starting conditions
    @cusCond_testing_event = true
    # Loop through running the page
    while @list[@index] do
      execute_command
      @index += 1
    end
    # Disable the 'testing conditions' flag (for completeness)
    @cusCond_testing_event = false
  end
end



#==============================================================================
# ** End of Script.
#==============================================================================


Customization
N/A

Compatibility
This script is designed to be compatible with all known scripts currently available for RPG Maker VX Ace

Screenshot
[Show/Hide] Screenshots

Page 1, working normally


Page 2, using the script

At the start of the event it has the


DEMO
http://min.us/m3hiuxyhX

*Installation Instructions
CODE
# How to Install:
#  Highlight and copy the entire script.
#  In your game's editor, select Tools >> Script Editor.
#  Along the left hand side scroll to the bottom, right click on after
#  'Materials' and select 'Insert'.
#  Paste in the blank window on the right.


FAQ
Ask away

Terms and Conditions
Use as you see fit.
Credits are appreciated, but not necessary

Credits
Tsukihime's Scripted event page conditions for the inspiration
http://www.rpgrevolution.com/forums/index....showtopic=56516


__________________________
K.I.S.S.
Want help with your scripting problems? Upload a demo! Or at the very least; provide links to the scripts in question.

Most important guide ever: Newbie's Guide to Switches
Go to the top of the page
 
+Quote Post
   
Tsukihime
post May 27 2012, 12:21 PM
Post #2


Level 25
Group Icon

Group: Revolutionary
Posts: 561
Type: None
RM Skill: Undisclosed
Rev Points: 25




Oh, use a conditional branch. Great idea.

I've updated my event extension script to check and evaluate the conditional branch.
It's just basically copying command_111 over from Game_Interpreter and replacing "@param" with "param" and "@event_id" with "event_id" assuming you pass those in as arguments.

Everything should work fine because all it uses are event_id and command.params.

lol you decided to go with the need_refresh = true everywhere.
I'm still looking around to see if there's a way for me to avoid that!

QUOTE
since this script can't be run during battle


I've added battle condition support.
But it's a little rough because of the default code running this check first:

CODE
if !c.turn_ending && !c.turn_valid && !c.enemy_valid && !c.actor_valid && !c.switch_valid
    return false      # Conditions not set: not executed
end


So I basically copied some code just to take out that particular check.

QUOTE
and second being the direction of the player/event, because it would take too much processing to reset the event's page every time the player turns.


What about the player/event's current position?
Very often do people use things like

CODE
store player X in var 1
store player Y in var 2

if var 1 == n
   if var 2 == m
     do this


So we should update everytime the player moves.
In order to prevent refreshing too many events, maybe instead of refreshing all events, we just refresh a certain set of events using memoization or some other technique to remember which events should be refreshed at certain points in time.

Anything that doesn't need to be updated all the time should be stored in a separate set that will only be refreshed when an additional flag is set. In the best scenario, everytime you move, you are only refreshing one or two events rather than 10-20 (including all transfers and any parallel events currently running on the map in the background, etc)

This post has been edited by Tsukihime: May 27 2012, 06:28 PM


__________________________
My Scripts
Go to the top of the page
 
+Quote Post
   
Night_Runner
post May 28 2012, 05:19 AM
Post #3


Level 50
Group Icon

Group: +Gold Member
Posts: 1,525
Type: Scripter
RM Skill: Undisclosed




My script doesn't necessarily use the conditional branch.
Whenever $game_map.needs_refresh is true, my script finds if the event's page may be using my code (which is kinda poorly implemented), and will run the event, until it executes one of the two snippets of code that my script needs, stating whether to use or reject the page.

Haha, yeah, the needs_refresh isn't great, but I couldn't think of any alternative that would work well and have as little effect on performance (I was thinking of multi-threading, and once per second running needs_refresh = true, since VXA seems to handle event refreshing pretty well, but even so waiting a full second could cause problems for parallel events).

If you have a separate event (event cool.gif that is updating variables every second, then that changing of the variable would set $game_map.needs_refresh = true, and would then try and refresh the events, so it's a relatively easy work around.

The having an array of known events that use this script may help, but I'm happy with how it works at the moment, if there's need I can easily change it happy.gif


__________________________
K.I.S.S.
Want help with your scripting problems? Upload a demo! Or at the very least; provide links to the scripts in question.

Most important guide ever: Newbie's Guide to Switches
Go to the top of the page
 
+Quote Post
   

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 24th May 2013 - 08:59 AM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker