[VX Ace] VE Materia - AP Gain Script Command

Discussion in 'RGSSx Script Support' started by Vis_Mage, Oct 6, 2019.

  1. Vis_Mage

    Vis_Mage Novice Magician Veteran

    Messages:
    392
    Likes Received:
    142
    Location:
    Ridge Island
    First Language:
    English
    Primarily Uses:
    RMVXA
    Howdy! :kaohi:

    I'm wondering if anyone could help me out with what I hopefully believe is a simple script edit to Victor's Materia script : https://victorenginescripts.wordpress.com/rpg-maker-vx-ace/materia-system/

    By default, the materia gains AP upon defeating foes. I'm hoping to change it so I can manually set the AP of Materia via a script call. For reference, In game I have different groups of materia (Fire/Water/Ice/etc.). When you first get a fire materia, it will have 1 total AP, once you get a second fire materia, I'll then set ALL fire materia to have 2 total AP. I'll handle keeping track of owned materia, and the AP gain via an event, all I need it a way to set all materia with an armor ID of X to a certain amount of AP.

    I've made a couple small tweaks that, while I don't think any would affect the change to AP gain, I figured I should include just in case. (NOTE: I attached it at the bottom of this post, as the script exceeded the max post size)

    Notable at line 574 you'll see:
    @ap ||= $game_variables[198]___
    With this, I've been able to make it so when I obtain a materia, it's initial total AP is set to the value of variable 198, but I cannot then increase the AP of those Materia after first obtaining them. I thought I'd point it out, in case it proves helpful.

    Hopefully this makes sense. Let me know if you have any questions.

    Thank you!
     

    Attached Files:

    #1
    Another Fen likes this.
  2. Another Fen

    Another Fen Veteran Veteran

    Messages:
    534
    Likes Received:
    246
    First Language:
    German
    Hey there,
    I may have overlooked something while skimming through the script (only the original one though since I wasn't logged in).

    The main way of getting AP seems to be the "ap=" method from the Game_Actor class, which just forwards the amount to the "gain_ap" methods from all equipped materias (RPG::Armor).

    A method to process all materias that are either equipped by an actor or are held in the parties inventory could probably look like this:
    Code:
    class Game_Interpreter  # <- Put into Interpreter class for use in script commands
     
      def iterate_all_materias(&block)
        return enum_for(:iterate_all_materias)  unless block_given?  # Makes the { ... } block when calling this method optional, not necessarily needed to make the code work.
        $game_party.materias.each(&block)  # <- Materias in Party Inventory
        $data_actors.each_index { |index|  # Iterate all database actor slots...
          actor = $game_actors[index]
          next  unless actor
          actor.all_materias.each(&block)  # <- Materias held by "index"-th actor
        }
      end
    end
    which would allow you to do script commands like this:
    Code:
    iterate_all_materias { |materia|
      if materia.id == 15  # If Materia derived from Armor #15...
        # ...Increase AP by Variable 176 (minus the AP the materia already has):
        materia.gain_ap($game_variables[176] - materia.ap, 1)
      end
    }
    That said, it seems that instead of
    materia.gain_ap( ... )
    you could also use
    materia.ap = $game_variables[176]
    here to set the value directly (if you are not using Materia Breeding).

    As an alternative to using the armor id to determine the element, you could also make use of the armors notebox.
    For example, you could give every fire materia the notetag
    <fire-materia>
    and search the notebox for it instead of checking multiple ids:
    (the angle brackets are not required of course, but they have become popular for note-tags)
    Code:
    iterate_all_materias { |materia|
      if materia.note.include?("<fire-materia>")  # <- Check if notebox includes that substring
        materia.ap = $game_variables[176]  # <- Set Materia AP
      end
    }
     
    Last edited: Oct 7, 2019
    #2
    Vis_Mage likes this.
  3. Vis_Mage

    Vis_Mage Novice Magician Veteran

    Messages:
    392
    Likes Received:
    142
    Location:
    Ridge Island
    First Language:
    English
    Primarily Uses:
    RMVXA
    @Another Fen
    Thank you very much for your help! Everything seems to be working great. In particular, I've used the second script call.
     
    #3

Share This Page