States : Spread
#1
States : Spread
Version: 1.0

Introduction

I've always thought that it was silly that there aren't any communicable states, communicable meaning a state that is inflicted on one target but spreads to others. For instance, if you were fighting a wild pig, there is a chance its bite would inflict swine flu, then your friends would in turn catch it from you, and... yeah.

Features
  • Create states that can spread.
  • Can set a variance of how likely it is to spread.
  • Can determine if it only spreads between friends, foes, or both.

Script

Code:
#===============================================================================
# ** States : Spread
#===============================================================================

#===============================================================================
# ** RPG::State
#===============================================================================

class RPG::State
  #-----------------------------------------------------------------------------
  # * Spread = {id => [chance(, scope)], ...}
  #-----------------------------------------------------------------------------
  #   -Chance is how likely from [chance] to 100 is it for this state to spread
  #   -Scope is does it affect friends, foes, all or none.
  #     :all     (or 0) #=> Spreads to friends and foes
  #     :friends (or 1) #=> Spreads to friends
  #     :foes    (or 2) #=> Spreads to foes
  #-----------------------------------------------------------------------------
  Spread = Hash.new
  # Developer Customization
  Spread[5] = [30, :all]
  Spread[6] = [50, :friends]
  #-----------------------------------------------------------------------------
  # * Internal Use (*Don't touch*)
  #-----------------------------------------------------------------------------
  Spread_All      = [nil, 0, :all]
  Spread_Friends  = [1, :friends]
  Spread_Foes     = [2, :foes]
  #-----------------------------------------------------------------------------
  # * Spread?
  #-----------------------------------------------------------------------------
  def can_spread?
    # True if any settings are registered
    Spread.has_key?(@id)
  end
  #-----------------------------------------------------------------------------
  # * Spread Chance
  #-----------------------------------------------------------------------------
  def spread_chance
    # If defined, returns value, else returns 0
    can_spread? ? Spread[id][0] : 0
  end
  #-----------------------------------------------------------------------------
  # * Spread to Friends?
  #-----------------------------------------------------------------------------
  def spread_to_friends?
    # False if state doesn't have a spread setting
    return false unless can_spread?
    # True if spread all
    return true if Spread_All.include?(Spread[id][1])
    # True if spread friend
    Spread_Friends.include?(Scope[id][1])
  end
  #-----------------------------------------------------------------------------
  # * Spread to foes?
  #-----------------------------------------------------------------------------
  def spread_to_foes?
    # False if state doesn't have a spread setting
    return false unless can_spread?
    # True if spread all
    return true if Spread_All.include?(Spread[id][1])
    # True if one of these values equals the second setting
    Spread_Foes.include?(Scope[id][1])
  end
  #-----------------------------------------------------------------------------
  # * Spread Success?
  #-----------------------------------------------------------------------------
  def spread_success?
    # Spread chance is equal to or greater than a random between 1 and 100
    spread_chance >= rand(100)
  end
end

#===============================================================================
# ** Game_Battler
#===============================================================================

class Game_Battler
  #-----------------------------------------------------------------------------
  # * Alias Listings
  #-----------------------------------------------------------------------------
  alias_method :spreadstates_gmbattler_removestatesauto, :remove_states_auto
  #-----------------------------------------------------------------------------
  # * Remove States Auto
  #-----------------------------------------------------------------------------
  def remove_states_auto
    # The usual...
    spreadstates_gmbattler_removestatesauto
    # Iterate through current states
    spread_states
  end
  #-----------------------------------------------------------------------------
  # * Spread States
  #-----------------------------------------------------------------------------
  def spread_states
    # Iterate through inflicted states
    @states.each do |id|
      # Get state data
      state = $data_states[id]
      # Next unless state is spreadable
      next unless state.can_spread?
      # Spread to friends and/or foes where applicable
      spread_state_to_friends(id) if state.spread_to_friends?
      spread_state_to_foes(id)    if state.spread_to_foes?
    end
  end
end

#===============================================================================
# ** Game_Actor
#===============================================================================

