RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
Luck

0 Members and 1 Guest are viewing this topic.

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Best Member2012 Best RPG Maker User (Scripting)2012 Favorite Staff Member2012 Most Mature MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
Luck Stat
Version: 1.0a
Author: modern algebra
Date: Easter Sunday, 2011

Version History


  • <Version 1.0a> 04.24.2011 - This fixes a small error where it wasn't averaging party luck but simply sending the sum
  • <Version 1.0> 04.24.2011 - Original Release

Description


This script introduces a luck stat which essentially modifies the chances for any relevant random event that happens in RMVX. As such, it affects hit rate, evasion, critical hit rate, the probability of a state being contracted and letting go (when that is given a probability), what items will drop at the end of battle, and also how much gold will drop. If you are using TDS's Weapon Unleash (and have it above the luck script in the Script Editor), then it will also affect the probability of unleashing.

Features

  • Adds a new luck stat
  • Affects pretty much every (relevant) random thing that happens in RMVX
  • Shows up in the Status and Equip scenes, if you so desire
  • Control its growth curve by actor, just like any other stat

Screenshots



Instructions

Paste the script into its own slot in the Script Editor, somewhere above Main but below Materials and any other custom scripts you may be using. For instructions on configuration, please see the header of the script and the Editable Region.

Script


Code: [Select]
#==============================================================================
#    Luck Stat
#    Version: 1.0a
#    Author: modern algebra (rmrk.net)
#    Date: Easter Sunday, 2011
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Description:
#
#   Chances are you've never thought about this, but there are a lot of random
#  things going on in RMVX. Which items drop when you kill monsters; if states
#  are applied or released; whether you hit or miss or evade or land a critical
#  hit, all of these things are random. This script adds a new statistic which
#  is intended to modify the chances of these various things happening: Luck!
#  It also makes gold drop amounts random and affects that as well.
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Instructions:
#
#   In order to add this script to your game, simply paste it into it its own
#   slot in the Script Editor (F11) above Main but below other custom scripts.
#
#   Roll on down to line 77 for more detailed configuration, but in brief:
#  line 79 is where you change the label for the stat. You can set whether it
#  is shown in the Status scene at line 80 (and where at lines 81 and 83). To
#  see it in the Equip scene, you can set line 88 to true. The most important
#  one is at line 91, where you set the growth for the luck stat of each actor.
#
#   There are also a number of note tags you can use. For any item or state,
#  you can use the following codes (where x and y are integers):
#        \luck[x]
#        \luck[y%]
#  The first adds x directly to the actor's luck, while the second adds that
#  percentage of the actor's total current luck to itself. For weapons and
#  armors, this will happen immediately and only for as long as the armor is
#  equipped. They can also be combined and then the equipment will add (y% + x)
#  luck to the actor when it is equipped. For items, the luck will be added
#  permanently once the item us used, just like for the regular stats. For
#  states, the luck changes will only apply so long as the state is applied. As
#  well for states, you can set a tag to identify whether the state has a
#  positive or negative effect. This is so your luck stat can make it more
#  likely to contract the positive states and less likely to contract the
#  negative ones. In order to identify a state as positive, use this:
#        \positive
#  If not identified as positive, it will assume the state is negative.
#
#   In terms of how this stat should affect how you plan out the game, the stat
#  is intended to be used at lower values - it can work for higher values as
#  well, but it will generally become less effective. The easiest way to think
#  of the stat is as the chance to get more chances. So, if an actor has 50
#  luck and a 4% chance to critical, the Luck stat is a 50% chance to get
#  another 4% chance to critical if you miss the first time. When your luck
#  goes over 100, then you will automatically get a second chance and the
#  remainder is the chance to have a third chance (or fourth, fifth, etc...).
#  So if luck is 225, then it would be three chances at 4% and a 25% chance to
#  have a fourth chance. It affects gold differently. For that, it simply takes
#  the mean average of the party's luck and you randomly get somewhere between
#  0 and that percentage extra gold. So if the gold drop would be 70 and your
#  party has an average luck of 50, then you would get anywhere between 70 and
#  105 gold.
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Compatibility:
#    TDS Weapon Unleash - This script should function and modify the chance to
#      unleash. Must place Luck below Weapon Unleash though
#    MA Note Editor - this will work with the Note Editor as long as you have
#      the note editor's general compatibility patch and it's above this script
#    MA FSCMS - The Luck Stat will show up in the Status window
#    YEM Status Menu - You can set the icon at line 124 and the stat should
#     show up in the scene, but it will be cut off if there isn't room for it.
#    YEM Equipment Overhaul - You can set the icon at line 124 and the luck
#     stat should show up, but it will be cut off if there isn't room for it.
#    Others - There shouldn't be errors as long as the Luck script is below
#      them, but it might not function exactly as expected if those scripts
#      vastly alter battles or change the status or equip scenes. If you notice
#      anything odd, please post in my topic and I will try to help.
#==============================================================================

#\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
#    EDITABLE REGION
#||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
MALS_VOCAB_LUCK = "LUK" # The label to identify the stat in Status and Equip
MALS_STATUS_SHOW = true # Whether to show Luck in Status
MALS_STATUS_X = -1      #  The x position of luck in the status window. When -1,
                        # it will be at the same x as the other parameters
