The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX => VX Scripts Database => Topic started by: modern algebra on April 23, 2011, 12:33:23 AM

Title: Gold Drop Variance
Post by: modern algebra on April 23, 2011, 12:33:23 AM
Gold Drop Variance
Version: 1.0
Author: modern algebra
Date: April 22, 2011

Version History




Description



Gold drops in RMVX are static by default, with every creature always dropping the exact same amount every time you kill them. This script allows you to change that by making them drop a random amount between values that you choose.

Features


Instructions

Paste this script into its own slot in the Script Editor (F11), above Main but below any other custom scripts. For instructions on how to use it, please see the header of the script.

Script




#==============================================================================
#    Gold Drop Variance
#    Version: 1.0
#    Author: modern algebra (rmrk.net)
#    Date: April 22, 2011
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Description:
#
#    Gold drops in RMVX are static by default, with every creature always
#   dropping the exact same amount every time you kill them. This script allows
#   you to change that by making them drop a random amount between values that
#   you choose.
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Instructions:
#
#    Paste this script into its own slot in the Script Editor (F11), above Main
#   and below other custom scripts.
#
#    To set this script up, go to line 42 and set the default variance. That is
#   the default amount the gold drops could vary by when you kill a monster. If
#   you want it so that the variance is different for specific monsters, then
#   all you need to do is put the following code in those monster's note box:
#
#        \var_gold[x]
#
#   Where x is the integer you want the drop to vary by. That will set it so
#   that the drop for that monster will vary between the normal drop and the
#   normal drop + x. So, if it is 10 and the enemy is set to 20, then it will
#   drop between 20 and 29 gold. You could also set it by percent with the code:
#
#        \var_gold[y%]
#   
#   Where y is the percent you want it to vary by. That will set it so the
#   monster will drop between the normal drop and the normal drop + y%. So, if
#   it is set to 25 and the enemy is set to 20, then it will drop between 20 and
#   24 gold (since 25% of 20 is 5).
#
#   If you want to change the note box code, go to line 50.
#==============================================================================
#\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
#    EDITABLE REGION
#||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
#  MAGDV_DEFAULT_VARIANCE - This is the default amount gold drops will vary by.
# If it is an integer, then it will vary between the set amount and this. If
# you make it a float (20.0 rather than 20), then it will vary by that percent
# of the set amount (ie. if the set amount is 160 and this value is set to 20.0,
# then the amount dropped will be between 160 and 191. (since 20% of 160 is 32)
# If you want some enemies to have a different variance, you just need to tag
# it in their noteboxes (see lines 19 - 35).
MAGDV_DEFAULT_VARIANCE = 20.0
#  MAGDV_REGEXP - You shouldn't need to modify this; all this does is allow you
# to change the notebox code which you can use to change the specific variance
# for enemies. The default value is "VAR_GOLD", meaning the code \var_gold[x]
# will be the notebox code. If you change it to "VG", for instance, the code
# would be \vg[x]. It is up to you.
MAGDV_REGEXP = "VAR_GOLD"
#||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
#    END EDITABLE REGION
#//////////////////////////////////////////////////////////////////////////////

$imported = {} if !$imported
$imported["MAGoldDropVariance"] = true

#==============================================================================
# ** RPG::Enemy
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    aliased method - gold
#==============================================================================

class RPG::Enemy
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Gold
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias mlgb_luk_gld_9og1 gold unless self.method_defined? (:mlgb_luk_gld_9og1)
  def gold (*args, &block)
    gld = mlgb_luk_gld_9og1 (*args, &block) # Run Original Method
    add = gold_variance
    if add.is_a? (Float)
      add = ((gld*add) / 100).to_i
    end
    return gld + (rand (add))
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Gold Variance
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def gold_variance
    if !@gold_variance
      @gold_variance = MAGDV_DEFAULT_VARIANCE
      if self.note[/#{MAGDV_REGEXP}\[(\d+)(%?)\]/i] != nil
        @gold_variance = $2.empty? ? $1.to_i : $1.to_f
      end
    end
    return @gold_variance
  end
end


Credit




Support



If you have any suggestions or need support for this script, please post in this thread on RMRK, no matter how old it is. I will do my best to assist you.

Author's Notes



This is the first script I decided to use the $imported convention. It's also probably the least likely to ever need special compatibility measures taken for it. Oh well! It's a good idea to use it and I probably should have started earlier.
Title: Re: Gold Drop Variance
Post by: yuyu! on April 24, 2011, 12:08:34 AM
Wow! What a great idea to add a little spruce to any game. Good job, MA! :)
Title: Re: Gold Drop Variance
Post by: Infinate X on April 24, 2011, 02:49:56 AM
greate script
Title: Re: Gold Drop Variance
Post by: pacdiggity on April 24, 2011, 03:16:33 AM
If you keep writing awesome scripts, I'll keep having to add to my scripts list.
Damn your creativity and innovative mind! I'm probably using more of your scripts that my own.
But then again, I've only written like 5. And you have slightly more. Just a little.
Another great script MA.
Title: Re: Gold Drop Variance
Post by: hexgame on May 11, 2011, 11:54:20 AM
Great script idea, I'm having a problem though. Could you perhaps have the gold round up? After every battle, I've been getting around 23.xxxxxxxxxxx gold.
Title: Re: Gold Drop Variance
Post by: modern algebra on May 11, 2011, 02:49:28 PM
That's very strange. Are you sure it is from this script or might you have another one that influences gold drop? Because my script already accounts for that here:



    if add.is_a? (Float)
      add = ((gld*add) / 100).to_i
    end


the .to_i converts it from a decimal to an integer. In my testing, I was unable to reproduce this error.
Title: Re: Gold Drop Variance
Post by: pacdiggity on February 04, 2012, 10:50:10 PM
Hey, MA... May I post a VXA port of this? I keep doing your scripts because they're all useful and actually pretty easy, so I may be asking this question a lot over the next couple of weeks ._.
Title: Re: Gold Drop Variance
Post by: modern algebra on February 04, 2012, 10:54:39 PM
Sure, I wasn't intending to port this one since I incorporated it into Drop Options (http://rmrk.net/index.php/topic,44618.0.html)
Title: Re: Gold Drop Variance
Post by: pacdiggity on February 04, 2012, 10:59:30 PM
Oh, haha. I didn't realize that ._.
That does make sense though, now that I think about it. Eh, I guess there's no real point in posting it now. I'll just do something else.