The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX => VX Scripts Database => Topic started by: modern algebra on May 15, 2010, 01:26:20 AM

Title: Apply State Equipment
Post by: modern algebra on May 15, 2010, 01:26:20 AM
Apply State Equipment
Version: 1.0
Author: modern algebra
Date: May 14, 2010

Version History



Planned Future Versions


Description


This script allows you to assign states to equipment that will be applied to an actor for as long as he/she has that weapon or armor equipped.

Features


Instructions

Please see the header of the script.

However, one quick note about priority - if a state applied in the normal manner would cancel a state given by equipment, then that state will cancel the equipment state until its duration is over. If a state that is applied in a normal manner would be cancelled by an equipment state, then it will be removed. If the two states would cancel each other out, the one applied normally takes priority until it is extinguished.

Script


Code: [Select]
#==============================================================================
#    Apply State Equipment
#    Version: 1.0
#    Author: modern algebra (rmrk.net)
#    Date: May 14, 2010
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Description:
#
#    This script allows you to assign states to equipment that will be applied
#   to an actor for as long as he/she has that weapon or armor equipped.
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Instructions:
#
#    Paste this script into its own slot in the Script Editor (F11), somewhere
#   below Materials but above Main.
#
#    To assign states to a weapon or armor, simply put in the code:
#      \equip_states[state_1, state_2, ..., state_n]
#
#    where state_1 ... state_n are the IDs of the states you want this
#   equipment to apply to the actor.
#
#  EXAMPLES:
#    \equip_state[1] - would apply an Incapacitated state to the actor
#    \equip_state[10, 13] would apply the states DEF UP and ATK Down
#==============================================================================
#  ** RPG::BaseItem
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes: 
#    new method - ma_equip_states
#==============================================================================

class RPG::BaseItem
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Equip States
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def ma_equip_states
    if !@ma_equip_states
      @ma_equip_states = []
      if self.note[/\\EQUIP_STATES\[([\d,\s]*?)\]/i] != nil
        state_s = $1.to_s
        state_s.gsub (/(\d+)/) { |i| @ma_equip_states.push (i.to_i) }
      end
    end
    return @ma_equip_states
  end
end

#==============================================================================
# ** Game Actor
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    aliased method - initialize; states; change_equip
#    new method - add_equip_state
#==============================================================================

class Game_Actor
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Object Initialization
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias maa_ase_initz_6rv2 initialize
  def initialize (*args)
    @ase_equipstates = []
    maa_ase_initz_6rv2 (*args) # Run Original Method
    equips.each { |equip|
      next if !equip # Next if slot is nil
      equip.ma_equip_states.each { |state_id| add_equip_state (state_id) }
    }
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Change Equipment
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias moda_eqstates_chnguip_8ik2 change_equip
  def change_equip(equip_type, item, test = false, *args)
    last = equips[equip_type]
    if !test
      last.ma_equip_states.each { |id| @ase_equipstates.delete (id) } if last
      item.ma_equip_states.each { |id| add_equip_state (id) } if item
    end
    moda_eqstates_chnguip_8ik2 (equip_type, item, test, *args) # Run Original Method
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * States
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias malga_apsteq_stts_7uj2 states
  def states (*args)
    result = malga_apsteq_stts_7uj2 (*args)
    for state_id in @ase_equipstates
      state = $data_states[state_id]
      next if result.include? (state)
      skip = false
      result.each { |state2|
        if state2.state_set.include? (state.id)
          skip = true
          break
        end
      }
      next if skip
      state.state_set.each { |state_id|
        result.delete ($data_states[state_id])
        remove_state (state_id)
        @removed_states.delete (state_id) # Don't report its removal
      }
      result.push (state)
    end
    return result
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Add Equip State
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def add_equip_state (state_id)
    real_states = @states
    @states = []
    add_state (state_id)
    @ase_equipstates += @states
    @states = real_states
  end
end

Credit



Support


Please post here, in this topic at RMRK.net for help with this script.

Known Compatibility Issues

No compatibility errors that I am currently aware of.
Title: Re: Apply State Equipment
Post by: cozziekuns on May 15, 2010, 01:30:51 AM
I was a bit confused about what this did at first. But now that I've seen it, it seems to be a pretty nice script.
Title: Re: Apply State Equipment
Post by: kreavenkreaven on August 13, 2010, 03:24:59 PM
Amazing. It may be a simple script, but that's more useful than you can imagine. I love it. And I'd love even more to see this version 1.1. I hope the offer is still valid. Well, is it? ???
Title: Re: Apply State Equipment
Post by: willee02 on August 19, 2010, 02:59:04 AM
I tried this script but it doesn't seem to apply the state I want a weapon or armor to have. I did place this on the note for the weapon or armor \equip_state[1]

I did also paste the whole script on the script editor below materials but above main. It doesn't show any error. What could be causing this? :)
Title: Re: Apply State Equipment
Post by: modern algebra on August 19, 2010, 03:06:48 AM
Well, it should be \equip_states[1] - state should be plural.

Also, you realize that 1 is the incapacitated state?
Title: Re: Apply State Equipment
Post by: willee02 on August 19, 2010, 03:56:44 AM
ohhh so that's why, i just copied and pasted the example on the script :p

yes, its incapacitated just like in the example. ^^
Title: Re: Apply State Equipment
Post by: Grafikal on October 12, 2010, 08:23:14 PM
  • <Version 1.1> If anyone expresses interest, I am thinking of making an addon to show what states would be applied and removed in the Equip scene. I will not do this if no one posts asking for it though.

Do want do want
Title: Re: Apply State Equipment
Post by: StAlexia on December 04, 2010, 04:05:06 AM
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fimg138.imageshack.us%2Fimg138%2F2934%2Fsadaasda.png&hash=1706e7deeb82fc40540fa1f20834b491abf81bdd) :-[

I dont know why I'm getting this error whenever I'm about to enter a battle... Any ideas? u_u
Title: Re: Apply State Equipment
Post by: modern algebra on December 04, 2010, 05:58:17 PM
It's probably an incompatibility with another script. Try placing this script below all your other custom scripts, but still above Main.
Title: Re: Apply State Equipment
Post by: StAlexia on December 04, 2010, 08:06:17 PM
  • <Version 1.1> If anyone expresses interest, I am thinking of making an addon to show what states would be applied and removed in the Equip scene. I will not do this if no one posts asking for it though.

Do want do want

I'm also interested :D It'd be super cool

It's probably an incompatibility with another script. Try placing this script below all your other custom scripts, but still above Main.

Yep, i tried it but the error keeps popping before the battle begins :S This script could be very determinant in my game's development since the usage I'm planning for this script is to have something like "weapon modes", i.e. if you equip a saber you'll have a series of skills available only for that kind of weapon, as well with swords, spears, etc.   :'(

But I'm also planning to have Low, Mid and High rate weapons and depending on their rating they'll have 2 or more modes available (for example a high-rate 2h sword which has 3 modes: low guard, mid guard and high guard, each mode having it's own skills (formation skills [parameter changing skills] and damage/recovery skills [standard skills)]

So I'm guessing if this script could help me do that kind of stuff or if there's any alternative way, like engines or scripts  :-\

Ty in advance
Title: Re: Apply State Equipment
Post by: modern algebra on December 04, 2010, 08:28:29 PM
Well, see if you can diagnose which script this one is conflicting with and send me a link to it. To do so, just make a new project and start by just putting the Apply State Equipment script in. Then, add your other scripts one-by-one, testing in between. When the error occurs, report the last script you had added.