MALS_STATUS_Y = -1      #  The y position of luck in the status window. When -1,
                        # it will be just below other stats. If more negative,
                        # it will be below the other stats + the absolute value
                        # of this. This is so you can reposition it if you have
                        # other added stats.
MALS_EQUIP_SHOW = true  #  Whether to show Luck in the Equip Scene. This will
                        # likely not work with anything but the default scene
                        # and YEM Equip Menu
MALS_LUCK_GROWTH = { # <- Do not touch
#  MALS_LUCK_GROWTH - this is where you can set the level growth of the luck
# for every actor. You can do it in a few ways: either by an array where you
# set it individually for each level, or by a formula encapsulated in quotation
# marks. The 0 => line will be the default growth if you don't set a specific
# one for the actor, while each subsequent line (1 =>; 2 =>) will be the growth
# for the actor with that ID. Remember to put a comma at the end of each.
#   EXAMPLES:
#     0 => "4 * level / 3",
#       This is the default growth and it will mean the actor gains 1 luck
#      every level and 2 every third level.
#     8 => "3 + (level*2)",
#       This would be the growth for Actor 8 and he or she would start out with
#      5 luck and gain 2 more every level.
#     5 => [5, 6, 8, 9, 10, 12, 13, 14, 16, 17, 18, 20, 22, 23, 25, 26, 28, 29,
#           30, 32, 33, 35, 36, 38, 39, 41, 42, 44, 45, 47, 47, 48, 50, 51, 52,
#           54, 55, 56, 58, 59, 61, 62, 64, 65, 67, 68, 69, 71, 73, 74, 75, 76,
#           77, 79, 80, 81, 82, 84, 86, 87, 88, 90, 91, 92, 94, 95, 96, 98, 100,
#           101, 102, 104, 105, 107, 110, 111, 112, 114, 116, 117, 118, 120,
#           121, 121, 124, 126, 127, 128, 129, 131, 132, 134, 136, 139, 140,
#           142, 143, 145, 148],
#       This would be the growth for actor 5 and he or she would start with 5
#      luck at level 1 and would have the set amount at each level (so 6 at
#      level 2, 8 at level 3, 9 at level 4, etc...)
  0 => "4 * level / 3",
  2 => "4 + (level / 4)",
  8 => [5, 6, 8, 9, 10, 12, 13, 14, 16, 17, 18, 20, 22, 23, 25, 26, 28, 29, 30,
        32, 33, 35, 36, 38, 39, 41, 42, 44, 45, 47, 47, 48, 50, 51, 52, 54, 55,
        56, 58, 59, 61, 62, 64, 65, 67, 68, 69, 71, 73, 74, 75, 76, 77, 79, 80,
        81, 82, 84, 86, 87, 88, 90, 91, 92, 94, 95, 96, 98, 100, 101, 102, 104,
        105, 107, 110, 111, 112, 114, 116, 117, 118, 120, 121, 121, 124, 126,
        127, 128, 129, 131, 132, 134, 136, 139, 140, 142, 143, 145, 148],
} # <- DO not touch
MALS_LUCK_ICON = 103    # This is icon for Luck if you are using YEM scripts
#||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
#    END EDITABLE REGION
#//////////////////////////////////////////////////////////////////////////////
MALS_LUCK_GROWTH.default = MALS_LUCK_GROWTH[0] # <- Do not touch

$imported = {} unless $imported
$imported["LuckStat"] = true

#==============================================================================
# *** RPG
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    modified classes - BaseItem; State; Actor; Enemy
#==============================================================================

module RPG

#============================================================================
# ** BaseItem
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    new method - luck; luck_rate
#============================================================================

class BaseItem
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Luck
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def luck
    @luck = (self.note[/\\LUCK\[(-?\d+)\]/i] != nil ? $1.to_i : 0) if !@luck
    return @luck
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Luck Rate
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def luck_rate
    @luck_rate = (self.note[/\\LUCK\[(-?\d+)%\]/i] != nil ? $1.to_f / 100.0 : 0) if !@luck_rate
    return @luck_rate
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Compatibility with Note Editor
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  if self.method_defined? (:ma_reset_note_values)
    alias mlg_luk_rstnotes_4rf2 ma_reset_note_values
    def ma_reset_note_values (*args)
      mlg_luk_rstnotes_4rf2 (*args)
      @luck = nil
      @luck_rate = nil
    end
  end
end

#============================================================================
# ** State
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    new method - luck; luck_rate
#    aliased method - auto_release_prob
#============================================================================

