Help - Search - Members - Calendar
Full Version: Common Events Activating through Armor
RPG RPG Revolution Forums > Game Engines > RPG Maker XP Discussion
The Undying Nephalim
Greetings, I'm new to these forums and I hope things go well here. I have a question about RPG Maker XP that's essential for my game to work.

Basically I need a common event to activate whenever a player equips armor. I notice that Items have a Common Event dropdown window yet Weapons and Armor are missing the feature. Is it possible to add that in via scripts? Is there another way around that if not? Or is it simply impossible to do?

Any help will be greatly appreciated.
Logan110
The common event is called when the item is used, so it basically gives the items extra effects. Weapons and armors accomplish this through other means, generally via skills or scripts. What exactly were you trying to accomplish?
Helios
Changing the battler/character perharps?
Bellcross
Yea, more information on what "exactly" you're trying to do would be a great help. I may be able to assist.
Callista
CODE
#==============================================================================
# ** Scene_Equip
#------------------------------------------------------------------------------
#  This class performs equipment screen processing.
#  Edited by Callista *
#  Overwrites : update_item
#==============================================================================
class Scene_Equip
  # Set up common events here, like so:
  # item_database_id => common_event_id.
  
  WEAPON_EVENTS = { 1 => 1 }
  ARMOR_EVENTS = { 1 => 1 }
  
#--------------------------------------------------------------------------
# * Frame Update (when item window is active)
#--------------------------------------------------------------------------
  def update_item
    # If B button was pressed
    if Input.trigger?(Input::B)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      # Activate right window
      @right_window.active = true
      @item_window.active = false
      @item_window.index = -1
      return
    end
    # If C button was pressed
    if Input.trigger?(Input::C)
      # Play equip SE
      $game_system.se_play($data_system.equip_se)
      # Get currently selected data on the item window
      item = @item_window.item
      # Change equipment
      @actor.equip(@right_window.index, item == nil ? 0 : item.id)
      if item.is_a?(RPG::Weapon)
        $game_temp.common_event_id = WEAPON_EVENTS[item.id] != nil ? WEAPON_EVENTS[item.id] : 0
      else
        $game_temp.common_event_id = ARMOR_EVENTS[item.id] != nil ? ARMOR_EVENTS[item.id] : 0
      end
      # Activate right window
      @right_window.active = true
      @item_window.active = false
      @item_window.index = -1
      # Remake right window and item window contents
      @right_window.refresh
      @item_window.refresh
      return
    end
  end
end


