The RPG Maker Resource Kit

RMRK RPG Maker Creation => RPG Maker General => General Scripting => Topic started by: Zethzune on December 13, 2009, 03:56:35 AM

Title: [Resolved] Auto-Calculated XP
Post by: Zethzune on December 13, 2009, 03:56:35 AM
I want to make the XP gained from battle be automatically calculated from the difficulty of the enemy. I'm already doing this but it's quite tedious to calculate and enter the XP myself, especially while I do balance testing for my game (Adjust one stat, and the XP changes - or adjust the XP equation and have to redo every monster!).

The problem is not so much a lack of ability (this is pretty much just inserting some simple arithmetic...) but I can't seem to locate the part of the base RMXP code where the XP is given to the party at the end of a battle...

Edit: I seem to have found it; however I am still slightly mystified... So far I have:

# Add EXP and amount of gold obtained
exp += (enemy.exp + (enemy.str + enemy.dex + enemy.agi + enemy.int + )


I want to use the exp as bonus XP, for monsters with special abilities that might make them more difficult than their base stats suggest. But I want the equation to be the average of the sum of the monsters ten base stats.
Title: Re: Auto-Calculated XP
Post by: Mr_Wiggles on December 13, 2009, 04:14:32 AM
mabey this helps?
Try looking at Blizz's Tons of add ons
http://forum.chaos-project.com/index.php?topic=105.0
i think in part 2 under "Different Difficulties"
to see how he made his changes...
Title: Re: Auto-Calculated XP
Post by: albertfish on December 13, 2009, 10:50:43 AM
Quote from: Zethzune on December 13, 2009, 03:56:35 AM
I want to use the exp as bonus XP, for monsters with special abilities that might make them more difficult than their base stats suggest. But I want the equation to be the average of the sum of the monsters ten base stats.

Isn't that what you were doing in the code you have there? I'm not really sure what you need to know :P.
Title: Re: [Resolved] Auto-Calculated XP
Post by: Zethzune on December 13, 2009, 05:18:20 PM
Yes, I seem to have figured it out myself. :lol:
I ended up adding auto-calculated gold too.

Here's my completed code for anyone trying to do the same - You might have to edit the multiplier at the end to better suit your game's balance and XP scale. Replace "start_phase5" in Scene_Battle2 to add it.

  def start_phase5
    # Shift to phase 5
    @phase = 5
    # Play battle end ME
    $game_system.me_play($game_system.battle_end_me)
    # Return to BGM before battle started
    $game_system.bgm_play($game_temp.map_bgm)
    # Initialize EXP, amount of gold, and treasure
    exp = 0
    autoexp = 0
    gold = 0
    autogold = 0
    treasures = []
    # Loop
    for enemy in $game_troop.enemies
      # If enemy is not hidden
      unless enemy.hidden
        # Add amount of experience obtained
        autoexp = ((enemy.maxhp + enemy.maxsp + enemy.str + enemy.dex + enemy.agi + enemy.int + enemy.atk + enemy.pdef + enemy.mdef + enemy.eva)*0.04).floor
        exp += (enemy.exp + autoexp)
        #Add amount of gold obtained
        if gold > 0
          autogold = (rand(enemy.gold) + enemy.gold)
          gold += (enemy.gold + autogold)
        else
          gold += 0
        end
        # Determine if treasure appears
        if rand(100) < enemy.treasure_prob
          if enemy.item_id > 0
            treasures.push($data_items[enemy.item_id])
          end
          if enemy.weapon_id > 0
            treasures.push($data_weapons[enemy.weapon_id])
          end
          if enemy.armor_id > 0
            treasures.push($data_armors[enemy.armor_id])
          end
        end
      end
    end
    # Treasure is limited to a maximum of 6 items
    treasures = treasures[0..5]
    # Obtaining EXP
    for i in 0...$game_party.actors.size
      actor = $game_party.actors[i]
      if actor.cant_get_exp? == false
        last_level = actor.level
        actor.exp += exp
        if actor.level > last_level
          @status_window.level_up(i)
        end
      end
    end
    # Obtaining gold
    $game_party.gain_gold(gold)
    # Obtaining treasure
    for item in treasures
      case item
      when RPG::Item
        $game_party.gain_item(item.id, 1)
      when RPG::Weapon
        $game_party.gain_weapon(item.id, 1)
      when RPG::Armor
        $game_party.gain_armor(item.id, 1)
      end
    end
    # Make battle result window
    @result_window = Window_BattleResult.new(exp, gold, treasures)
    # Set wait count
    @phase5_wait_count = 100
  end