class State
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Luck
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def luck
    @luck = (self.note[/\\LUCK\[(-?\d+)\]/i] != nil ? $1.to_i : 0) if !@luck
    return @luck
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Luck Rate
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def luck_rate
    @luck_rate = (self.note[/\\LUCK\[(-?\d+)%\]/i] != nil ? $1.to_f / 100.0 : 0) if !@luck_rate
    return @luck_rate
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Positive State?
  #    This allows you to specify some states as positive, thus meaning luck
  #   will favourably influence its application instead of unfavourably
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def positive_state?
    @positivity = self.note[/\\POSITIVE/i] != nil if @positivity == nil
    return @positivity
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Auto Release Probability
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias ma_lk_autorel_5tc7 auto_release_prob unless self.method_defined? (:ma_lk_autorel_5tc7)
  def auto_release_prob (*args)
    prob = ma_lk_autorel_5tc7 (*args)
    if $game_temp && positive_state?
      prob = 2*prob - $game_temp.luck_prob (prob)
    else
      prob = $game_temp.luck_prob (prob)
    end
    return prob
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Compatibility with Note Editor
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  if self.method_defined? (:ma_reset_note_values)
    alias mlg_luk_rstnotes_4rf2 ma_reset_note_values
    def ma_reset_note_values (*args)
      mlg_luk_rstnotes_4rf2 (*args)
      @luck = nil
      @luck_rate = nil
      @positivity = nil
    end
  end
end

#==============================================================================
# ** Actor
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    new method - luck
#==============================================================================

class Actor
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Luck
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def luck (level)
    @luck_base = [] if !@luck_base
    if @luck_base[level] == nil
      growth = MALS_LUCK_GROWTH[self.id]
      if growth.is_a? (Array)
        @luck_base[level] = growth[[level - 1, growth.size - 1].min]
      else
        eval ("@luck_base[level] = #{growth}")
      end
    end
    return @luck_base[level]
  end
end

#==============================================================================
# ** Enemy
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    new method - luck
#    modified class - DropItem
#==============================================================================

class Enemy
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Luck
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def luck
    @luck = (self.note[/\\LUCK\[(-?\d+)\]/i] != nil ? $1.to_i : 0) if @luck == nil
    return @luck
  end
 
  #==========================================================================
  # ** DropItem
  #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  #  Summary of Changes:
  #    aliased method - denominator
  #==========================================================================
 
  class DropItem
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # * Denominator
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    alias mlgb_luk_denmn_4rt2 denominator unless self.method_defined? (:mlgb_luk_denmn_4rt2)
    def denominator (*args)
      denom = mlgb_luk_denmn_4rt2 (*args) # Run Original Method
      percent = $game_temp.luck_prob (100 / denom)
      return (100.0 / percent).round
    end
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Compatibility with Note Editor
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  if self.method_defined? (:ma_reset_note_values)
    alias mlg_luk_rstnotes_4rf2 ma_reset_note_values
    def ma_reset_note_values (*args)
      mlg_luk_rstnotes_4rf2 (*args)
      @luck_base = []
    end
  end
end

#==============================================================================
#  TDS Weapon Unleash Compatibility
#==============================================================================
class Weapon
  if self.method_defined? (:unleash_info)
    alias ma_luk_com_wpnunls_8ib3 unleash_info
    def unleash_info (*args)
      array = ma_luk_com_wpnunls_8ib3 (*args)
      array[1] = $game_temp.luck_prob (array[1]) if array && $game_temp
      return array
    end
  end
end

end

#==============================================================================
# *** Vocab
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    new method - luck
#==============================================================================

module Vocab
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Luck
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def self.luck
    return MALS_VOCAB_LUCK
  end
end

#==============================================================================
# ** Game_Temp
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    new accessor - luck_mod
#    aliased method - initialize
#==============================================================================

class Game_Temp
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Public Instance Variables
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  attr_accessor :luck_mod
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Object Initialization
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias mrgb_lc_iniz_1wd9 initialize
  def initialize (*args)
    mrgb_lc_iniz_1wd9 (*args) # Run Original Method
    @luck_mod = 0
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Luck Probability
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def luck_prob (prob, luck = @luck_mod)
    return prob if prob == 100 || luck <= 0
    t = luck / 100
    t += 1 if rand (100) < (luck % 100)
    return t == 0 ? prob : ((1.0 - (((100 - prob).to_f / 100.0)**(t + 1))) * 100).to_i
  end
end

#==============================================================================
# ** Game_Battler
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    aliased methods - clear_extra_values; item_growth_effect; item_test;
#      remove_states_auto; make_attack_damage_value; calc_hit; calc_eva
#    new method - luck; luck=
#==============================================================================

