Enemy Gold Formulas

This script allows you to use a formula to calculate how much gold is obtained from an enemy.

enemyGoldFormulas1

Download

Script: download here

Installation

Place this script below Materials and above Main

Usage

Note-tag enemies with

<gold formula: FORMULA>

Where the FORMULA is any valid ruby formula that returns a number.
You can use the following variables in your formula:

gold - the default gold value set in the database for that enemy
   a - this enemy
   p - game party
   t - game troop
   v - game variables
   s - game switches

If no gold formula is specified, then the default gold is given.

If you would like to use ruby statements that extend across multiple lines,
you can use the extended note-tag:

<gold formula>
if v[1]
  gold + 200
else
  gold - 200
end
</gold formula>

This may be useful if you have complex logic and you don’t want to write it as
a one-liner.

You may also like...

8 Responses

  1. Doug says:

    It seems there’s an inherent error that I’ve found while debugging. Using a simple formula like:

    is fine. The problem is the following:

    Scenario: I have a troop of 1-3 slimes. 1 will always appear, two are set halfway and might appear.

    I will use a single slime as example.

    One slime at the end of battle if you debug you will see that the script rolls gold values for every one of the 3 slimes in the troop. The rolls lets say are 5g 11g 7g. The battle summary will say: You gained 7g! But in actuality 11g is placed in your inventory. I don’t know if the problem is that Game_Troop gold_total function needs to be updated as well, but this is a problem. I haven’t confirmed yet, but I think this will have the same problem to your enemy XP formula scripts. Any idea how to fix it?

    • Doug says:

      formula: (3..7).to_a.sample * a.level

      Clarifying formula since it was removed from previous post.

    • Hime says:

      The problem occurs when you work with random numbers.

      The way the thing is done is that it calculates the total for the troop, and then displays it. Then it calculates the total again when rewarding the party. This issue can be addressed by calculating it once and then caching it, but that may cause compatibility issues.

      Here is a temp fix: https://github.com/Hime-Works/Requests/issues/229

  2. Hime says:

    Updated to support “this enemy” formula variable.

  3. Charlie says:

    I have a n00b question.
    What exactly do the variables ‘t’, ‘p’ etc relate to?
    As in, is it something related to the average level of the troop? Is it just the troop number in the database? The number of enemies in the troop?
    Sorry, I’m really confused.
    I want to be able to relate gold to the enemy’s level. So that you get more gold for defeating a higher level enemy.

    • Hime says:

      It is a reference to the current troop and party objects. For example, `t.turn_count` will return the current count of the battle. `t` is simply a short-hand for `$game_troop`.

      I’ve updated the script so that you can reference the current enemy in your formula with the `a` formula variable. You can get the enemy’s level using `a.level`, assuming enemy the level script you’re using provides that as the attribute name.

  1. February 25, 2024

    … [Trackback]

    […] Find More on that Topic: himeworks.com/2013/06/enemy-gold-formulas/ […]

Leave a Reply to Doug Cancel reply

Your email address will not be published. Required fields are marked *