class Game_Actor
  #-----------------------------------------------------------------------------
  # * Spread State to Friends
  #-----------------------------------------------------------------------------
  def spread_state_to_friends(state)
    $game_party.actors.each   {|a| a.add_state(state) if state.spread_success?}
  end
  #-----------------------------------------------------------------------------
  # * Spread State to Foes
  #-----------------------------------------------------------------------------
  def spread_state_to_foes(state)
    $game_troop.enemies.each  {|e| e.add_state(state) if state.spread_success?}
  end
end

#===============================================================================
# ** Game_Enemy
#===============================================================================

class Game_Enemy
  #-----------------------------------------------------------------------------
  # * Spread State to Friends
  #-----------------------------------------------------------------------------
  def spread_state_to_friends(state)
    $game_troop.enemies.each  {|e| e.add_state(state) if state.spread_success?}
  end
  #-----------------------------------------------------------------------------
  # * Spread State to Foes
  #-----------------------------------------------------------------------------
  def spread_state_to_foes(state)
    $game_party.actors.each   {|a| a.add_state(state) if state.spread_success?}
  end
end

Instructions

Just below Scene_Debug, above main.

I put some default settings in there, just to show you how to set it up.

Compatibility

Should work with or without SDK. While it was written in XP, if it happens to work in VX or VX Ace let me know and I'll fix the topic.

Credits and Thanks

Free for commercial and non-commercial use, so long as you remember to give credit ;D

Author's Notes

I normally test my scripts before posting, but I have not tested this one as I'm drafting up my CBS right now. If you run into any problems, let me know in this thread and I will see what I can do to fix them.
[Image: Button-BOTB.png]
[Image: Save-Point.gif][Image: Button-You-Tube2.png][Image: Button-Sound-Cloud2.png][Image: Button-Audio-Mack2.png]
[Image: LS-Banner.gif]
NEW ALBUM OUT NOW!

Reply }
#2
what are states spread? :3
~SAVE-POINT~
[Image: SP1-Mapper.png]
Reply }
#3
I wrote an example in the introduction but I'll write you another one.

You were exclusively inflicted with the Black Plague by a nasty monster, but the rest of your friends are fine. As time goes on, the monster who attacked with this state has already been killed, you're the only one who is suffering from it. Oh no, you just noticed somebody else got the state too, now your friend is sick as well!

^Thats basically what this script does, it causes states to spread from one fighter to the next. Just as some states automatically go away with time, some of these states will appear on your friends if you don't treat it right away.
[Image: Button-BOTB.png]
[Image: Save-Point.gif][Image: Button-You-Tube2.png][Image: Button-Sound-Cloud2.png][Image: Button-Audio-Mack2.png]
[Image: LS-Banner.gif]
NEW ALBUM OUT NOW!

Reply }


Possibly Related Threads…
Thread Author Replies Views Last Post
   KDamage States XP kyonides 0 1,070 06-29-2023, 02:20 AM
Last Post: kyonides
   Kolloseum States XP kyonides 55 73,594 02-26-2019, 08:28 AM
Last Post: kyonides
   Unalterable States DerVVulfman 0 4,316 01-22-2019, 01:04 AM
Last Post: DerVVulfman
   States : Expiration States Kain Nobel 1 6,816 01-26-2017, 09:45 PM
Last Post: Noctis
   DVV's States Rotation DerVVulfman 5 10,181 04-21-2016, 05:41 AM
Last Post: DerVVulfman
   Tiered States MechanicalPen 10 18,590 08-08-2013, 03:36 AM
Last Post: Karindanslav
   States : Toggle Kain Nobel 0 5,032 10-09-2012, 05:22 PM
Last Post: Kain Nobel
   States : Spread Kain Nobel 0 4,865 10-09-2012, 05:04 PM
Last Post: Kain Nobel
   Kristina's Map States DerVVulfman 1 6,270 06-30-2010, 09:33 AM
Last Post: Nadim
   States Activation System aka State-Based Passive Augments, Version 0.2 Charlie Fleed 7 13,113 03-06-2010, 09:26 PM
Last Post: fgsfds



Users browsing this thread: 1 Guest(s)