class Game_Battler
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Object Initialization
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias malg_luck_clrexvals_5yq1 clear_extra_values
  def clear_extra_values (*args)
    malg_luck_clrexvals_5yq1 (*args) # Run Original Method
    @luck_plus = 0
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Item Growth Effect Application
  #     user : Item user
  #     item : item
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias modrna_itmgrowth_eff_6yh4 item_growth_effect
  def item_growth_effect(user, item, *args)
    modrna_itmgrowth_eff_6yh4 (user, item, *args)
    @luck_plus += item.luck + (item.luck_rate*self.luck)
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Item Test
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias mdlg_luc_itmtst_5rx2 item_test
  def item_test(user, item, *args)
    return true if item.luck != 0 || item.luck_rate != 0
    return mdlg_luc_itmtst_5rx2 (user, item, *args)
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Auto Remove States
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias odagb_lck_rmvautostt_6jn2 remove_states_auto
  def remove_states_auto (*args)
    $game_temp.luck_mod = self.luck
    odagb_lck_rmvautostt_6jn2 (*args) # Auto Remove States
    $game_temp.luck_mod = 0
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Make Attack Damage Value
  #    do luck_mod here instead of cri so as not to corrupt the general stat
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias mlg_luck_dmg_atk_9uc4 make_attack_damage_value
  def make_attack_damage_value (attacker, *args)
    $game_temp.luck_mod = attacker.luck
    mlg_luck_dmg_atk_9uc4 (attacker, *args) # Run Original Method
    $game_temp.luck_mod = 0
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Calculation of Final Hit Ratio
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias maba_luk_htclc_7uz3 calc_hit
  def calc_hit (user, *args)
    hit = maba_luk_htclc_7uz3 (user, *args)
    return $game_temp.luck_prob (hit, user.luck)
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Calculate Final Evasion Rate
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias malgbr_lck_clceva_3da7 calc_eva
  def calc_eva(user, *args)
    eva = malgbr_lck_clceva_3da7 (user, *args)
    return $game_temp.luck_prob (eva, self.luck)
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Luck
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def luck
    n = [[base_luck + @luck_plus, 1].max, 999].min
    floats = 1.0
    for state in states
      floats += state.luck_rate
      n += state.luck_rate
    end
    n *= floats
    n = [[Integer(n), 1].max, 999].min
    return n
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Set Luck
  #    new_luck : the new value of luck
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def luck= (new_luck)
    @luck_plus += new_luck - self.luck
    @luck_plus = [[@luck_plus, -999].max, 999].min
  end
  #==========================================================================
  #  TDS Weapon Unleash Compatibility
  #==========================================================================
  if self.method_defined? (:weapon_unleash?)
    alias ma_lk_cmp_tdswu_5th1 weapon_unleash?
    def weapon_unleash? (*args)
      $game_temp.luck_mod = luck
      v = ma_lk_cmp_tdswu_5th1 (*args)
      $game_temp.luck_mod = 0
      return v
    end
  end
end

#==============================================================================
# ** Game_Actor
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    aliased method - state_probability; cri
#    new method - base_luck
#==============================================================================

class Game_Actor
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Get Basic Luck
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def base_luck
    n = actor.luck (@level)
    floats = 1.0
    for equip in equips.compact
      floats += equip.luck_rate
      n += equip.luck
    end
    n = (n*floats).to_i
    return n
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * State Probability
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias mag_luck_probstate_8id2 state_probability
  def state_probability (state_id, *args)
    default = mag_luck_probstate_8id2 (state_id, *args)
    $game_temp.luck_mod = luck
    if $data_states[state_id].positive_state?
      return $game_temp.luck_prob (default)
    else
      return 2*default - ($game_temp.luck_prob (default))
    end
    $game_temp.luck_mod = 0
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Critical
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias malg_luk_cri_7uk9 cri
  def cri (*args)
    return $game_temp.luck_prob (malg_luk_cri_7uk9 (*args))
  end
end

#==============================================================================
# ** Game_Enemy
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    aliased method - state_probability
#    new method - base_luck
#==============================================================================

class Game_Enemy
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Get Basic Luck
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def base_luck
    return enemy.luck
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * State Probability
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias mag_luck_stateprob_4tg2 state_probability
  def state_probability (state_id, *args)
    default = mag_luck_stateprob_4tg2 (state_id, *args)
    $game_temp.luck_mod = luck
    if $data_states[state_id].positive_state?
      return $game_temp.luck_prob (default)
    else
      return 2*default - ($game_temp.luck_prob (default))
    end
    $game_temp.luck_mod = 0
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Critical
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias malg_lck_crit_2wq1 cri
  def cri (*args)
    return $game_temp.luck_prob (malg_lck_crit_2wq1 (*args))
  end
end

#==============================================================================
# ** Game_Unit
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    new method - luck_average
#==============================================================================

class Game_Unit
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Average Luck
  #    This takes the mean of the party member's luck for gold & item drop %
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def luck_average
    luck = 0
    existing_members.each { |actor| luck += actor.luck }
    return (luck / [1, existing_members.size].max)
  end
end

#==============================================================================
# ** Game Troop
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    aliased methods - gold_total; make_drop_items
#==============================================================================

class Game_Troop
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Gold Total
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias mrgba_luk_glddrop_7uj1 gold_total
  def gold_total (*args)
    total = mrgba_luk_glddrop_7uj1 (*args)
    total += rand (1 + (total * ($game_party.luck_average / 100.0)).to_i)
    return total
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Make Drop Items
  #    luck_mod done here to avoid corrupting denominator
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias mgba_luk_dropitms_8fv2 make_drop_items
  def make_drop_items (*args)
    $game_temp.luck_mod = $game_party.luck_average
    v = mgba_luk_dropitms_8fv2 (*args)
    $game_temp.luck_mod = 0
    return v
  end
end

