VE Materia - AP Gain Script Command

Vis_Mage

Novice Magician
Veteran
Joined
Jul 28, 2013
Messages
567
Reaction score
196
First Language
English
Primarily Uses
RMMV
Howdy! :kaohi:

I'm wondering if anyone could help me out with what I hopefully believe is a simple script edit or add-on to Victor's Materia Plugin :https://forums.rpgmakerweb.com/index.php?threads/ve-materia-system.56724/

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.

What I'm hoping I can do is give all of the different fire group materia the tag <fire-materia> , and then be able to run a command that sets the AP of all Materia with the <fire-materia> tag to a specified amount.

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

Thank you!
 

Another Fen

Veteran
Veteran
Joined
Jan 23, 2013
Messages
564
Reaction score
274
First Language
German
Primarily Uses
Hey there,

If it is still relevant you could try something like this as a base, it does not automatically update the AP automatically yet as you gain materias though:

Code:
/* @plugindesc Group materias and set their AP to the amount of materia
  * @help Use
  * <materia:XXX>
  * in a materias notebox to assign a group to a materia.
  * Use
  * $gameParty.refreshMateriaGroupAp();
  * as a script command to set all materias AP to the amount
  * of materia of the same group held by the party.
  */

(function()  {

// Materia Group Type (From <materia:XXX> notetag)
Game_Materia.prototype.groupType = function() {
    return this.item().meta["materia"];
};

// List of all materias the party has access to (including equipment)
Game_Party.prototype.consolidatedMaterias = function() {
    var result = this.materias();
    for (var member of this.allMembers()) {
        result = result.concat(member.allMaterias());
    }
    return result;
};

// Update AP of all materias in the partys possession with a group tag:
Game_Party.prototype.refreshMateriaGroupAp = function() {
    var materias = this.consolidatedMaterias();
    var materiaQuantities = {};
    // Determine materia quantities:
    for (var materia of materias) {
        var type = materia.groupType();
        if (type) {
            materiaQuantities[type] = (materiaQuantities[type] || 0) + 1;
        }
    }
    // Update materia AP:
    for (var materia of materias) {
        var type = materia.groupType();
        if (type) {
            materia.gainAp(materiaQuantities[type] - materia.ap(), 1);
        }
    }
    // Refresh all party members to update materia effects:
    for (var member of this.allMembers()) {
        member.refresh();
    }
};

})();

For the notetag, this uses MVs default meta tags, so you can set a group using
<materia:fire>
instead. It only allows one group though, so if you need more you might want to edit the beginning of the script above.

To update the AP, you'd need to use
$gameParty.refreshMateriaGroupAp()
as a script call.

I haven't tested it yet though...
 
Last edited:

Vis_Mage

Novice Magician
Veteran
Joined
Jul 28, 2013
Messages
567
Reaction score
196
First Language
English
Primarily Uses
RMMV
Hey, thank you for taking a look at my request!

I gave the plugin a test, but I wasn't able to get it working. Just to be sure, what part of the plugin am I supposed to edit for each group? I tried changing
meta["materia"]; to meta["materia:fire"]; without any luck.

Likewise, just so I understand correctly, what this would do is set the AP to the number of owned materia with the <materia:fire>, whenever I run the $gameParty.refreshMateriaGroupAp script call, right?
 

Another Fen

Veteran
Veteran
Joined
Jan 23, 2013
Messages
564
Reaction score
274
First Language
German
Primarily Uses
Hey there,

Sorry for that, unfortunately it was quite late when I cobbled everything together, plus I still don't have the maker or the default plugins on this pc, hence the lack of automatic updating features. :)
(Although I fear these excuses start to become routine for me by now...)

I simply forgot to add brackets to the script call above, since it is a function call the command should be
$gameParty.refreshMateriaGroupAp();

The "meta" property for database entries works as a shortcut for generic notetags. When you put
<materia:fire>
into an entries notetag the game will extract it and save it in the meta property. So item.meta["materia"]
would be "fire". If you don't use a colon and only put
<materia>
in the note the corresponding meta entry would be true instead.
If an entry does not have any materia-tag in its note then the meta would be undefined, which is treated like false in many conditions.
 
Last edited:

Vis_Mage

Novice Magician
Veteran
Joined
Jul 28, 2013
Messages
567
Reaction score
196
First Language
English
Primarily Uses
RMMV
Haha, it's no problem, man :kaohi:

I am getting an error with the current script call, though. When I run the script call, I get:

$gameParty.refreshMateriaGroupAp is not a function

Also, I'm a little confused about something. You mentioned that the plugin currently only works with one group. Where exactly do I define what this group name is (as in, where do I have to put "fire" so it checks for, and changes the AP of, "fire" group materia)? Or am I misunderstanding how it works?
 

Another Fen

Veteran
Veteran
Joined
Jan 23, 2013
Messages
564
Reaction score
274
First Language
German
Primarily Uses
Took me a while to spot the error but yes, I forgot a "prototype" in the code above... :/
Corrected the code above and hopefully added some info text for the plugin manager. :)

(Sorry for still not having tested anything.)
 

Vis_Mage

Novice Magician
Veteran
Joined
Jul 28, 2013
Messages
567
Reaction score
196
First Language
English
Primarily Uses
RMMV
Thank you very much, things seem to be working just about perfectly, with one exception. The plugin is working perfectly for unequipped Materia, but doesn't seem to recognize any Materia that is already equipped by someone.
 

Another Fen

Veteran
Veteran
Joined
Jan 23, 2013
Messages
564
Reaction score
274
First Language
German
Primarily Uses
Thanks for your patience and doing my job for me here. :D
This time I mixed up Ruby and Javascript semantics. Fixed the code above.

(In Ruby, array.concat(other array) extends the first array by adding the content of the other array to it. Javascript instead creates a new array with all elements without modifying the first array)

Just to be sure, right now the code should include inventory and equipment of all party members, meaning that materias held by actors removed from or not yet in the party do not count. Hope that is what you meant? Otherwise the "Game_Party.prototype.consolidatedMaterias" function would probably have to be extended to include other sources.
 
Last edited:

Vis_Mage

Novice Magician
Veteran
Joined
Jul 28, 2013
Messages
567
Reaction score
196
First Language
English
Primarily Uses
RMMV
Awesome, everything seems to be working perfectly! And you were right, I didn't think to specify it, but only counting actors that have joined the party is indeed what I was hoping to do.

Thank you very much for helping me through my request! :kaothx:
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Happy Thanksgiving everyone! What are you thankful for? I'm thankful that I no longer have PTSD, and that I get to enjoy a good meal with my mom and stepdad! It might not be the same as before COVID, but at least I still get to enjoy the holiday!


Made another map, this one even has a cool moving waterfall. I'll have an animated GIF later whenever I'm done adding stuff. :LZSwink:
Back here again?! RPG MAKER, I can't quit you. :kaosigh:
um... why didn't anyone tell how easy it is to add motions to Sideview battlers? I literally copied the last one, changed the name and index, said where it should play, and boom... I've got intro motions.

Forum statistics

Threads
105,542
Messages
1,014,495
Members
137,221
Latest member
TheRozman
Top