Paste before Main and after Scene_Equip, set up according to script instructions. In the example I included, common event 1 will activate when you equip a Bronze Sword (weapon id 1) or Bronze Shield (armor id 1).
The Undying Nephalim
Thanks a bunch Castilla, it looks like that script will work just fine. A few quick questions though... what function (I'm not sure what they are referred to as in Ruby) controls what armor or weapon activated the common script? Is it possible to have it so that equipping any armor will automatically trigger the common event? Also, how can I make it so that equipping armor will trigger a switch instead of a common event?

(For everyone I'm basically trying to make it so when you equip armor it changes the graphic of your character. I initially just had it so that the common script was always running on parallel process but now since there are so many armor combinations the game lags to the point that it's no longer playable. I basically want it so that when you equip armor it activates the switch needed for the common event to run and then at the end of the common event it deactivates so that there's only a few seconds of lag)

As always any help is greatly appreciated, I'll be sure to mention you in the credits Castilla.
Callista
You should use a visual equipment script. They do exactly what you want.
The Undying Nephalim
QUOTE (Callista @ Mar 12 2010, 12:31 PM) *
You should use a visual equipment script. They do exactly what you want.


I looked up the Visual Equipment Script and for the most part that's perfect. The problem is that it isn't compatible with the Caterpillar script that I use. Now that I've played around all I really need is a method for activating a switch when a player equips something. Something along the lines of a script that would read as "If player equips any armor, then switch (insertname) = On". That way when a player equips anything, it activates the switch needed to run my common event, the graphics change, and then at the end of the common event it sets the switch to Off so that there's no lag.
Callista
CODE
#=========================================================================
=====
# ** Scene_Equip
#------------------------------------------------------------------------------
#  This class performs equipment screen processing.
#  Edited by Callista *
#  Overwrites : update_item
#==============================================================================
class Scene_Equip
  # Set up common events here, like so:
  # item_database_id => common_event_id.
  
  WEAPON_EVENTS = { 1 => 1 }
  ARMOR_EVENTS = { 1 => 1 }
  SWITCH = 1
  
#--------------------------------------------------------------------------
# * Frame Update (when item window is active)
#--------------------------------------------------------------------------
  def update_item
    # If B button was pressed
    if Input.trigger?(Input::B)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      # Activate right window
      @right_window.active = true
      @item_window.active = false
      @item_window.index = -1
      return
    end
    # If C button was pressed
    if Input.trigger?(Input::C)
      # Play equip SE
      $game_system.se_play($data_system.equip_se)
      # Get currently selected data on the item window
      item = @item_window.item
      # Change equipment
      @actor.equip(@right_window.index, item == nil ? 0 : item.id)
      if item.is_a?(RPG::Weapon)
        $game_temp.common_event_id = WEAPON_EVENTS[item.id] != nil ? WEAPON_EVENTS[item.id] : 0
      else
        $game_temp.common_event_id = ARMOR_EVENTS[item.id] != nil ? ARMOR_EVENTS[item.id] : 0
        $game_switches[SWITCH] = true
      end
      # Activate right window
      @right_window.active = true
      @item_window.active = false
      @item_window.index = -1
      # Remake right window and item window contents
      @right_window.refresh
      @item_window.refresh
      return
    end
  end
end


Same thing, except now SWITCH is turned on when you equip any armour.
The Undying Nephalim
Thanks Castella, I think this will do it. If I want a specific switch, for instance a switch called "Outfits" to activate and it's number 0005 on the list, what would I need to add to that script to get that switch to work? Would I replace "SWITCH = 1" with "0005:Outfits = 1" ? I'm still getting used to this language... it's a wee bit different from Python and C++ sweat.gif
Callista
QUOTE
Castilla

QUOTE
Castella


:x

No, you just replace 1 with the switch number. Ruby isn't very different from Python. :)
The Undying Nephalim
QUOTE (Callista @ Mar 12 2010, 02:21 PM) *
QUOTE
Castilla

QUOTE
Castella


:x

No, you just replace 1 with the switch number. Ruby isn't very different from Python. smile.gif


I changed it from SWITCH = 1 to SWITCH = 5 and it seems the switch will not activate when I equip armor. I have a feeling I might have messed it up somehow sweat.gif
Callista
CODE
#=========================================================================
# ** Scene_Equip
#------------------------------------------------------------------------------
#  This class performs equipment screen processing.
#  Edited by Callista *
#  Overwrites : update_item
#==============================================================================
class Scene_Equip
  # Set up common events here, like so:
  # item_database_id => common_event_id.
  
  WEAPON_EVENTS = { 1 => 1 }
  ARMOR_EVENTS = { 1 => 1 }
  SWITCH = 5
  
#--------------------------------------------------------------------------
# * Frame Update (when item window is active)
#--------------------------------------------------------------------------
  def update_item
    # If B button was pressed
    if Input.trigger?(Input::B)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      # Activate right window
      @right_window.active = true
      @item_window.active = false
      @item_window.index = -1
      return
    end
    # If C button was pressed
    if Input.trigger?(Input::C)
      # Play equip SE
      $game_system.se_play($data_system.equip_se)
      # Get currently selected data on the item window
      item = @item_window.item
      # Change equipment
      @actor.equip(@right_window.index, item == nil ? 0 : item.id)
      if item.is_a?(RPG::Weapon)
        $game_temp.common_event_id = WEAPON_EVENTS[item.id] != nil ? WEAPON_EVENTS[item.id] : 0
      else
        $game_temp.common_event_id = ARMOR_EVENTS[item.id] != nil ? ARMOR_EVENTS[item.id] : 0
        $game_switches[SWITCH] = true if item != nil
      end
      # Activate right window
      @right_window.active = true
      @item_window.active = false
      @item_window.index = -1
      # Remake right window and item window contents
      @right_window.refresh
      @item_window.refresh
      return
    end
  end
end
Works for me.
The Undying Nephalim
Hmmm, it still won't activate the switch for me. I have it placed right after Scene_Equip in the Scripts.... maybe the positioning has something to do with it not working for me? Or maybe I was supposed to replace Scene_Equip or somehow link the two? I'm sorry if I'm frustrating, I'm still trying to get a handle of scripts. sweat.gif Your patience is greatly appreiciated. biggrin.gif
Callista
Place it right before Main, and there's no reason for it not to activate unless you have some other script conflicting.
The Undying Nephalim
I've tried the script on a completely fresh file with no custom scripts and it still will not activate any switches. Could it be that I might have a different version of RPG Maker XP? Even then I'd think all versions of RPG Maker XP would use the same syntax...
Callista
It does work on a fresh file. Just make a test common event that triggers when switch 5 (or whatever you picked) is on, go to the menu, equip some armour, and exit the menu.
The Undying Nephalim
I included some screenshots to maybe help find out what I am doing wrong...

Here's the script to set it so that Switch # 5 activates when you equip armor



Here's the common event that runs when Switch # 5 is active



I equipped the Armor...



And the switch does not activate.




I'm really puzzled as to why it's not working...
Callista
The switch does activate. Press F9 after you equip the armor and you'll see it's activating. The only thing I can think of would be something wrong with postality knights's scripts, but I'm not sure why they would even mess around with them. Try the legal version and see if it works, but I'm pretty sure it's something wrong with your events. Check if something somewhere isn't turning the switch off or so.
The Undying Nephalim
I copied everything into the official version of RPG Maker XP and it still will not work... this mystery really has me stumped. I don't have any instance where it sets Switch 5 to Off. Maybe there's another way to get what I am trying to do to work?
Callista
Make a new project. Paste my script. Make a common event set to autorun when switch 5 is on with "show text: something" and "control switch: 5 off". Now go in the menu and equip some armour. You'll see some text pop up when you leave the menu. Now you can build from there, because I have no clue what's wrong.
The Undying Nephalim
QUOTE (Callista @ Mar 12 2010, 04:49 PM) *
Make a new project. Paste my script. Make a common event set to autorun when switch 5 is on with "show text: something" and "control switch: 5 off". Now go in the menu and equip some armour. You'll see some text pop up when you leave the menu. Now you can build from there, because I have no clue what's wrong.



I found out the problem, apparently it will only activate the switch if the Common Event is the first common event on the list. Is there anywhere in your script that somehow limits it to Common Event 1? If so where in the script can I edit toI change it to another common event number like 5 or even 999? Again you have so much thanks from me, I have been working on this game for over two years and if this finally works then you'll get tons of kudos from me.
Callista
No. If you do it as I said, it will work on any common event ID. The switch has nothing to do with the common event.
The Undying Nephalim
I think for some reason these two lines might be what was responsible.

WEAPON_EVENTS = { 1 => 1 }
ARMOR_EVENTS = { 1 => 1 }

When they were set that like the switch would only activate if Common Event 1 was effected

I changed it to:

WEAPON_EVENTS = { 1 => 5 }
ARMOR_EVENTS = { 1 => 5 }

since common event 5 managed everything and then it worked.

I'm curious what exactly do those two lines of code do?
Callista
Err... that's what you asked for first. It makes it so common event ID 5 is activated when you equip weapon or armor with ID 1. I have no idea what it is you're doing that makes it work like that, but hey, if it works...
The Undying Nephalim
QUOTE (Callista @ Mar 12 2010, 05:22 PM) *
Err... that's what you asked for first. It makes it so common event ID 5 is activated when you equip weapon or armor with ID 1. I have no idea what it is you're doing that makes it work like that, but hey, if it works...


Hehe, awesome it looks like the problem was solved. I had to equip armor that had an ID higher then 1. I figure if I want this Switch to trigger for multiple armors I'd have to add:

ARMOR_EVENTS = {1 => 1 }
ARMOR_EVENTS = {2 => 1 }
ARMOR_EVENTS = {3 => 1 }
etc, etc

into the script? Or is there a way to set it so that the ID is all armors? Maybe something like: ARMOR_EVENTS = {ALL => 1 }

Whatever the case I think I should be able to figure it out from here hopefully. Thank you so much for all your help Castilla. You're my new hero of week. biggrin.gif
Callista
ARMOR_EVENTS = { 1 => 1, 2 => 1, 3 => 1} etc., actually. That shouldn't really be needed though.
The Undying Nephalim
Thanks a bunch Castilla it works absolutely perfectly now even in Postality. biggrin.gif biggrin.gif biggrin.gif

I'm sorry if I was confusing in my questions or caused frustration... again I'm still learning all the syntax of Ruby so I'm still a noob at this. I'm starting to see the similarities to Python though.

You'll be getting a spot in the credits for sure. This has helped tremendously. thumbsup.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2013 Invision Power Services, Inc.