#==============================================================================
# ** Window_Status
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    aliased method - draw_parameters
#==============================================================================
if MALS_STATUS_SHOW
  class Window_Status
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # * Draw Parameters
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    alias ma_luk_drwparams_2fg4 draw_parameters
    def draw_parameters (x, y, *args)
      ma_luk_drwparams_2fg4 (x, y, *args)
      x = MALS_STATUS_X if MALS_STATUS_X != -1
      y = (MALS_STATUS_Y != -1 ? MALS_STATUS_Y : y + WLH*4 + MALS_STATUS_Y.abs - 1)
      self.contents.font.color = system_color
      self.contents.draw_text(x, y, 120, WLH, Vocab::luck)
      self.contents.font.color = normal_color
      self.contents.draw_text(x + 120, y, 36, WLH, @actor.luck, 2)
    end
  end
end

if MALS_EQUIP_SHOW
  #============================================================================
  # ** Window_EquipStatus
  #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  #  Summary of Changes:
  #    modified_constant - WLH
  #    aliased method - refresh
  #    new method - set_luck
  #============================================================================
  class Window_EquipStatus
    WLH = 20
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # * Set Luck
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    def set_luck (new_luck)
      if @new_luck != new_luck
        @new_luck = new_luck
        refresh
      end
    end
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # * Refresh
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    alias mdrn_luk_eqpref_7us6 refresh
    def refresh (*args)
      if self.contents.height < 120
        self.height = 152
        create_contents
      end
      mdrn_luk_eqpref_7us6 (*args)
      self.contents.font.color = system_color
      self.contents.draw_text(4, WLH*5, 80, WLH, Vocab::luck)
      self.contents.font.color = normal_color
      self.contents.draw_text(90, WLH*5, 30, WLH, @actor.luck, 2)
      self.contents.font.color = system_color
      self.contents.draw_text(122, WLH*5, 20, WLH, ">", 1)
      if @new_luck != nil
        self.contents.font.color = new_parameter_color(@actor.luck, @new_luck)
        self.contents.draw_text(142, WLH*5, 30, WLH, @new_luck, 2)
      end
    end
  end
 
  #============================================================================
  # ** Scene Equip
  #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  #  Summary of Changes:
  #    aliased method
  #============================================================================
 
  class Scene_Equip
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # * Update Status Window
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    alias malg_luck_updstatwin_6yh3 update_status_window
    def update_status_window (*args)
      if @equip_window.active
        @status_window.set_luck (nil)
      elsif @item_window.active
        temp_actor = @actor.clone
        temp_actor.change_equip(@equip_window.index, @item_window.item, true)
        @status_window.set_luck (temp_actor.luck)
      end
      malg_luck_updstatwin_6yh3 (*args)
    end
  end
end

#==============================================================================
# YEM COMPATIBILITY
#==============================================================================

#  Status Menu Melody
if $imported["StatusMenuMelody"] && MALS_STATUS_SHOW
  #==========================================================================
  # ** Window Status General
  #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  #  Summary of Changes:
  #    aliased method - draw_parameters
  #==========================================================================
  class Window_Status_General
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # * Draw Parameters
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    alias mlgb_luk_drwparams_6yv2 draw_parameters
    def draw_parameters (x, y, *args)
      mlgb_luk_drwparams_6yv2 (x, y, *args)
      x += 24
      x = MALS_STATUS_X if MALS_STATUS_X != -1
      y = (MALS_STATUS_Y != -1 ? MALS_STATUS_Y : y + (WLH*(2 + YEM::STATUS::SHOWN_STATS.size)) + MALS_STATUS_Y.abs - 1)
      draw_icon(MALS_LUCK_ICON, x, y)
      self.contents.font.color = system_color
      self.contents.draw_text(x + 24, y, 48, WLH, Vocab::luck)
      self.contents.font.color = normal_color
      self.contents.draw_text(x + 72, y, 84, WLH, @actor.luck, 2)
    end
  end
end
#  Equipment Overhaul
if $imported["EquipmentOverhaul"] && MALS_EQUIP_SHOW
  #==========================================================================
  # ** Window EquipStat
  #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  #  Summary of Changes:
  #    aliased methods - draw_actor_stats; draw_clone_stats
  #==========================================================================
  class Window_EquipStat
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # * Draw Actor Stats
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    alias modrn_yemequip_drwactrstats_8uf2 draw_actor_stats
    def draw_actor_stats (*args)
      modrn_yemequip_drwactrstats_8uf2 (*args) # Run Original Method
      dy = WLH*YEM::EQUIP::SHOWN_STATS.size
      draw_icon(MALS_LUCK_ICON, 0, dy)
      self.contents.font.size = YEM::EQUIP::STAT_FONT_SIZE
      self.contents.font.color = system_color
      self.contents.draw_text(24, dy, 60, WLH, Vocab.luck, 0)
      self.contents.font.color = normal_color
      self.contents.draw_text(84, dy, 45, WLH, @actor.luck, 2)
      self.contents.font.color = system_color
      self.contents.font.size = Font.default_size
      self.contents.draw_text(129, dy, 30, WLH, YEM::EQUIP::VOCAB[:arrow], 1)
      if @equip_index == nil or (@equip != nil and !@actor.equippable?(@equip))
        self.contents.font.size = YEM::EQUIP::STAT_FONT_SIZE
        self.contents.font.color = normal_color
        self.contents.draw_text(159, dy, 45, WLH, @actor.luck, 2)
      end
    end
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # * Draw Clone Stats
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    alias modrn_yemequip_luk_clnst_5tb9 draw_clone_stats
    def draw_clone_stats (*args)
      modrn_yemequip_luk_clnst_5tb9 (*args) # Run Original Method
      dy = WLH*YEM::EQUIP::SHOWN_STATS.size
      if @clone.luck > @actor.luck
        self.contents.font.color = power_up_color
      elsif @clone.luck < @actor.luck
        self.contents.font.color = power_down_color
      else
        self.contents.font.color = normal_color
      end
      self.contents.font.size = YEM::EQUIP::STAT_FONT_SIZE
      self.contents.draw_text(159, dy, 45, WLH, @clone.luck, 2)
    end
  end
