States : Spread - Kain Nobel - 07-10-2012
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.
RE: States : Spread - MiguHideki - 07-10-2012
what are states spread? :3
RE: States : Spread - Kain Nobel - 07-10-2012
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.
|