end
You can also retrieve it from Pastebin

Addons

Spoiler for Luck-influenced Variable:
This is an ADDON to the script. You need the main script above.
What this does is allow you to apply the formula so as to influence the value of a variable. It can thus influence the drop of chests and other stuff like that. You need to upgrade to v. 1.0a to use this addon (if you only have v. 1.0). Otherwise you will probably get a NoMethod error when you try to use :troop. Without further ado, the addon is:

Code: [Select]
#==============================================================================
#    Luck-influenced Variable
#      Addon to Luck Stat 1.0a
#    Version: 1.0
#    Author: modern algebra
#    Date: May 3, 2011
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Description:
#
#    This script just adds an easy code to set a variable to a random number
#   influenced by the luck of the party, an individual actor, an individual
#   enemy, or the enemy troop. This will allow you to create, for instance,
#   random treasure chests that give a better chance for better loot depending
#   on the party's luck.
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Instructions:
#
#    Paste this script above Main and below Materials in the Script Editor. Use
#   one of the following codes in a script call:
#
#        variable_luck (variable_ID, base, :type, id)
#          variable_ID : the ID of the variable you want it set to
#          base  : the basic probability you want it to modify.
#          :type : This is what you are checking. It can be one of four
#            :party - this will take the luck of the actor in the position
#              identified by id. Ie, if id is 0, it would use the leader's
#              luck. If id is excluded, it takes the average luck of the party
#            :troop - this will take the luck of the enemy in the position
#              identified by id. Ie, if id is 2, it would use the third enemy's
#              luck. If id is excluded, it takes the average luck of the troop
#            :actor - this will take the luck of the actor with id. Ie, if id
#              is 1, then it takes the luck of the first actor in the database.
#            :enemy - this will take the luck of the enemy with id. Ie, if id
#              is 5, it takes the luck of the fifth enemy in the database.
#          id   : the relevance of id depends on the :type chosen, so read them
#            to figure it out. Note that it can be excluded if you want the
#            average luck for :party or :troop
#
#    EXAMPLES:
#      variable_luck (4, 8, :actor, 3)
#        This modifies the 8 based on the luck of Actor 3. It is then saved in
#       Variable 4.
#      variable_luck (7, 10, :party)
#        This modifies 10 based on the average luck of the party. It is then
#       saved in Variable 7.
#      variable_luck (6, 5, :troop, 0)
#        This modifies 10 based on the luck of the first member of the enemy
#       troop. It is then saved in Variable 6.
#
#    The best way to use this is in an event such as the following:
#  @>Script: variable_luck (1, 8, :party)
#  @>Control Variables: [0002: Random] = Random No. 0...100
#  @>Conditional Branch: Variable [0002: Random] < Variable [0001: Chance]
#      @>   Successful
#   : Else
#      @>   Not Successful
#   : Branch End
#==============================================================================

#==============================================================================
# ** Game_Interpreter
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    new method - variable_luck
#==============================================================================

class Game_Interpreter
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Variable Luck
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def variable_luck (variable_id, base, type, aid = -1)
    mod = case type
    when :party then aid == -1 ? $game_party.luck_average : $game_party.members[aid].luck
    when :actor then $game_actors[aid].luck
    when :enemy then $data_enemies[aid].luck
    when :troop then aid == -1 ? $game_troop.luck_average : $game_troop.members[aid].luck
    end
    $game_variables[variable_id] = $game_temp.luck_prob (base, mod)
  end
end

Credit


  • modern algebra

Support


Please post in this topic at RMRK for support or suggestions, no matter how old this topic is. Do not PM me.

Known Compatibility Issues

There shouldn't be too many scripts which would cause errors, but the stat may not function properly with some exotic battle systems, status scenes, or equip scenes. The script is, however, designed to work with my FSCMS, Note Editor, YEM Status Menu and Equipment Overhaul (though it may be cut off if too many stats are already shown), and it should affect the possibility of unleashing if you are using TDS's Weapon Unleash script. All of the above scripts must be placed above the Luck stat in the Script Editor, as should any other custom script.
« Last Edit: May 03, 2011, 07:59:03 PM by modern algebra »

pokeball TDSOffline
***
Rep:
Level 84
-T D S-
Silver - GIAW 11 (Hard)Silver - Game In A Week VII
Very good script modern algebra.

And thank you for making it compatible with one of mine.

Just one question though.

How did you make it compatible with the weapon unleash method?

Code: [Select]
  if self.method_defined? (:weapon_unleash?)
    alias ma_lk_cmp_tdswu_5th1 weapon_unleash?
    def weapon_unleash? (*args)
      $game_temp.luck_mod = luck
      v = ma_lk_cmp_tdswu_5th1 (*args)
      $game_temp.luck_mod = 0
      return v
    end
  end
end

I keep looking at the code, but it I just can't figure it out.

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Best Member2012 Best RPG Maker User (Scripting)2012 Favorite Staff Member2012 Most Mature MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
Well, in that method in your script, the conditional branch which determines whether the skill is unleashed is:

Code: [Select]

    unleash_info = weapon.unleash_info
    # Return false if unleash info is nil
    return false if unleash_info == nil
    # If Unleash Rate is more than a random number from 0-100%
    if (rand(100) < unleash_info[1])
      # Set Weapon Unleash Skill
      @action.set_skill(unleash_info[0])
      # Return true
      return true
    end

So, all I really did to that method was simply identify which actor it was by setting his/her luck to a variable in $game_temp so that when the interpreter reaches that conditional branch, the value in $game_temp.luck_mod is the particular actor's luck.

Then, in the Weapon class, I included this method:

Code: [Select]
    alias ma_luk_com_wpnunls_8ib3 unleash_info
    def unleash_info (*args)
      array = ma_luk_com_wpnunls_8ib3 (*args)
      array[1] = $game_temp.luck_prob (array[1]) if array && $game_temp
      return array
    end

So, when this method returns the array, it calculates a new probability based on the luck value stored in $game_temp.luck_mod. Thus, when your script is checking:

Code: [Select]
if (rand(100) < unleash_info[1])

unleash_info[1] has actually been modified depending on the luck value of the battler.

It's a pretty roundabout way of doing it, but I didn't want to overwrite anything in your script so that is the way I chose.

pokeball TDSOffline
***
Rep:
Level 84
-T D S-
Silver - GIAW 11 (Hard)Silver - Game In A Week VII
Interesting way of doing it.

I always find myself learning something new from your scripts, and this one had a few things I've been trying to find examples of to learn.

Thank you for your answer and have a nice day.

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Best Member2012 Best RPG Maker User (Scripting)2012 Favorite Staff Member2012 Most Mature MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
I'm glad they can be helpful. This one I felt was a bit of a mess really, since I never really had a defined plan for the script and just made it up as I went along. Plus I have very seldom tried to script specific compatibilities into the script itself - I usually just take general precautions and wait for compatibility requests. It ended up being a lot longer than I had first anticipated.
« Last Edit: April 26, 2011, 12:25:14 AM by modern algebra »

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Best Member2012 Best RPG Maker User (Scripting)2012 Favorite Staff Member2012 Most Mature MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
I created an addon to the script that allows you to use the luck stat to influence the value of a variable. This is useful, for instance, as you can now have luck influence the loot you get from a chest or something similar. It is here:

Code: [Select]
#==============================================================================
#    Luck-influenced variable
#      Addon to Luck Stat 1.0a
#    Version: 1.0
#    Author: modern algebra
#    Date: May 3, 2011
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Description:
#
#    This script just adds an easy code to set a variable to a random number
#   influenced by the luck of the party, an individual actor, an individual
#   enemy, or the enemy troop. This will allow you to create, for instance,
#   random treasure chests that give a better chance for better loot depending
#   on the party's luck.
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Instructions:
#
#    Paste this script above Main and below Materials in the Script Editor. Use
#   one of the following codes in a script call:
#
#        variable_luck (variable_ID, base, :type, id)
#          variable_ID : the ID of the variable you want it set to
#          base  : the basic probability you want it to modify.
#          :type : This is what you are checking. It can be one of four
#            :party - this will take the luck of the actor in the position
#              identified by id. Ie, if id is 0, it would use the leader's
#              luck. If id is excluded, it takes the average luck of the party
#            :troop - this will take the luck of the enemy in the position
#              identified by id. Ie, if id is 2, it would use the third enemy's
#              luck. If id is excluded, it takes the average luck of the troop
#            :actor - this will take the luck of the actor with id. Ie, if id
#              is 1, then it takes the luck of the first actor in the database.
#            :enemy - this will take the luck of the enemy with id. Ie, if id
#              is 5, it takes the luck of the fifth enemy in the database.
#          id   : the relevance of id depends on the :type chosen, so read them
#            to figure it out. Note that it can be excluded if you want the
#            average luck for :party or :troop
#
#    EXAMPLES:
#      variable_luck (4, 8, :actor, 3)
#        This modifies the 8 based on the luck of Actor 3. It is then saved in
#       Variable 4.
#      variable_luck (7, 10, :party)
#        This modifies 10 based on the average luck of the party. It is then
#       saved in Variable 7.
#      variable_luck (6, 5, :troop, 0)
#        This modifies 10 based on the luck of the first member of the enemy
#       troop. It is then saved in Variable 6.
#
#    The best way to use this is in an event such as the following:
#  @>Script: variable_luck (1, 8, :party)
#  @>Control Variables: [0002: Random] = Random No. 0...100
#  @>Conditional Branch: Variable [0002: Random] < Variable [0001: Chance]
#      @>   Successful
#   : Else
#      @>   Not Successful
#   : Branch End
#==============================================================================

#==============================================================================
# ** Game_Interpreter
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    new method - variable_luck
#==============================================================================

class Game_Interpreter
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Variable Luck
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def variable_luck (variable_id, base, type, aid = -1)
    mod = case type
    when :party then aid == -1 ? $game_party.luck_average : $game_party.members[aid].luck
    when :actor then $game_actors[aid].luck
    when :enemy then $data_enemies[aid].luck
    when :troop then aid == -1 ? $game_troop.luck_average : $game_troop.members[aid].luck
    end
    $game_variables[variable_id] = $game_temp.luck_prob (base, mod)
  end
end

You need to upgrade to v. 1.0a to use this addon (if you only have v. 1.0). Otherwise you will probably get a NoMethod error when you try to use :troop.

**
Rep: +0/-0Level 69
RMRK Junior
Sweet script!
Just one question... Is it possible to alter the KGC distribute parameters script so that I can put points into luck? (to be compatible with your luck script)

Thanks!

(I would post the script - but not sure how? It wont let me... It's readily available anyway.)

**
Rep: +0/-0Level 69
RMRK Junior
One other thing... The script gives me a 'stack error is too deep' error.
This this not compatible with tankentai?

**
Rep: +0/-0Level 69
RMRK Junior
Nah I didn't.What causes the 'stack error is too deep' is due to an infinite cycle of processes causing an error.

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Best Member2012 Best RPG Maker User (Scripting)2012 Favorite Staff Member2012 Most Mature MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
True, and that will happen if you have two copies of the same script (if the script aliases anything), but it's not the only cause.

As far as I know, yours is the only complaint of incompatibility with Tankentai but it's possible. Recreate the error in a new project and upload it and I will take a look.

**
Rep: +0/-0Level 69
RMRK Junior
Okay so... Was testing it out and I was 'wrong.' The true error lies with the added actor options. I just didn't understand why it would occur with the added actor options, but here it is..
http://rmrk.net/index.php/topic,39142.0.html

The error happens 'sometimes' in the luck script and other times in the added actor options script. Not sure why it switches back and forth...

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Best Member2012 Best RPG Maker User (Scripting)2012 Favorite Staff Member2012 Most Mature MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
And when does it happen? Do I have to go into a battle, make some event, add one of the new options, etc...? I've tried just starting the game with both scripts and I never received an error. The Luck script should be below the Added Actor Options script by the way, but I don't think that would cause a stack error.

But yeah, tell me exactly what I need to do to hit the error or, better yet, recreate the error in a new project and upload it so I can just play through that.

**
Rep: +0/-0Level 69
RMRK Junior
Go into battle and the first attack on a monster causes the error.
Here you go Modern Algebra. I uploaded it for you!
http://www.mediafire.com/?saz4qpvqc4fn44z
« Last Edit: June 24, 2011, 04:31:31 PM by Verzen »

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Best Member2012 Best RPG Maker User (Scripting)2012 Favorite Staff Member2012 Most Mature MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
It's not an incompatibility - it's an error in the Added Actor Options script. Go to line 296 of that script and you should see:

Code: [Select]
    n = coz_aao_ga_cri cri

Delete the last cri. It should be this:

Code: [Select]
    n = coz_aao_ga_cri

That should fix your problem.

**
Rep: +0/-0Level 69
RMRK Junior
Awesome! Thanks. Works perfectly now!

*
Rep: +0/-0Level 64
RMRK Junior
I really like this script first of all because Luck is such an important stat in rpgs IMO.

I had a question though and I was wondering if anyone could help me, it is in regards to using the script to modify a variable.

What I am trying to do is use it to modify my stealing skill:

Its pretty basic stuff as I am still dipping my toes into RGSS.  It simply uses a common event that utilizes two variables:

0003 (RANDOMGEN) which is a random number between 0-100.  and 0004 (LUCKAPPLY) and then uses your script variable_luck(4,10, :actor, 1)

So it then takes the Random number and adds the luck number and that determines the success rate.  I am still tweaking that particular portion.

My question however is: can I set the actor_id to whatever actor used the skill that called the common event instead of as a predetermined actor ID?  As of right now only one character in my test bed program can use the steal skill but I plan for at least two in my actual game to be able to use it

« Last Edit: November 11, 2011, 08:09:26 PM by Violesnature »

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Best Member2012 Best RPG Maker User (Scripting)2012 Favorite Staff Member2012 Most Mature MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
Well, maybe you could just make two identical steal skills, with the only difference being that the common event of one refers to the first actor and the common event of the other to the second actor. Then just make it so that the first actor only learns the first Steal skill while the second actor learns the second Steal skill.

*
Rep: +0/-0Level 64
RMRK Junior
That certainly works and if thats the way it has to be done it wouldn't be hard.  I was just wondering if there was a way to do it in the script itself and I would assume that there isn't since you already responded :).

I appreciate you taking the time to respond mate.  Guess I'll just go the two common event route.

Mucho Gracias,
Violes